Skip to content

test: example e2e test#3505

Closed
fredericoo wants to merge 4 commits intomainfrom
fb-e2e-example
Closed

test: example e2e test#3505
fredericoo wants to merge 4 commits intomainfrom
fb-e2e-example

Conversation

@fredericoo
Copy link
Contributor

@fredericoo fredericoo commented Feb 25, 2026

This PR is an example of good practices when writing e2e tests with playwright

highlights:

  • be dumb: not dynamically finding any selectors, parsing numbers etc
  • good a11y = good tests, enable us to rely on the accessibility tree to find things (like the line items in the cart, or the cart badge)
  • assumes we start a clean session each time (which is the case) with clean cookies
  • assumes we have a stable product we can always find (which is the case too)

@shopify
Copy link
Contributor

shopify bot commented Feb 25, 2026

Oxygen deployed a preview of your fb-e2e-example branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment February 27, 2026 2:33 PM

Learn more about Hydrogen's GitHub integration.

@fredericoo fredericoo marked this pull request as ready for review February 26, 2026 20:06
@fredericoo fredericoo requested a review from a team as a code owner February 26, 2026 20:06
@binks-code-reviewer
Copy link

binks-code-reviewer bot commented Feb 26, 2026

🤖 Code Review · #projects-dev-ai for questions
React with 👍/👎 or reply — all feedback helps improve the agent.

Complete - 1 findings

📋 History

✅ No issues → ✅ 1 findings

await expect(cartToggle.getByLabel('Items: 1')).toBeVisible();

expect(parseInt(updatedCount)).toBeGreaterThan(parseInt(initialCount));
await cart.assertInCart(page, productName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we follow the POM pattern and make the object into a class or singleton, each domains assertion doesn't have to keep passing in the Playwright's page as an arg.

   const cartUtil = new CartUtil(page); 
   cartUtil.assertInCart(productName)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it’s a decision we can make together! i particularly dont like POM because it needs to be declared at the top all to avoid passing page as a param to functions

we can do it though, especially if there are more advantages than skipping page


// Wait for the cart update network request to complete
await page.waitForLoadState('networkidle');
await expect(cartToggle.getByLabel('items: 0')).toBeVisible();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky selector due to inconsistent label casing (items: 0 vs Items: 1)

The test asserts two different accessible labels for the cart badge:

await expect(cartToggle.getByLabel('items: 0')).toBeVisible();
...
await expect(cartToggle.getByLabel('Items: 1')).toBeVisible();

This is likely to fail depending on the actual accessible name casing/format and is inconsistent within the same test. If the UI label is Items: 0, the first assertion fails; if it’s items: 1, the second fails. Even if matching is case-insensitive in some contexts, relying on that is brittle across locator strategies.

@fredericoo fredericoo closed this Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants