Skip to content

Commit

Permalink
Re-use shared steps from e2e project + add CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl committed Aug 13, 2024
1 parent bb2fa32 commit 489dd02
Show file tree
Hide file tree
Showing 12 changed files with 553 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
node_modules
public
assets
test-results
playwright-report
cypress.json
reporter-config.json
dist/
21 changes: 13 additions & 8 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Playwright Tests
on:
push:
branches:
- main
pull_request:
schedule:
- cron: "0 8 * * MON-FRI"
workflow_dispatch:

jobs:
test:
timeout-minutes: 60
Expand All @@ -16,15 +16,20 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
run: npx playwright install
- name: Add config
run: cp e2e_tests/.env.example e2e_tests/.env
- name: Run Playwright tests
run: npx playwright test
run: npm run e2e-test
env:
DELIUS_USERNAME: ${{ secrets.E2E_DELIUS_USERNAME }}
DELIUS_PASSWORD: ${{ secrets.E2E_DELIUS_PASSWORD }}
- name: Publish HTML report
if: always()
uses: JamesIves/github-pages-deploy-action@94f3c658273cf92fb48ef99e5fbc02bd2dc642b2 # v4
with:
folder: playwright-report
target-folder: playwright-report/${{ github.ref_name }}/${{ github.run_id }}/${{ github.run_attempt }}"
target-folder: playwright-report/${{ github.ref_name }}/${{ github.run_id }}/${{ github.run_attempt }}
- name: Output HTML report URL
if: always()
run: echo '[🎭 Playwright HTML Report](https://ministryofjustice.github.io/hmpps-probation-integration-e2e-tests/${{ env.report-dir }})' | tee -a "$GITHUB_STEP_SUMMARY"
run: echo '[🎭 Playwright HTML Report](https://ministryofjustice.github.io/hmpps-probation-integration-e2e-tests/playwright-report/${{ github.ref_name }}/${{ github.run_id }}/${{ github.run_attempt }})' | tee -a "$GITHUB_STEP_SUMMARY"
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

NODE_ENV=dev && node_modules/.bin/lint-staged && npm run typecheck && npm test
NODE_ENV=dev && node_modules/.bin/lint-staged && npm run typecheck && npm test
4 changes: 2 additions & 2 deletions .zap/autorun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ env:
users:
- name: "TestUser"
credentials:
username: "$ZAP_USERNAME"
password: "$ZAP_PASSWORD"
username: "$E2E_DELIUS_USERNAME"
password: "$E2E_DELIUS_PASSWORD"
parameters:
failOnError: true
failOnWarning: false
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ npm run int-test
npm run int-test-ui
```

### Running end-to-end tests
Create a `.env` file in the e2e_tests directory with your Delius credentials. You can use `.env.example` as a template.
```shell
cp -n .env.example .env
```

Run the tests
```shell
npm run e2e-test

# Or, run in debug mode to enable breakpoints and test recorder
npm run e2e-test:debug
```

### Dependency Checks

The template project has implemented some scheduled checks to ensure that key dependencies are kept up to date.
Expand Down
7 changes: 7 additions & 0 deletions e2e_tests/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# URLs
DELIUS_URL=https://ndelius.test.probation.service.justice.gov.uk
MANAGE_A_SUPERVISION_URL=https://manage-a-supervision-dev.hmpps.service.justice.gov.uk

# Credentials
#DELIUS_USERNAME=example
#DELIUS_PASSWORD=example
10 changes: 0 additions & 10 deletions e2e_tests/steps/login.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { expect, test } from '@playwright/test'
import * as dotenv from 'dotenv'
import { DateTime } from 'luxon'
import { deliusPerson } from '@ministryofjustice/hmpps-probation-integration-e2e-tests/steps/delius/utils/person'
import { createOffender } from '@ministryofjustice/hmpps-probation-integration-e2e-tests/steps/delius/offender/create-offender'
import { login as loginToDelius } from '@ministryofjustice/hmpps-probation-integration-e2e-tests/steps/delius/login'
import loginToManageMySupervision from '../steps/login'
import { login as loginToManageMySupervision } from '@ministryofjustice/hmpps-probation-integration-e2e-tests/steps/manage-a-supervision/login'

dotenv.config() // read environment variables into process.env
dotenv.config({ path: 'e2e_tests/.env' }) // read environment variables into process.env

test('Verify the persons header details in Manage a Supervision', async ({ page }) => {
test('Verify the header details', async ({ page }) => {
// Create a person in Delius
await loginToDelius(page)
const person = deliusPerson()
const crn = await createOffender(page, { person })
Expand All @@ -23,6 +25,8 @@ test('Verify the persons header details in Manage a Supervision', async ({ page
await expect(page).toHaveTitle('Manage a Supervision - Overview')
await expect(page.locator('[data-qa="crn"]')).toContainText(crn)
await expect(page.locator('[data-qa="name"]')).toContainText(`${person.firstName} ${person.lastName}`)
await expect(page.locator('[data-qa="headerDateOfBirthValue"]')).toContainText('27 October 1961')
await expect(page.locator('[data-qa="headerDateOfBirthValue"]')).toContainText(
DateTime.fromJSDate(person.dob).toFormat('d MMMM yyyy'),
)
await expect(page.locator('[data-qa="tierValue"]').first()).toContainText('D0')
})
Loading

0 comments on commit 489dd02

Please sign in to comment.