Skip to main content

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โ€‹

ToolVersionPurpose
Jest^29.xTest runner, assertions
jest-puppeteer^9.xPuppeteer integration for Jest
Puppeteer^21.xHeadless 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โ€‹

  1. Navigate to a product page
  2. Add product to cart
  3. Proceed to checkout as guest
  4. Fill in billing/shipping address
  5. Select PayPal PPCP hosted card payment
  6. Enter test card details
  7. Submit order
  8. Assert: "Order received" page shown with order number

Registered User Checkoutโ€‹

  1. Log in with test customer account
  2. Navigate to a product page
  3. Add to cart
  4. Proceed to checkout (address pre-filled)
  5. Select saved credit card (if available)
  6. Submit order
  7. Assert: Order confirmation page

Add to Cartโ€‹

  1. Navigate to product listing page
  2. Click "Add to Cart"
  3. Assert: Cart badge count increases
  4. Navigate to cart page
  5. Assert: Product appears in cart

Search โ€” Algoliaโ€‹

  1. Click the search bar
  2. Type a search query (e.g., "silver bar")
  3. Assert: Autocomplete suggestions appear within 2 seconds
  4. Click a suggestion
  5. Assert: Navigate to correct product page

Order Trackingโ€‹

  1. Navigate to order tracking page
  2. Enter an order number and email
  3. 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โ€‹

  1. Create a new .test.js file in scenario-testing/src/
  2. Import utilities from utility.js
  3. Use page from jest-puppeteer (global)
  4. Add meaningful describe and it blocks
  5. 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โ€‹

IssueAction
Tests timing outIncrease timeout in config.json; check site is reachable at baseUrl
Puppeteer browser not launchingAdd --no-sandbox to launch args; ensure Chrome dependencies installed
Checkout test failing on paymentPayPal sandbox credentials may be expired; check Kount sandbox mode
Tests pass locally but fail in CICheck CI environment has Chrome; use --disable-dev-shm-usage arg