Skip to content

New addition to Tips and Tricks #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion docs/tips-tricks.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
# Tips and Tricks

Sometimes, little changes can make a big difference in your project. Here are some test writing tips to keep everything running smoothly.
Sometimes, little changes can make a big difference in your project.
Here are some test writing tips to keep everything running smoothly.

## Actions and action groups

### Use the appropriate action to verify that the 'select' element contains the expected options

To ensure that your `select` form element contains only expected values:

- Use the `grabMultiple` action to get all `options` from the `select` element.
- Use the `assertContains` action to verify that the array of `options` contains expected values.
- Use the `assertNotContains` action to verify that the array of `options` does not contain certain values.
- If you need to verify that you have a specific list of `options` in a `select` element, use `assertEquals`.

<span style="color:green">
Good
</span>

```xml
<grabMultiple selector="{{AdminProductFormSection.customAttributeSelectOptions($$createDropdownProductAttribute.attribute[attribute_code]$$)}}" stepKey="selectOptions" />
<assertContains stepKey="seeFirstAdminOption">
<actualResult type="variable">selectOptions</actualResult>
<expectedResult type="string">admin_option_1</expectedResult>
</assertContains>
<assertContains stepKey="seeSecondAdminOption">
<actualResult type="variable">selectOptions</actualResult>
<expectedResult type="string">admin_option_2</expectedResult>
</assertContains>

<assertNotContains stepKey="dontSeeFirstStoreOption">
<actualResult type="variable">selectOptions</actualResult>
<expectedResult type="string">option1</expectedResult>
</assertNotContains>
<assertNotContains stepKey="dontSeeSecondStoreOption">
<actualResult type="variable">selectOptions</actualResult>
<expectedResult type="string">option2</expectedResult>
</assertNotContains>
```

<span style="color:red">
Bad
</span>

```xml
<click selector="{{AdminProductFormSection.customAttributeDropdownField($$createDropdownProductAttribute.attribute[attribute_code]$$)}}" stepKey="clickOnAttributeDropdown"/>
<see selector="{{AdminProductFormSection.customAttributeDropdownField($$createDropdownProductAttribute.attribute[attribute_code]$$)}}" userInput="admin_option_1" stepKey="seeFirstAdminOption"/>
<see selector="{{AdminProductFormSection.customAttributeDropdownField($$createDropdownProductAttribute.attribute[attribute_code]$$)}}" userInput="admin_option_2" stepKey="seeSecondAdminOption"/>
<dontSee selector="{{AdminProductFormSection.customAttributeDropdownField($$createDropdownProductAttribute.attribute[attribute_code]$$)}}" userInput="option1" stepKey="dontSeeFirstStoreOption"/>
<dontSee selector="{{AdminProductFormSection.customAttributeDropdownField($$createDropdownProductAttribute.attribute[attribute_code]$$)}}" userInput="option2" stepKey="dontSeeSecondStoreOption"/>
```

### Use parameterized selectors in action groups with argument references

Clarity and readability are important factors in good test writing.
Expand Down