Skip to content
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

Feature/e2e tests conversion to playwright #486

Draft
wants to merge 40 commits into
base: release/02-Dec-24-R1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eaae6af
enabled webkit smoke tests
DanielClarkeEducation Dec 2, 2024
cd23035
Initialised Playwright for E2E tests plus updated README with details…
DanielClarkeEducation Dec 2, 2024
f3e9183
release branch merge
DanielClarkeEducation Dec 2, 2024
eac53a8
Added new back button tests + new action and modification to PR workflow
DanielClarkeEducation Dec 6, 2024
ecf297c
fixed GitHub action
DanielClarkeEducation Dec 6, 2024
e032e2a
Added base url to playwright config
DanielClarkeEducation Dec 6, 2024
58a06d0
change to back button tests
DanielClarkeEducation Dec 6, 2024
a1694e5
fix for checking home page
DanielClarkeEducation Dec 6, 2024
027e399
test
DanielClarkeEducation Dec 6, 2024
4767019
test
DanielClarkeEducation Dec 6, 2024
45e1afb
Merge branch 'release/02-Dec-24-R1' into feature/e2e-tests-conversion…
DanielClarkeEducation Dec 6, 2024
651c570
test: added more e2e tests in playwright
ThomasWhittington Dec 12, 2024
7e14903
Merge branch 'release/02-Dec-24-R1' into feature/e2e-tests-conversion…
sam-c-dfe Dec 17, 2024
2c6f471
Added domain to env variables
sam-c-dfe Dec 17, 2024
7248f53
Updated url
sam-c-dfe Dec 18, 2024
a0adb8c
Wrapped url in quotes
sam-c-dfe Dec 18, 2024
7784c98
Added tracing
sam-c-dfe Dec 18, 2024
f6607e0
Updated action
sam-c-dfe Dec 18, 2024
997dfd8
Updated config and added a print to see what the page url is to help …
sam-c-dfe Dec 18, 2024
a83d6aa
Amended url
sam-c-dfe Dec 19, 2024
8b88416
Extended timeout
sam-c-dfe Dec 19, 2024
ef5f4cb
Changed the domain
sam-c-dfe Dec 19, 2024
185db13
Switched to yarn to try fix running issue
sam-c-dfe Dec 19, 2024
4ea89cc
Changed node version
sam-c-dfe Dec 19, 2024
2b7cb06
Changed runner
sam-c-dfe Dec 19, 2024
1e154e1
Changed the runner
sam-c-dfe Dec 19, 2024
4fbc9bd
Changed the trace type
sam-c-dfe Dec 19, 2024
3daafbe
added page title to the output
sam-c-dfe Dec 19, 2024
50aac87
Added filter to shorten the number of tests run for now
sam-c-dfe Dec 19, 2024
4e450bf
Added waituntil
sam-c-dfe Dec 19, 2024
d23341e
Added expect for the page title
sam-c-dfe Dec 19, 2024
a958b59
Changed page title check
sam-c-dfe Dec 19, 2024
79e42b6
Ignore https errors to test if that's the issue?
sam-c-dfe Dec 20, 2024
7090ae9
write document data to output
sam-c-dfe Dec 20, 2024
3245d99
changed outputs
sam-c-dfe Dec 20, 2024
70cbf9e
Changed to console log
sam-c-dfe Dec 20, 2024
201aba3
Try switching to using playwright webserver
sam-c-dfe Dec 20, 2024
c0b8a83
Tweaked config
sam-c-dfe Dec 20, 2024
2c2a031
Config change
sam-c-dfe Dec 20, 2024
7ba56a4
Updated the config
sam-c-dfe Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/actions/run-playwright-e2e-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Run Playwright end to end tests
description: Run end to end tests using Playwright

inputs:
webapp_url:
required: true
type: string
auth_secret:
required: true
type: string

