From ef1cab0bfee1e49bcdb4d0a2d47d9d4a616be1f3 Mon Sep 17 00:00:00 2001 From: Donald Booth Date: Mon, 22 Apr 2019 10:27:52 -0500 Subject: [PATCH 1/4] Added two new tips. --- docs/tips-tricks.md | 50 +++++++++++++++++++++++++++++++++++++++++++++ temprepo | 1 + 2 files changed, 51 insertions(+) create mode 160000 temprepo diff --git a/docs/tips-tricks.md b/docs/tips-tricks.md index b4b0ba2b8..2857d1ee5 100644 --- a/docs/tips-tricks.md +++ b/docs/tips-tricks.md @@ -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 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. +In this scenario `text()` is more exacting. Use it when you need to be very precise about what is getting compared. + + +GOOD: + + +`//span[contains(text(), 'SomeTextHere')]` + + +BAD: + + +`//span[text()='SomeTextHere']` + ### Build selectors in proper order When building selectors for form elements, start with the parent context of the form element. @@ -353,6 +374,31 @@ BAD: ## General tips +### Use data references to avoid hardcoded values + +If you need to run a command such as ``, 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. + + +GOOD: + + +```xml + +``` + + +BAD: + + +```xml + +``` + +For example: +[This test][] refers to this [Data file][] + ### Use descriptive variable names Use descriptive variable names to increase readability. @@ -398,3 +444,7 @@ BAD: ``` + + +[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 \ No newline at end of file diff --git a/temprepo b/temprepo new file mode 160000 index 000000000..32905654f --- /dev/null +++ b/temprepo @@ -0,0 +1 @@ +Subproject commit 32905654fe3c8a67b233d52c43421dffdf22358d From 062acd0c8ff1d41635b8d1dbd0bd8aa8bab848c8 Mon Sep 17 00:00:00 2001 From: Donald Booth Date: Mon, 22 Apr 2019 10:36:23 -0500 Subject: [PATCH 2/4] Remove temprepo. --- temprepo | 1 - 1 file changed, 1 deletion(-) delete mode 160000 temprepo diff --git a/temprepo b/temprepo deleted file mode 160000 index 32905654f..000000000 --- a/temprepo +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 32905654fe3c8a67b233d52c43421dffdf22358d From 31cc2128414eba3ec154162e6637628d493940a0 Mon Sep 17 00:00:00 2001 From: Donald Booth Date: Mon, 22 Apr 2019 10:38:50 -0500 Subject: [PATCH 3/4] Fixed link. --- docs/tips-tricks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tips-tricks.md b/docs/tips-tricks.md index 2857d1ee5..5f028dec2 100644 --- a/docs/tips-tricks.md +++ b/docs/tips-tricks.md @@ -397,7 +397,7 @@ BAD: ``` For example: -[This test][] refers to this [Data file][] +[This test][] refers to this [Data file][]. ### Use descriptive variable names @@ -447,4 +447,4 @@ BAD: [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 \ No newline at end of file +[Data file]: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Captcha/Test/Mftf/Data/CaptchaConfigData.xml \ No newline at end of file From a8a1e794c8d4cef2b92ae2ca4b620369670f703c Mon Sep 17 00:00:00 2001 From: Donald Booth Date: Tue, 23 Apr 2019 11:16:43 -0500 Subject: [PATCH 4/4] Fixed typo. --- docs/tips-tricks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tips-tricks.md b/docs/tips-tricks.md index 5f028dec2..edc1d57bd 100644 --- a/docs/tips-tricks.md +++ b/docs/tips-tricks.md @@ -289,7 +289,7 @@ When possible, use `contains(text(), 'someTextHere')` rather than `text()='someT `contains()` ignores whitespace while `text()` accounts for it. **Why?** -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. +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. @@ -447,4 +447,4 @@ BAD: [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 \ No newline at end of file +[Data file]: https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Captcha/Test/Mftf/Data/CaptchaConfigData.xml