Skip to content

Commit 7df23c5

Browse files
zomarsgitbook-bot
authored andcommitted
GITBOOK-128: No subject
1 parent 4c2ed43 commit 7df23c5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* [Don't modularize prematurely](engineering/best-practices/dont-modularize-prematurely.md)
5353
* [Only select data you need](engineering/best-practices/only-select-data-you-need.md)
5454
* [Disallowing the use of unrestricted Metadata fields](engineering/best-practices/disallowing-the-use-of-unrestricted-metadata-fields.md)
55+
* [E2E Tests Best Practices](engineering/best-practices/e2e-tests-best-practices.md)
5556
* [💻 Codebase](engineering/codebase/README.md)
5657
* [🚫 Git Private Submodules](engineering/codebase/git-private-submodules.md)
5758
* [🏎 Monorepo / Turborepo](engineering/codebase/monorepo-turborepo.md)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
description: >-
3+
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

Comments
 (0)