Skip to content

Commit

Permalink
style: Better playwright config
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Christie committed Feb 7, 2025
1 parent ac4889d commit 086b5d2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 28 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/latest-stack-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ jobs:
behave --tags=-wip
env:
BEHAVIOUR_AWS_ACCESS_KEY_ID: ${{ secrets.BEHAVIOUR_AWS_ACCESS_KEY_ID }}
BEHAVIOUR_AWS_SECRET_ACCESS_KEY: ${{ secrets.BEHAVIOUR_AWS_SECRET_ACCESS_KEY }}
BEHAVIOUR_AWS_ENDPOINT_URL: ${{ secrets.BEHAVIOUR_AWS_ENDPOINT_URL }}
BEHAVIOUR_AWS_SECRET_ACCESS_KEY: ${{ secrets.BEHAVIOUR_AWS_SECRET_ACCESS_KEY }}
BEHAVIOUR_AWX_HOST: ${{ secrets.BEHAVIOUR_AWX_HOSTNAME }}
BEHAVIOUR_AWX_USERNAME: ${{ secrets.BEHAVIOUR_AWX_USERNAME }}
BEHAVIOUR_AWX_PASSWORD: ${{ secrets.BEHAVIOUR_AWX_PASSWORD }}
BEHAVIOUR_STACK_USERNAME: ${{ secrets.BEHAVIOUR_STACK_USERNAME }}
BEHAVIOUR_STACK_PASSWORD: ${{ secrets.BEHAVIOUR_STACK_PASSWORD }}
BEHAVIOUR_AWX_USERNAME: ${{ secrets.BEHAVIOUR_AWX_USERNAME }}
BEHAVIOUR_STACK_CLIENT_ID_SECRET: ${{ secrets.BEHAVIOUR_STACK_CLIENT_ID_SECRET }}
BEHAVIOUR_STACK_NAME: behaviour
BEHAVIOUR_STACK_PASSWORD: ${{ secrets.BEHAVIOUR_STACK_PASSWORD }}
BEHAVIOUR_STACK_USERNAME: ${{ secrets.BEHAVIOUR_STACK_USERNAME }}

playwright-test:
runs-on: ubuntu-latest
Expand All @@ -94,7 +94,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '23'
node-version: '23.7'

- name: Install dependencies
run: npm ci
Expand All @@ -107,9 +107,10 @@ jobs:
npx playwright test
env:
BEHAVIOUR_AWX_USERNAME: ${{ secrets.BEHAVIOUR_AWX_USERNAME }}
BEHAVIOUR_STACK_USERNAME: ${{ secrets.BEHAVIOUR_STACK_USERNAME }}
BEHAVIOUR_STACK_PASSWORD: ${{ secrets.BEHAVIOUR_STACK_PASSWORD }}
BEHAVIOUR_PLAYWRIGHT_TEST_TARGET: A71EV2A
BEHAVIOUR_STACK_NAME: behaviour
BEHAVIOUR_STACK_PASSWORD: ${{ secrets.BEHAVIOUR_STACK_PASSWORD }}
BEHAVIOUR_STACK_USERNAME: ${{ secrets.BEHAVIOUR_STACK_USERNAME }}

