Skip to content

Commit

Permalink
initial playwright commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarkowsky committed Oct 9, 2024
1 parent a64fa24 commit 03b9606
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# TODO: This is the default from Playwright. Needs changes to work in our pipeline if we want that.
# name: Playwright Tests
# on:
# push:
# branches: [ main, master ]
# pull_request:
# branches: [ main, master ]
# jobs:
# test:
# timeout-minutes: 60
# runs-on: ubuntu-latest
# 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 tests
# run: npx playwright test
# - uses: actions/upload-artifact@v4
# if: ${{ !cancelled() }}
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 30
5 changes: 5 additions & 0 deletions e2e/.env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BASE_URL=
BCSC_USERNAME=
BCSC_PASSWORD=
BCEID_USERNAME=
BCEID_PASSWORD=
5 changes: 5 additions & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
9 changes: 9 additions & 0 deletions e2e/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dotenv from 'dotenv';

dotenv.config()

export const BASE_URL = process.env.URL ?? 'localhost:3000';
export const BCSC_USERNAME = process.env.BCSC_USERNAME ?? '';
export const BCSC_PASSWORD = process.env.BCSC_PASSWORD ?? '';
export const BCEID_USERNAME = process.env.BCEID_USERNAME ?? '';
export const BCEID_PASSWORD = process.env.BCEID_PASSWORD ?? '';
23 changes: 23 additions & 0 deletions e2e/functions/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {BASE_URL, BCEID_PASSWORD, BCEID_USERNAME, BCSC_PASSWORD, BCSC_USERNAME} from '../env';

export const loginBCServicesCard = async ({ page }) => {
await page.goto(BASE_URL);
await page.getByRole('button', { name: 'Login' }).click();
await page.getByRole('link', { name: 'BC Services Card' }).click();
await page.getByLabel('Log in with Test with').click();
await page.getByLabel('Email or username').click();
await page.getByLabel('Email or username').fill(BCSC_USERNAME);
await page.getByLabel('Password').click();
await page.getByLabel('Password').fill(BCSC_PASSWORD);
await page.getByRole('button', { name: 'Continue' }).click();
};

export const loginBCeID = async ({ page }) => {
await page.goto(BASE_URL);
await page.getByRole('button', { name: 'Login' }).click();
await page.getByRole('link', { name: 'Basic or Business BCeID' }).click();
await page.locator('#user').fill(BCEID_USERNAME);
await page.getByLabel('Password').click();
await page.getByLabel('Password').fill(BCEID_PASSWORD);
await page.getByRole('button', { name: 'Continue' }).click();
};
17 changes: 17 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "e2e",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "1.48.0",
"@types/node": "22.7.5"
},
"dependencies": {
"dotenv": "16.4.5"
}
}
77 changes: 77 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { defineConfig, devices } from '@playwright/test';
import { BASE_URL } from './env';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
12 changes: 12 additions & 0 deletions e2e/tests/login.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from '@playwright/test';
import { loginBCServicesCard, loginBCeID } from '../functions/login';

test('log in with BC Services Card', async ({ page }) => {
await loginBCServicesCard({ page });
await expect(page.getByRole('button', { name: 'Logout' })).toBeVisible();
});

test('log in with BCeID', async ({ page }) => {
await loginBCeID({ page });
await expect(page.getByRole('button', { name: 'Logout' })).toBeVisible();
});

0 comments on commit 03b9606

Please sign in to comment.