You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/best.md
+161-2Lines changed: 161 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ So if you want to click an element which is not a button or a link and use its t
32
32
I.click(locate('.button').withText('Click me'));
33
33
```
34
34
35
-
## Use Short Cuts
35
+
## Short Cuts
36
36
37
37
To write simpler and effective tests we encourage to use short cuts.
38
38
Make test be focused on one feature and try to simplify everything that is not related directly to test.
@@ -60,8 +60,14 @@ Scenario('editing a metric', async ({ I, loginAs, metricPage }) => {
60
60
I.see('Duration: Week', '.summary');
61
61
});
62
62
```
63
+
## Locators
63
64
64
-
## Refactoring and PageObjects
65
+
* If you don't use multi-lingual website or you don't update texts often it is OK to click on links by their texts or match fields by their placeholders.
66
+
* If you don't want to rely on guessing locators, specify them manyally with `{ css: 'button' }` or `{ xpath: '//button' }`. We call them strict locators. Those locators will be faster but less readable.
67
+
* Even better if you have a convention on acive elements with special attributes like `data-test` or `data-qa`. Use `customLocator` plugin to easily add them to tests.
68
+
* Keep tests readable whcih will make them maintainable.
69
+
70
+
## Page Objects
65
71
66
72
When a project is growing and more and more tests are required, it's time to think about reusing test code across the tests. Some common actions should be moved from tests to other files so to be accessible from different tests.
67
73
@@ -76,3 +82,156 @@ Here is a recommended strategy what to store where:
76
82
77
83
However, it's recommended to not overengineer and keep tests simple. If a test code doesn't require reusage at this point it should not be transformed to use page objects.
78
84
85
+
86
+
* use page objects to store common actions
87
+
* don't make page objects for every page! Only for pages shared across different tests and suites.
88
+
* use classes for page objects, this allows inheritace. Export instance of that classes.
89
+
* if a page object is focused around a form with a multiple fields in it, use a flexible set of arguments in it:
90
+
91
+
```js
92
+
classCheckoutForm {
93
+
94
+
fillBillingInformation(data= {}) {
95
+
// take data in a flexible format
96
+
// iterate over fields to will them all
97
+
for (let key ofObject.keys(data)) {
98
+
I.fillField(key, data[key]); // like this one
99
+
}
100
+
}
101
+
102
+
}
103
+
module.exports=newCheckoutForm();
104
+
module.exports.CheckoutForm= CheckoutForm; // for inheritance
105
+
```
106
+
107
+
* for a components that are repeated accross a website (widgets) but doesn't belong to any page, use component objects. They are the same as page objects but focused only aroung one element:
0 commit comments