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
test(e2e): implement PR feedback and update CLAUDE.md
Implemented feedback from PR review including test improvements and
updated e2e/CLAUDE.md following best practices for documentation.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: e2e/CLAUDE.md
+60-50Lines changed: 60 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,53 +2,47 @@
2
2
3
3
## Test Isolation
4
4
5
-
### Cart State Management
6
-
To clear cart state between tests, **clear ALL cookies**. Cart state is stored in a cookie, so there's no need to individually remove line items, discounts, etc. Clearing all cookies provides complete test isolation.
5
+
Playwright automatically provides test isolation - each test runs in its own browser context with isolated storage, cookies, and state. You generally don't need to manually clear cookies or storage between tests.
7
6
8
-
```typescript
9
-
test.afterEach(async ({storefront}) => {
10
-
awaitstorefront.clearAllCookies();
11
-
});
12
-
```
13
-
14
-
For maximum isolation, consider clearing cookies in both `beforeEach` and `afterEach`:
15
-
```typescript
16
-
test.beforeEach(async ({storefront}) => {
17
-
awaitstorefront.clearAllCookies();
18
-
});
19
-
20
-
test.afterEach(async ({storefront}) => {
21
-
awaitstorefront.clearAllCookies();
22
-
});
23
-
```
7
+
**Exception:** If you need to clear state within a single test (e.g., testing empty cart after clearing), do so explicitly in that test.
24
8
25
9
## Test Organization
26
10
27
-
### Shared Setup in beforeEach
28
-
Prefer putting statements shared at the start of ALL tests in a file into a `beforeEach` hook rather than repeating them in each test:
11
+
### Test Setup Strategy
12
+
13
+
Per [Playwright best practices](https://playwright.dev/docs/best-practices#make-tests-as-isolated-as-possible): Use `beforeEach` hooks to eliminate repetitive setup steps while maintaining test isolation.
Always choose selectors based on **DOM elements and semantic structure**, NOT CSS classes or styles. Tests should reflect how a user perceives and interacts with the page.
59
53
60
54
**Priority order for selectors:**
61
-
1. Role + accessible name: `getByRole('button', {name: 'Add to cart'})`
62
-
2. Role + landmark: `getByRole('banner').getByRole('link', {name: /cart/i})`
63
-
3. Text content: `getByText('Continue to Checkout')`
64
-
4. Test IDs (when necessary): `getByTestId('cart-drawer')`
65
-
5. CSS classes (last resort, for entities only): `locator('li.cart-line:visible')`
55
+
1.**Role + accessible name** (preferred): `getByRole('button', {name: 'Add to cart'})`
The skeleton template has both a cart drawer (aside) and a cart page. Both contain similar elements but only one is visible at a time. Use `:visible` pseudo-selector to match only the current context:
132
+
The skeleton template has both a cart drawer (aside) and a cart page. Both contain similar elements but only one is visible at a time.
134
133
135
134
```typescript
136
-
// GOOD: Only matches visible elements
135
+
// GOOD: Role-based selectors with chaining for specificity
// AVOID: CSS selectors (DOM can change, leading to flaky tests)
150
+
getCartLineItems() {
151
+
returnthis.page.locator('li.cart-line:visible'); // Not resilient
144
152
}
145
153
```
154
+
155
+
**Why avoid CSS?** Per [Playwright docs](https://playwright.dev/docs/locators), CSS selectors are "not recommended as the DOM can often change leading to non resilient tests." Use role-based selectors that reflect how users perceive the page.
0 commit comments