runs:
using: composite
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18.x
# - name: Install dependencies
# shell: bash
# working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/playwright
# run: npm ci
- name: Install dependencies
shell: bash
working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/playwright
run: npm install -g yarn && yarn install --frozen-lockfile
# - name: Install Playwright Browsers
# shell: bash
# working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/playwright
# run: npx playwright install --with-deps
- name: Install Playwright Browsers
shell: bash
working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/playwright
run: yarn playwright install --with-deps
- name: Run Playwright tests
shell: bash
working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/playwright
env:
CI: true
run: WEBAPP_URL="http://localhost:3000" AUTH_SECRET=${{ inputs.auth_secret }} DOMAIN="localhost" npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
16 changes: 11 additions & 5 deletions .github/workflows/code-pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ concurrency:
env:
DOTNET_VERSION: 8
SOLUTION_NAME: 'Dfe.EarlyYearsQualification.sln'
URL: http://127.0.0.1:5000
URL: 'http://127.0.0.1:5000'

jobs:

build-app:
name: Build, check and run tests
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

steps:
- name: Check out repository
Expand All @@ -52,10 +52,16 @@ jobs:
url: ${{ env.URL }}
auth_secret: ${{ secrets.WEBAPP_E2E_ACCESS_KEY }}

- name: Run e2e tests
uses: ./.github/actions/run-e2e-tests
# - name: Run e2e tests
# uses: ./.github/actions/run-e2e-tests
# with:
# url: ${{ env.URL }}
# auth_secret: ${{ secrets.WEBAPP_E2E_ACCESS_KEY }}

- name: Run Playwright e2e tests
uses: ./.github/actions/run-playwright-e2e-tests
with:
url: ${{ env.URL }}
webapp_url: ${{ env.URL }}
auth_secret: ${{ secrets.WEBAPP_E2E_ACCESS_KEY }}

- name: Run Accessibility tests
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@ dotnet test --collect:"XPlat Code Coverage" --settings coverlet.runsettings
```

This will pull in the exclusions such as the .cshtml files and will replicate coverage in the GitHub Actions.

## End to end/Smoke testing

End to end tests are ran using [Playwright](https://playwright.dev/).

To run the tests, run the following commands:
- Add some environment variables
```
WEBAPP_URL={URL OF THE HOME PAGE}
AUTH_SECRET={PASSWORD FOR ENVIRONMENT}
DOMAIN={DOMAIN FOR COOKIE TO BE ADDED TO (when local: localhost)}
```
- Run the local web app.
- Navigate to the correct folder, be it:
- ``cd tests/Dfe.EarlyYearsQualification.E2ETests/playwright`` for the E2E tests.
- ``cd tests/Dfe.EarlyYearsQualification.SmokeTests/playwright`` for the smoke tests.
- Tell Node Version Manager that you want the latest version with: ``nvm use node --lts``
- Run the tests with: ``npx playwright test`` (add --ui to run the tests in playwrights UI)

### Problems with Safari?
If you notice you are having issues with running Safari tests locally and them failing then there is a fix.

This is happening due to because Safari strictly enforcing the `upgrade-insecure-requests` header. This is converting the HTTP requests to HTTPS.

To fix this, comment out this line in the web app's [Program.cs](https://github.com/DFE-Digital/check-an-early-years-qualification/blob/main/src/Dfe.EarlyYearsQualification.Web/Program.cs#L138-L140). This will remove the header from all requests and should let Safari use HTTP.
3 changes: 3 additions & 0 deletions tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WEBAPP_URL='http://localhost:3000'
AUTH_SECRET=ABC
DOMAIN=localhost

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "playwright",
"version": "1.0.0",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@playwright/test": "^1.49.0",
"@types/node": "^22.10.1",
"dotenv": "^16.4.7"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {defineConfig, devices} from '@playwright/test';

/**
* 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.
*/
require('dotenv').config();

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: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.WEBAPP_URL,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',

ignoreHTTPSErrors: true,
},
/* 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:`cd ../../../src/Dfe.EarlyYearsQualification.Web && dotnet run --urls "${process.env.WEBAPP_URL}" --project ./Dfe.EarlyYearsQualification.Web.csproj --UseMockContentful=true --ServiceAccess:Keys:0="${process.env.AUTH_SECRET}"`,
url: process.env.WEBAPP_URL,
reuseExistingServer: !process.env.CI,
},
});
Loading
Loading