Skip to content

Commit ef1cab0

Browse files
committed
Added two new tips.
1 parent ee5d3f7 commit ef1cab0

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

docs/tips-tricks.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,27 @@ Use numbers within `stepKeys` when order is important, such as with testing sort
283283

284284
## Selectors
285285

286+
### Use contains() around text()
287+
288+
When possible, use `contains(text(), 'someTextHere')` rather than `text()='someTextHere'`.
289+
`contains()` ignores whitespace while `text()` accounts for it.
290+
291+
**Why?**
292+
If you are comparing text wihtin 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.
293+
In this scenario `text()` is more exacting. Use it when you need to be very precise about what is getting compared.
294+
295+
<span style="color:green">
296+
GOOD:
297+
</span>
298+
299+
`//span[contains(text(), 'SomeTextHere')]`
300+
301+
<span style="color:red">
302+
BAD:
303+
</span>
304+
305+
`//span[text()='SomeTextHere']`
306+
286307
### Build selectors in proper order
287308

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

354375
## General tips
355376

377+
### Use data references to avoid hardcoded values
378+
379+
If you need to run a command such as `<magentoCLI command="config:set" />`, do not hardcode paths and values to the command.
380+
Rather, create an appropriate `ConfigData.xml` file, which contains the required parameters for running the command.
381+
It will simplify the future maintanence of tests.
382+
383+
<span style="color:green">
384+
GOOD:
385+
</span>
386+
387+
```xml
388+
<magentoCLI command="config:set {{StorefrontCustomerCaptchaLength3ConfigData.path}} {{StorefrontCustomerCaptchaLength3ConfigData.value}}" stepKey="setCaptchaLength" />
389+
```
390+
391+
<span style="color:red">
392+
BAD:
393+
</span>
394+
395+
```xml
396+
<magentoCLI command="config:set customer/captcha/length 3" stepKey="setCaptchaLength" />
397+
```
398+
399+
For example:
400+
[This test][] refers to this [Data file][]
401+
356402
### Use descriptive variable names
357403

358404
Use descriptive variable names to increase readability.
@@ -398,3 +444,7 @@ BAD:
398444
```
399445

400446
<!--{% endraw %}-->
447+
448+
<!-- Link Definitions -->
449+
[This test]: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Captcha/Test/Mftf/Test/StorefrontCaptchaRegisterNewCustomerTest.xml#L24
450+
Data file]: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Captcha/Test/Mftf/Data/CaptchaConfigData.xml

temprepo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 32905654fe3c8a67b233d52c43421dffdf22358d

0 commit comments

Comments
 (0)