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
These are some basic principles that should be respected when working with E2E
4
+
tests. Failure to follow these practices can be a motive for PR rejection.
5
+
---
6
+
7
+
# E2E Tests Best Practices
8
+
9
+
* A test should avoid using Text Locators: `page.locator('text=`
10
+
* Add a proper to data-testid to the HTML element and retrieve it by using page.getByTestId
11
+
* From [Playwright docs](https://playwright.dev/docs/locators#locate-by-test-id):
12
+
*> Testing by test ids is the most resilient way of testing as even if your text or role of the attribute changes the test will still pass. QA's and developers should define explicit test ids and query them with page.getByTestId(). However testing by test ids is not user facing. If the role or text value is important to you then consider using user facing locators such as role and text locators.
13
+
* A test should be able to run locally as well as on CI
14
+
* A test should be able to be run multiple times and expect a consistent result
15
+
* A test should not introduce side-effects that may affect other tests running in parallel
16
+
* A test should use expect(page).toHaveURL() so we can fail fast if a new unexpected redirection is introduced
17
+
* A test should avoid using fixed seeded records for testing.
18
+
* This conflicts with parallelization and consistency
19
+
* A test should reset the DB state to be the same after running tests than it was before running them.
20
+
* This means all created records should be properly cleaned up after tests are run
21
+
* If seeded records were used, return them to their original state afterwards.
22
+
23
+
### TODO
24
+
25
+
* Guide for debugging E2E failures
26
+
* What to do when checks fail?
27
+
* How can I know where to look?
28
+
* Recommended Tools and extensions
29
+
* Workflow recommendations for working with E2E tests
0 commit comments