A tiny Playwright project that:
- Opens amazon.com
- Sets the location to a US ZIP code
- Hamburger menu → See all → Electronics → TV & Video
- Finds the 2nd item in the Best Sellers module
- Parses its price and fails if it’s > PRICE_THRESHOLD, otherwise passes
- Node.js 18+ and npm
# clone your repo (replace with your URL)
git clone https://github.com/gabrielcarioca/playwright-amazon-demo-best-seller.git
cd <repo>
# install deps
npm install
# install browsers Playwright uses
npx playwright installCreate a .env file in the project root with the desired ZIP and PRICE_THRESHOLD:
# .env
BASE_URL=https://www.amazon.com
ZIP=10001
PRICE_THRESHOLD=120
playwright.config.tsloads.envautomatically viaimport 'dotenv/config'.
npm testnpm run test:headednpm run test:uinpx playwright test tests/amazon/best_seller_price.spec.tsnpx playwright show-report{
"scripts": {
"test": "playwright test",
"test:headed": "playwright test --headed",
"test:ui": "playwright test --ui",
"codegen": "playwright codegen https://www.amazon.com"
}
}.
├─ tests/
│ ├─ amazon/
│ │ ├─ best_seller_price.spec.ts # the test
│ │ └─ helpers/amazon.ts # helpers: ZIP, hamburger, parsing, etc
├─ playwright.config.ts # loads .env, baseURL, tracing, timeouts
├─ .env # ZIP, PRICE_THRESHOLD, BASE_URL
└─ package.json
- After setting the ZIP (e.g., 10001), the header updates to reflect the US location.
- Hamburger navigation reaches TV & Video (menu closes; the “Televisions & Video” pill/link is visible).
- The test finds the Best Sellers card, selects the 2nd product with a price, parses it, and asserts:
expect(price).toBeLessThanOrEqual(PRICE_THRESHOLD);- Stuck on ZIP popover / “Continue” doesn’t click
Amazon shows a brief overlay that can block pointer events. Helpers use a native DOM click and verify the dialog actually closes. - Hamburger “TV & Video” click ignored
Helper falls back to native click to bypass the menu’s slide overlay. - Avoid
networkidlewaits
Amazon sends continuous analytics pings. Helpers wait for UI state instead (popover hidden, header text changed).
name: e2e
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci
- run: npx playwright install --with-deps
- run: |
echo "BASE_URL=https://www.amazon.com" >> .env
echo "ZIP=10001" >> .env
echo "PRICE_THRESHOLD=120" >> .env
- run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report
retention-days: 7