generated from bcgov/bcrs-template-ui
-
Notifications
You must be signed in to change notification settings - Fork 23
32434-set up test automation framework #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seeker25
merged 4 commits into
bcgov:feature-nuxt-v3-upgrade
from
anisshhbatrra:test-automation-32434
Feb 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # ============================================================================ | ||
| # Playwright Test Automation Workflow | ||
| # ============================================================================ | ||
| # | ||
| # Name: Pay UI Test Automation | ||
| # Description: Automated end-to-end regression testing using Playwright | ||
| # Created: February 17, 2026 | ||
| # Created By: Anish Batra | ||
| # | ||
| # Purpose: | ||
| # - Run automated regression tests on Pay UI application | ||
| # - Supports multiple login methods (BCSC and IDIR) | ||
| # - Generates Allure and Playwright HTML reports | ||
| # - Runs on schedule (Mon-Fri 11 AM EST) and manual trigger | ||
| # | ||
| # Triggers: | ||
| # - Push to main branch | ||
| # - Manual workflow dispatch | ||
| # - Scheduled: Mon-Fri 11:00 AM EST (16:00 UTC) | ||
| # ============================================================================ | ||
| name: Pay UI Test Automation | ||
| on: | ||
| push: | ||
| branches: [ feature-nuxt-v3-upgrade ] | ||
| workflow_dispatch: {} | ||
| schedule: | ||
| # Runs Mon-Fri at 11:00 AM Eastern Standard Time (fixed UTC-5 -> 16:00 UTC) | ||
| - cron: '0 16 * * 1-5' | ||
| jobs: | ||
| test: | ||
| timeout-minutes: 60 | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: test-automation | ||
| env: | ||
| TEST_USERNAME_BCSC: ${{ secrets.TEST_USERNAME_BCSC }} | ||
| TEST_PASSWORD_BCSC: ${{ secrets.TEST_PASSWORD_BCSC }} | ||
| TEST_USERNAME_IDIR: ${{ secrets.TEST_USERNAME_IDIR }} | ||
| TEST_PASSWORD_IDIR: ${{ secrets.TEST_PASSWORD_IDIR }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: lts/* | ||
| - name: Install dependencies | ||
| run: npm ci | ||
| - name: Install Playwright Browsers | ||
| run: npx playwright install --with-deps | ||
| - name: Run Playwright regression tests | ||
| run: npm run e2e:regression:test | ||
| - name: Generate Allure Report | ||
| if: ${{ !cancelled() }} | ||
| run: npm run allure:generate | ||
| - uses: actions/upload-artifact@v4 | ||
| if: ${{ !cancelled() }} | ||
| with: | ||
| name: allure-report | ||
| path: test-automation/allure-report/ | ||
| retention-days: 30 | ||
| - uses: actions/upload-artifact@v4 | ||
| if: ${{ !cancelled() }} | ||
| with: | ||
| name: playwright-html-report | ||
| path: test-automation/playwright-report/ | ||
| retention-days: 30 | ||
| - uses: actions/upload-artifact@v4 | ||
| if: ${{ !cancelled() }} | ||
| with: | ||
| name: test-results | ||
| path: test-automation/test-results/ | ||
| retention-days: 30 | ||
| - name: Publish HTML Report | ||
| if: ${{ !cancelled() }} | ||
| uses: daun/playwright-report-summary@v3 | ||
| with: | ||
| report-file: test-automation/playwright-report/results.json | ||
| github-token: ${{ secrets.GITHUB_TOKEN }}. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
|
|
||
| # Playwright | ||
| node_modules/ | ||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ | ||
| /.auth.json | ||
| /.auth-*.json | ||
|
|
||
| # Allure Reports | ||
| allure-results/ | ||
| allure-report/ | ||
| ./test-automation/allure-results | ||
| ./test-automation/allure-report | ||
|
|
||
| # Environment variables and secrets (NEVER commit credentials) | ||
| env/ | ||
| .env | ||
| .env.* | ||
| .env.local | ||
| .env.*.local | ||
|
|
||
| # IDE | ||
| .DS_Store | ||
| .idea/ | ||
| .vscode/ | ||
| *.swp | ||
| *.swo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # Pay UI Test Automation | ||
|
|
||
| End-to-end regression testing for Pay UI using Playwright. | ||
|
|
||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Node.js >= 18 | ||
| - npm >= 9 | ||
|
|
||
| --- | ||
|
|
||
| ## Setup | ||
|
|
||
| ```bash | ||
| cd test-automation | ||
| npm ci | ||
| npx playwright install --with-deps | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| Set these in .env file for correspoding env (or configure in GitHub Secrets for CI): | ||
|
|
||
|
|
||
| TEST_USERNAME_BCSC=your_bcsc_username | ||
| TEST_PASSWORD_BCSC=your_bcsc_password | ||
| TEST_USERNAME_IDIR=your_idir_username | ||
| TEST_PASSWORD_IDIR=your_idir_password | ||
|
|
||
|
|
||
| ## Running Tests | ||
|
|
||
| ```bash | ||
| # Run all regression tests (by default it will run with IDIR login) | ||
| npm run e2e:regression:test | ||
|
|
||
| # Run with specific login method | ||
| LOGIN_TYPE=bcsc npm run e2e:regression:test | ||
|
|
||
| ## Reports | ||
|
|
||
| ```bash | ||
| # Allure report | ||
| npm run allure:generate | ||
| npm run allure:open | ||
|
|
||
| # Playwright HTML report | ||
| npx playwright show-report | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Folder Structure | ||
|
|
||
| ``` | ||
| test-automation/ | ||
| ├── tests/ # Test spec files | ||
| ├── pages/ # Page Object Models | ||
| ├── env/ # Environment configs (.env.test, .env.dev) | ||
| ├── fixtures.js # Playwright fixtures | ||
| ├── globalSetup.js # Auth setup (runs before all tests) | ||
| └── playwright.config.js | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## CI/CD (GitHub Actions) | ||
|
|
||
| Tests run automatically **Monday–Friday at 11 AM EST** and can also be triggered manually via the Actions tab. | ||
|
|
||
| **Required GitHub Secrets:** | ||
| - `TEST_USERNAME_BCSC` | ||
| - `TEST_PASSWORD_BCSC` | ||
| - `TEST_USERNAME_IDIR` | ||
| - `TEST_PASSWORD_IDIR` | ||
|
|
||
| Go to **Settings → Secrets and variables → Actions** to add them. | ||
|
|
||
| --- | ||
|
|
||
| ## Adding New Tests | ||
|
|
||
| 1. Create a `.spec.js` file in `tests/` | ||
| 2. Tag with `@regression` to include in the regression suite | ||
| 3. Use page objects from `pages/` for reusability | ||
|
|
||
| ```javascript | ||
| import { test } from '../fixtures.js'; | ||
|
|
||
| test.describe('Feature Name @regression', () => { | ||
| test('should do something', async ({ page }) => { | ||
| // test code | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * ============================================================================ | ||
| * Playwright Test Fixtures | ||
| * ============================================================================ | ||
| * | ||
| * File: fixture.js | ||
| * Purpose: Define reusable test fixtures for all tests | ||
| * Created: February 16, 2026 | ||
| * | ||
| * Description: | ||
| * This file extends Playwright's base test fixture with custom fixtures, | ||
| * providing page objects to all tests without manual instantiation. | ||
| * Fixtures enable DRY (Don't Repeat Yourself) test code and consistent setup. | ||
| * ============================================================================ | ||
| */ | ||
|
|
||
| import { test as base, expect } from '@playwright/test'; | ||
| import { LoginPage } from './pages/login-page.js'; | ||
| import { AccountInfoPage } from './pages/account-info-page.js'; | ||
|
|
||
| const test = base.extend({ | ||
| loginPage: async ({ page }, use) => { | ||
| await use(new LoginPage(page)); | ||
| }, | ||
| accountInfoPage: async ({ page }, use) => { | ||
| await use(new AccountInfoPage(page)); | ||
| } | ||
| }); | ||
|
|
||
| export { | ||
| test, | ||
| expect | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /** | ||
| * ============================================================================ | ||
| * Global Setup - Authentication & Session Initialization | ||
| * ============================================================================ | ||
| * | ||
| * File: globalSetup.js | ||
| * Purpose: Runs before all tests to authenticate and cache sessions | ||
| * Author: Anish Batra | ||
| * Created: February 17, 2026 | ||
| * | ||
| * Description: | ||
| * This script executes globally before any tests run. It: | ||
| * 1. Loads environment configuration (dev/test) | ||
| * 2. Selects login method (BCSC or IDIR) via LOGIN_TYPE env var | ||
| * 3. Authenticates against the application | ||
| * 4. Saves authenticated session to .auth-<loginType>.json | ||
| * 5. All tests then reuse this cached session | ||
| * ============================================================================ | ||
| */ | ||
|
|
||
| import dotenv from 'dotenv'; | ||
| import { chromium } from '@playwright/test'; | ||
| import { LoginPage } from './pages/login-page.js'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| function loadEnvironmentConfig() { | ||
| const envName = process.env.ENV_NAME || 'dev'; | ||
| const envFilePath = path.join(__dirname, 'env', `.env.${envName}`); | ||
|
|
||
| console.log(`Global setup: Loading environment '${envName}'`); | ||
|
|
||
| if (!fs.existsSync(envFilePath)) { | ||
| throw new Error(`Environment file not found: ${envFilePath}`); | ||
| } | ||
|
|
||
| dotenv.config({ path: envFilePath }); | ||
| return { envName, envFilePath }; | ||
| } | ||
|
|
||
| function getCredentials() { | ||
| const loginType = (process.env.LOGIN_TYPE || 'idir').toLowerCase(); | ||
|
|
||
| const username = loginType === 'idir' | ||
| ? (process.env.TEST_USERNAME_IDIR || process.env.TEST_USERNAME) | ||
| : (process.env.TEST_USERNAME_BCSC || process.env.TEST_USERNAME); | ||
|
|
||
| const password = loginType === 'idir' | ||
| ? (process.env.TEST_PASSWORD_IDIR || process.env.TEST_PASSWORD) | ||
| : (process.env.TEST_PASSWORD_BCSC || process.env.TEST_PASSWORD); | ||
|
|
||
| return { username, password, loginType }; | ||
| } | ||
|
|
||
| function validateCredentialsAreProvided(username, password, baseURL, loginType, envFilePath) { | ||
| if (!username || !password || !baseURL) { | ||
| console.error(`Global setup: Missing required environment variables in ${envFilePath}`); | ||
| console.error(` BASE_URL: ${baseURL ? '✓' : '✗'}`); | ||
| console.error(` LOGIN_TYPE: ${loginType}`); | ||
| console.error(` TEST_USERNAME_BCSC: ${process.env.TEST_USERNAME_BCSC ? '✓' : '✗'}`); | ||
| console.error(` TEST_PASSWORD_BCSC: ${process.env.TEST_PASSWORD_BCSC ? '✓' : '✗'}`); | ||
| console.error(` TEST_USERNAME_IDIR: ${process.env.TEST_USERNAME_IDIR ? '✓' : '✗'}`); | ||
| console.error(` TEST_PASSWORD_IDIR: ${process.env.TEST_PASSWORD_IDIR ? '✓' : '✗'}`); | ||
| throw new Error('Missing required environment variables for login'); | ||
| } | ||
| } | ||
|
|
||
| async function launchBrowser() { | ||
| const isCI = !!process.env.CI || !!process.env.GITHUB_ACTIONS; | ||
| console.log('Global setup: Launching Chromium browser...'); | ||
| try { | ||
| const browser = await chromium.launch({ headless: isCI }); | ||
| console.log(`Global setup: Chromium browser launched successfully (headless=${isCI})`); | ||
| return browser; | ||
| } catch (launchError) { | ||
| console.error('Global setup: Failed to launch Chromium browser!', launchError.message); | ||
| throw new Error(`Browser launch failed: ${launchError.message}. Make sure to run: npx playwright install`); | ||
| } | ||
| } | ||
|
|
||
| async function performLoginAndSaveSession(page, context, baseURL, loginType, username, password) { | ||
| await page.goto(baseURL); | ||
|
|
||
| const loginPage = new LoginPage(page); | ||
|
|
||
| if (loginType === 'idir') { | ||
| console.log('Global setup: Using IDIR login flow'); | ||
| await loginPage.loginWithIDIR(username, password); | ||
| } else { | ||
| console.log('Global setup: Using BCSC login flow'); | ||
| await loginPage.loginWithBCSC(username, password); | ||
| } | ||
|
|
||
| await page.waitForLoadState('networkidle', { timeout: 10000 }).catch(() => {}); | ||
|
|
||
| try { | ||
| await page.waitForURL(`**/unauthorized`, { timeout: 5000 }); | ||
| } catch (e) { | ||
| // ignore - not all auth flows land on /unauthorized | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. catch, might want to log warning? |
||
| } | ||
|
|
||
| console.log('Global setup: Login completed, URL:', page.url()); | ||
|
|
||
| const authFileName = `.auth-${loginType}.json`; | ||
| const authFile = path.join(__dirname, authFileName); | ||
| await context.storageState({ path: authFile }); | ||
|
|
||
| console.log(`Global setup: Storage state saved to ${authFile}`); | ||
| } | ||
|
|
||
| async function globalSetup() { | ||
| const { envFilePath } = loadEnvironmentConfig(); | ||
| const baseURL = process.env.BASE_URL; | ||
| const { username, password, loginType } = getCredentials(); | ||
|
|
||
| validateCredentialsAreProvided(username, password, baseURL, loginType, envFilePath); | ||
|
|
||
| console.log(`Global setup: Starting login process for ${baseURL}...`); | ||
|
|
||
| const browser = await launchBrowser(); | ||
| const context = await browser.newContext(); | ||
| const page = await context.newPage(); | ||
|
|
||
| try { | ||
| await performLoginAndSaveSession(page, context, baseURL, loginType, username, password); | ||
| } catch (error) { | ||
| console.error('Global setup: Login failed!', error); | ||
| console.error('Current URL:', page.url()); | ||
| throw error; | ||
| } finally { | ||
| await browser.close(); | ||
| } | ||
|
|
||
| console.log('Global setup completed.'); | ||
| } | ||
|
|
||
| export default globalSetup; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catch, might want to log warning?