- name: Archive Playwright Report
uses: actions/upload-artifact@v4
Expand Down
8 changes: 3 additions & 5 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ export default defineConfig({

// Fail the build on CI if you accidentally left test.only in the source code.
forbidOnly: !!process.env.CI,
// No retries
retries: 0,
retries: 1,
// Opt out of parallel tests
workers: 1,

reporter: 'html',
// Path template for snapshot files.
// At the moment we remove the browser and platform from the path
// and put everything into a Snapshots directory.
snapshotPathTemplate: '{testDir}/Snapshots/{testFilePath}/{arg}{ext}',

reporter: 'html',

// Shared settings for all the projects below.
// See https://playwright.dev/docs/api/class-testoptions.
use: {
Expand Down Expand Up @@ -50,4 +47,5 @@ export default defineConfig({
maxDiffPixelRatio: 0.08,
},
},

});
39 changes: 29 additions & 10 deletions playwright/config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
/**
* Various configuration variables (extracted from the environment)
* and exported for use by the test scripts. Variables are shared
* with the API-based behaviour tests (see the 'behaviour' directory).
* and exported for use by the test scripts. Variables are common to
* the API-based behaviour tests (see the 'behaviour' directory's 'config.py').
*
* Expects: -
*
* BEHAVIOUR_AWX_USERNAME
* The username of the AWX user used to form the stack.
* Used to 'predict' the stack URL.
*
* BEHAVIOUR_STACK_NAME
* The 'name' of the stack used for the AWX JobTemplate that created the stack.
* Used to 'predict' the stack URL. It has a default of 'behaviour'.
*
* BEHAVIOUR_STACK_USERNAME
* A CAS user entitled to see the Target under test
*
* BEHAVIOUR_STACK_PASSWORD
* The password for the CAS user
*
* BEHAVIOUR_PLAYWRIGHT_TEST_TARGET
* A Target known to be present in the stack, accessible by the chosen CAS user
*/
const awxUsername = process.env.BEHAVIOUR_AWX_USERNAME
const stackDomain = 'xchem-dev.diamond.ac.uk'
const awxUsername: string = (process.env.BEHAVIOUR_AWX_USERNAME as string)
const stackDomain: string = 'xchem-dev.diamond.ac.uk'

export const stackUsername = process.env.BEHAVIOUR_STACK_USERNAME
export const stackPassword = process.env.BEHAVIOUR_STACK_PASSWORD
export const stackName = process.env.BEHAVIOUR_STACK_NAME
export const stackHostname = `fragalysis-${awxUsername}-${stackName}.${stackDomain}`
export const stackURL = `https://${stackHostname}`
export const testTarget = process.env.BEHAVIOUR_PLAYWRIGHT_TEST_TARGET
export const stackUsername: string = (process.env.BEHAVIOUR_STACK_USERNAME as string)
export const stackPassword: string = (process.env.BEHAVIOUR_STACK_PASSWORD as string)
export const stackName: string = (process.env.BEHAVIOUR_STACK_NAME || "behaviour" as string)
export const stackHostname: string = `fragalysis-${awxUsername}-${stackName}.${stackDomain}`
export const stackURL: string = `https://${stackHostname}`
export const testTarget: string = (process.env.BEHAVIOUR_PLAYWRIGHT_TEST_TARGET as string)
4 changes: 2 additions & 2 deletions playwright/fixture-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const test = baseTest.extend<{loggedInPage: any}> ({
await page.goto(`${stackURL}/accounts/login`)
// fill-in login details
await page.getByRole("link", {name: "Diamond CAS"}).click()
await page.getByRole("textbox", {name: "Username:"}).fill(`${stackUsername}`)
await page.getByRole("textbox", {name: "Password:"}).fill(`${stackPassword}`)
await page.getByRole("textbox", {name: "Username:"}).fill(stackUsername)
await page.getByRole("textbox", {name: "Password:"}).fill(stackPassword)
await page.getByRole("button", {name: "Login"}).click()
// Make the logged-in page available for tests
await use(page);
Expand Down
2 changes: 1 addition & 1 deletion playwright/test-fixture-login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* A test that simply ensures the login fixture is working.
* Test the login fixture.
*/
import { test } from './fixture-login'

Expand Down
8 changes: 5 additions & 3 deletions playwright/testlink-002.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* M2MS TestLink Test Case Oxford-2 (14 Nov 2024)
*
* Note: This test case uses the App Menu/Login rather than the login fixture.
* Note: This test case uses the App Menu/Login rather than the login fixture
* because it's about checking the front-end's login buttons, not the
* back-end's login process.
*/
import { test, expect } from '@playwright/test';
import { stackURL, stackUsername, stackPassword } from './config'
Expand All @@ -17,8 +19,8 @@ test('login', async ({ page }) => {
// 2
//---
await page.getByRole("link", {name: "Diamond CAS"}).click()
await page.getByRole("textbox", {name: "Username:"}).fill(`${stackUsername}`)
await page.getByRole("textbox", {name: "Password:"}).fill(`${stackPassword}`)
await page.getByRole("textbox", {name: "Username:"}).fill(stackUsername)
await page.getByRole("textbox", {name: "Password:"}).fill(stackPassword)
await page.getByRole("button", {name: "Login"}).click()
expect(page.getByText("You're logged in")).toBeVisible()
await page.getByRole("button", {name: /close/i}).click()
Expand Down

0 comments on commit 086b5d2

Please sign in to comment.