Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adding 2 tips to Tips and Tricks. #335

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

Merged
merged 9 commits into from
Apr 25, 2019
Merged
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
50 changes: 50 additions & 0 deletions docs/tips-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,27 @@ Use numbers within `stepKeys` when order is important, such as with testing sort

## Selectors

### Use contains() around text()

When possible, use `contains(text(), 'someTextHere')` rather than `text()='someTextHere'`.
`contains()` ignores whitespace while `text()` accounts for it.

**Why?**
If you are comparing text within a selector and have an unexpected space, or a blank line above or below the string, `text()` will fail while the `contains(text())` format will catch it.
In this scenario `text()` is more exacting. Use it when you need to be very precise about what is getting compared.

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

`//span[contains(text(), 'SomeTextHere')]`

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

`//span[text()='SomeTextHere']`

### Build selectors in proper order

When building selectors for form elements, start with the parent context of the form element.
Expand Down Expand Up @@ -353,6 +374,31 @@ BAD:

## General tips

### Use data references to avoid hardcoded values

If you need to run a command such as `<magentoCLI command="config:set" />`, do not hardcode paths and values to the command.
Rather, create an appropriate `ConfigData.xml` file, which contains the required parameters for running the command.
It will simplify the future maintanence of tests.

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

```xml
<magentoCLI command="config:set {{StorefrontCustomerCaptchaLength3ConfigData.path}} {{StorefrontCustomerCaptchaLength3ConfigData.value}}" stepKey="setCaptchaLength" />
```

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

```xml
<magentoCLI command="config:set customer/captcha/length 3" stepKey="setCaptchaLength" />
```

For example:
[This test][] refers to this [Data file][].

### Use descriptive variable names

Use descriptive variable names to increase readability.
Expand Down Expand Up @@ -398,3 +444,7 @@ BAD:
```

<!--{% endraw %}-->

<!-- Link Definitions -->
[This test]: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Captcha/Test/Mftf/Test/StorefrontCaptchaRegisterNewCustomerTest.xml#L24
[Data file]: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Captcha/Test/Mftf/Data/CaptchaConfigData.xml