Scenario Testing
Scottsdale Mint uses Jest + Puppeteer for end-to-end browser-based scenario testing. These tests simulate real customer interactions to validate critical checkout and purchasing flows.
Test Frameworkโ
| Tool | Version | Purpose |
|---|---|---|
| Jest | ^29.x | Test runner, assertions |
| jest-puppeteer | ^9.x | Puppeteer integration for Jest |
| Puppeteer | ^21.x | Headless Chrome browser automation |
Location: scenario-testing/
Directory Structureโ
scenario-testing/
โโโ config.json โ Test configuration (target URL, credentials)
โโโ jest.config.js โ Jest configuration
โโโ jest-puppeteer.config.js โ Puppeteer launch options
โโโ scenario-testing.js โ Shared utilities and helpers
โโโ package.json โ npm dependencies
โโโ src/
โโโ checkout.test.js โ Checkout and payment scenarios
โโโ utility.js โ Reusable helper functions
Configurationโ
config.jsonโ
{
"baseUrl": "https://scottsdalemint.test",
"testUser": {
"email": "[email protected]",
"password": "password"
},
"testProduct": {
"sku": "SM-TEST-1OZ-SILVER",
"url": "/product/1-oz-silver-bar/"
},
"timeouts": {
"navigation": 30000,
"waitForSelector": 10000
}
}
jest-puppeteer.config.jsโ
module.exports = {
launch: {
headless: process.env.PUPPETEER_HEADLESS !== 'false', // headless unless PUPPETEER_HEADLESS=false
slowMo: 0,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage'
]
},
server: null // Tests run against existing site, no local server started
};
Running Testsโ
Install dependenciesโ
cd scenario-testing
npm install
Run all testsโ
npm test
Run a specific test fileโ
npx jest src/checkout.test.js
Run with browser visible (debug mode)โ
PUPPETEER_HEADLESS=false npm test
Run against a specific URLโ
BASE_URL=https://staging.scottsdalemint.com npm test
Test Scenarios (src/checkout.test.js)โ
Guest Checkout โ Credit Cardโ
- Navigate to a product page
- Add product to cart
- Proceed to checkout as guest
- Fill in billing/shipping address
- Select PayPal PPCP hosted card payment
- Enter test card details
- Submit order
- Assert: "Order received" page shown with order number
Registered User Checkoutโ
- Log in with test customer account
- Navigate to a product page
- Add to cart
- Proceed to checkout (address pre-filled)
- Select saved credit card (if available)
- Submit order
- Assert: Order confirmation page
Add to Cartโ
- Navigate to product listing page
- Click "Add to Cart"
- Assert: Cart badge count increases
- Navigate to cart page
- Assert: Product appears in cart
Search โ Algoliaโ
- Click the search bar
- Type a search query (e.g., "silver bar")
- Assert: Autocomplete suggestions appear within 2 seconds
- Click a suggestion
- Assert: Navigate to correct product page
Order Trackingโ
- Navigate to order tracking page
- Enter an order number and email
- Assert: Order details and status are displayed
Utility Functions (src/utility.js)โ
// Navigate to page and wait for load
async function navigateTo(page, path) { ... }
// Fill a form field by label text
async function fillField(page, label, value) { ... }
// Wait for WooCommerce AJAX to complete
async function waitForAjax(page) { ... }
// Take a screenshot for debugging
async function screenshot(page, name) { ... }
// Add a product to cart by URL
async function addToCart(page, productUrl) { ... }
CI Integrationโ
Scenario tests can be run in the Bitbucket Pipeline after deploying to staging:
# In bitbucket-pipelines.yml
- step:
name: Scenario Tests
image: node:20
script:
- cd scenario-testing
- npm install
- BASE_URL=$STAGING_URL npm test
artifacts:
- scenario-testing/screenshots/**
note
Scenario tests should run against staging only โ never run automated checkout tests against production, as they would create real orders or trigger real payment flows.
Writing New Testsโ
- Create a new
.test.jsfile inscenario-testing/src/ - Import utilities from
utility.js - Use
pagefrom jest-puppeteer (global) - Add meaningful
describeanditblocks - Always await page navigations and assertions
Template:
const config = require('../config.json');
const { navigateTo } = require('./utility.js');
describe('Feature Name', () => {
beforeEach(async () => {
await navigateTo(page, '/');
});
it('should do something', async () => {
await navigateTo(page, '/some-page');
await page.waitForSelector('.element');
const text = await page.$eval('.element', el => el.textContent);
expect(text).toBe('Expected text');
});
});
Troubleshootingโ
| Issue | Action |
|---|---|
| Tests timing out | Increase timeout in config.json; check site is reachable at baseUrl |
| Puppeteer browser not launching | Add --no-sandbox to launch args; ensure Chrome dependencies installed |
| Checkout test failing on payment | PayPal sandbox credentials may be expired; check Kount sandbox mode |
| Tests pass locally but fail in CI | Check CI environment has Chrome; use --disable-dev-shm-usage arg |