Playwright test suite for the Sauce Demo / Swag Labs application, organized with page objects and shared components.
The suite currently covers authenticated browser flows, checkout behavior, cart state, and checkout-complete actions such as returning to the inventory page and downloading the order PDF.
tests/Playwright specspages/page objects for login, inventory, cart, and checkout screensshared-components/reusable UI components such as the header and cart listutils/testHooks.jsshared test fixture logicplaywright.config.jsPlaywright configuration and setup projecttests/auth.setup.jsauthenticated storage-state bootstrap
- Node.js 20+ is recommended
- npm
- Valid Sauce Demo credentials
-
Install dependencies:
npm install
-
Create a local
.envfile from.env.example:cp .env.example .env
-
Fill in the required values:
BASE_URL=https://www.saucedemo.com/ TEST_USERNAME=your-username TEST_PASSWORD=your-password
The Playwright config uses a setup project to authenticate once and save browser state to playwright/.auth/user.json. The Chromium project depends on that setup state, so the normal test run is:
npx playwright testRun a single spec file:
npx playwright test tests/checkout/checkout-complete-page.spec.jsOpen the HTML report after a run:
npx playwright show-reportplaywright.config.jsreads.envwithdotenv.- The default
baseURLishttps://www.saucedemo.com/. - Failed tests capture screenshots and traces on retry.
- The test run is configured for authenticated Chromium tests by default.
- Downloads are written to
./downloads/; the checkout-complete spec expects the order PDF to be saved there.
LoginPagefor login and validation errorsInventoryPagefor product listing, sorting, and add/remove actionsItemPagefor individual product detailsCartPagefor cart navigation and checkout entryCheckoutUserDetailsPagefor shipping information and validationCheckoutOverviewPagefor order summary checks and finish flowCheckoutCompletePagefor completion confirmation, back-home navigation, and PDF download
The checkout-complete spec follows the same path the page objects are built for:
- Open the inventory page
- Add an item to the cart
- Open the cart from the header
- Start checkout
- Enter shipping details
- Review the order
- Finish checkout
- Verify the completion page and download the PDF
tests/auth.setup.jsshould run before browser tests so storage state exists.utils/testHooks.jsclears./downloads/before each test and logs pass/fail status.