From 651c570985799103b7a784d515c49a8abc70e049 Mon Sep 17 00:00:00 2001 From: Tom Whittington Date: Thu, 12 Dec 2024 14:39:05 +0000 Subject: [PATCH] test: added more e2e tests in playwright --- README.md | 8 +- .../playwright/.env | 3 + .../playwright/package-lock.json | 16 +- .../playwright/package.json | 3 +- .../playwright/playwright.config.ts | 118 ++++++------- .../tests/journey/back-button.spec.ts | 157 +++++++----------- .../journey/date-missing-redirect.spec.ts | 20 +++ .../tests/journey/deny-public-access.spec.ts | 14 ++ .../playwright/tests/journey/journey.spec.ts | 145 ++++++++++++++++ .../playwright/tests/shared/processLogic.ts | 96 +++++++++++ .../playwright/tests/shared/urls-to-check.ts | 58 +++++++ .../playwright/.env | 3 + .../playwright/package-lock.json | 16 +- .../playwright/package.json | 3 +- .../playwright/playwright.config.ts | 1 + .../playwright/tests/smoke-tests.spec.ts | 14 +- 16 files changed, 507 insertions(+), 168 deletions(-) create mode 100644 tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env create mode 100644 tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/date-missing-redirect.spec.ts create mode 100644 tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/deny-public-access.spec.ts create mode 100644 tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/journey.spec.ts create mode 100644 tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/processLogic.ts create mode 100644 tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/urls-to-check.ts create mode 100644 tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/.env diff --git a/README.md b/README.md index 75c1e814..e7899de0 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,18 @@ This will pull in the exclusions such as the .cshtml files and will replicate co 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`` +- 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. diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env new file mode 100644 index 00000000..041b038f --- /dev/null +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env @@ -0,0 +1,3 @@ +WEBAPP_URL={URL OF THE HOME PAGE} +AUTH_SECRET={PASSWORD FOR ENVIRONMENT} +DOMAIN={DOMAIN FOR COOKIE TO BE ADDED TO (when local: localhost)} \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package-lock.json b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package-lock.json index 92b55adc..8c4b07e3 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package-lock.json +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package-lock.json @@ -10,7 +10,8 @@ "license": "ISC", "devDependencies": { "@playwright/test": "^1.49.0", - "@types/node": "^22.10.1" + "@types/node": "^22.10.1", + "dotenv": "^16.4.7" } }, "node_modules/@playwright/test": { @@ -39,6 +40,19 @@ "undici-types": "~6.20.0" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package.json b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package.json index 382b77d7..bbd0a9fb 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package.json +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/package.json @@ -9,6 +9,7 @@ "description": "", "devDependencies": { "@playwright/test": "^1.49.0", - "@types/node": "^22.10.1" + "@types/node": "^22.10.1", + "dotenv": "^16.4.7" } } diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/playwright.config.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/playwright.config.ts index b735a62d..b0783c55 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/playwright.config.ts +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/playwright.config.ts @@ -1,4 +1,4 @@ -import { defineConfig, devices } from '@playwright/test'; +import {defineConfig, devices} from '@playwright/test'; /** * Read environment variables from file. @@ -11,69 +11,71 @@ import { defineConfig, devices } from '@playwright/test'; /** * 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, + 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', - }, - - /* Configure projects for major browsers */ - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', }, - { - name: 'firefox', - use: { ...devices['Desktop Firefox'] }, - }, + /* Configure projects for major browsers */ + projects: [ + { + name: 'chromium', + use: {...devices['Desktop Chrome']}, + }, - { - name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, + /* + { + 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 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' }, + // }, + ], - /* 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, // }, - ], - - /* 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, - // }, }); diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/back-button.spec.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/back-button.spec.ts index 5107d06b..047a89aa 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/back-button.spec.ts +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/back-button.spec.ts @@ -1,110 +1,71 @@ -import { test, expect } from '@playwright/test'; +import { + test +} from '@playwright/test'; + +import { + startJourney, + checkUrl, + clickBackButton, + whereWasTheQualificationAwarded, + whenWasQualificationStarted, + whatLevelIsTheQualification, + whatIsTheAwardingOrganisation, + selectQualification, + confirmQualificiation, + processAdditionalRequirement, + confirmAdditonalRequirementsAnswers, + checkDetailsPage +} from '../shared/processLogic'; test.describe("A spec used to test the main back button route through the journey", () => { - // Mock details found in Dfe.EarlyYearsQualification.Mock.Content.MockContentfulService. - test("back buttons should all navigate to the appropriate pages in the main journey", async ({ page, context }) => { - await context.addCookies([ - { name: 'auth-secret', value: process.env.AUTH_SECRET, path: '/', domain: process.env.WEBAPP_URL } - ]); - - // home page - await page.goto("/"); - await expect(page.locator("#start-now-button")).toHaveCount(1); - await page.locator("#start-now-button").click(); - - // where-was-the-qualification-awarded page - england selection moves us on - expect(page.url()).toContain("/questions/where-was-the-qualification-awarded"); - await page.locator("#england").click(); - await page.locator("#question-submit").click(); - - // when-was-the-qualification-started page - valid date moves us on - expect(page.url()).toContain("/questions/when-was-the-qualification-started"); - await page.locator("#date-started-month").fill("6"); - await page.locator("#date-started-year").fill("2022"); - await page.locator("#question-submit").click(); - - // what-level-is-the-qualification page - valid level moves us on - expect(page.url()).toContain("/questions/what-level-is-the-qualification"); - await page.locator("#3").click(); - await page.locator("#question-submit").click(); - - // what-is-the-awarding-organisation page - valid awarding organisation moves us on - expect(page.url()).toContain("/questions/what-is-the-awarding-organisation"); - await page.locator("#awarding-organisation-select").selectOption("1"); - await page.locator("#question-submit").click(); - - // qualifications page - click a qualification in the list to move us on - expect(page.url()).toContain("/qualifications"); - await page.locator("a[href=\"/confirm-qualification/EYQ-240\"]").click(); - - // check additional questions first page - expect(page.url()).toContain("/qualifications/check-additional-questions/EYQ-240/1"); - await page.locator("#yes").click(); - await page.locator("#additional-requirement-button").click(); - - // check additional questions second page - expect(page.url()).toContain("/qualifications/check-additional-questions/EYQ-240/2"); - await page.locator("#no").click(); - await page.locator("#additional-requirement-button").click(); - - // confirm answers page - expect(page.url()).toContain("/qualifications/check-additional-questions/EYQ-240/confirm-answers"); - await page.locator("#confirm-answers").click(); - - // qualifications page - expect(page.url()).toContain("/qualifications/qualification-details/EYQ-240"); - - /// Time to go back through the journey! - await page.locator("#back-button").click(); - - // confirm answers page - expect(page.url()).toContain("/qualifications/check-additional-questions/EYQ-240/confirm-answers"); - await page.locator("#back-button").click(); - - // answered additional questions, so back to second additional questions page - expect(page.url()).toContain("/qualifications/check-additional-questions/EYQ-240/2"); - await page.locator("#back-button").click(); - - // answered additional questions, so back to first additional questions page - expect(page.url()).toContain("/qualifications/check-additional-questions/EYQ-240/1"); - await page.locator("#back-button").click(); - - // qualifications page - expect(page.url()).toContain("/qualifications"); - await page.locator("#back-button").click(); - - expect(page.url()).toContain("/questions/what-is-the-awarding-organisation"); - await page.locator("#back-button").click(); - - expect(page.url()).toContain("/questions/what-level-is-the-qualification"); - await page.locator("#back-button").click(); - - expect(page.url()).toContain("/questions/when-was-the-qualification-started"); - await page.locator("#back-button").click(); - - expect(page.url()).toContain("/questions/where-was-the-qualification-awarded"); - await page.locator("#back-button").click(); - - expect(page.url()).toBe(process.env.WEBAPP_URL + "/"); + //Mock details found in Dfe.EarlyYearsQualification.Mock.Content.MockContentfulService. + test.beforeEach(async ({page, context}) => { + await startJourney(page, context); + }); + test("back buttons should all navigate to the appropriate pages in the main journey", async ({page}) => { + + await whereWasTheQualificationAwarded(page, "#england"); + await whenWasQualificationStarted(page, "6", "2022"); + await whatLevelIsTheQualification(page, 3); + await whatIsTheAwardingOrganisation(page, 1); + await selectQualification(page, "EYQ-240"); + await confirmQualificiation(page, "#yes"); + await processAdditionalRequirement(page, "EYQ-240", 1, "#yes"); + await processAdditionalRequirement(page, "EYQ-240", 2, "#no"); + await confirmAdditonalRequirementsAnswers(page, "EYQ-240"); + checkDetailsPage(page, "EYQ-240"); + + await clickBackButton(page); + checkUrl(page, "/qualifications/check-additional-questions/EYQ-240/confirm-answers"); + await clickBackButton(page); + checkUrl(page, "/qualifications/check-additional-questions/EYQ-240/2"); + await clickBackButton(page); + checkUrl(page, "/qualifications/check-additional-questions/EYQ-240/1"); + await clickBackButton(page); + checkUrl(page, "/qualifications"); + await clickBackButton(page); + checkUrl(page, "/questions/what-is-the-awarding-organisation"); + await clickBackButton(page); + checkUrl(page, "/questions/what-level-is-the-qualification"); + await clickBackButton(page); + checkUrl(page, "/questions/when-was-the-qualification-started"); + await clickBackButton(page); + checkUrl(page, "/questions/where-was-the-qualification-awarded"); + await clickBackButton(page); + checkUrl(page, process.env.WEBAPP_URL + "/"); }); test.describe("back buttons should all navigate to the appropriate pages in the main journey", async () => { - test.beforeEach(async ({page, context}) => { - await context.addCookies([ - { name: 'auth-secret', value: process.env.AUTH_SECRET, path: '/', domain: process.env.WEBAPP_URL } - ]); - }); - - test("the back button on the accessibility statement page navigates back to the home page", async ({ page, context }) => { + test("the back button on the accessibility statement page navigates back to the home page", async ({page}) => { await page.goto("/accessibility-statement"); - await page.locator("#back-button").click(); - expect(page.url()).toBe(process.env.WEBAPP_URL + "/"); + await clickBackButton(page); + checkUrl(page, process.env.WEBAPP_URL + "/"); }); - test("the back button on the cookies preference page navigates back to the home page", async ({ page, context }) => { + test("the back button on the cookies preference page navigates back to the home page", async ({page}) => { await page.goto("/cookies"); - await page.locator("#back-button").click(); - expect(page.url()).toBe(process.env.WEBAPP_URL + "/"); + await clickBackButton(page); + checkUrl(page, process.env.WEBAPP_URL + "/"); }); }); }); diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/date-missing-redirect.spec.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/date-missing-redirect.spec.ts new file mode 100644 index 00000000..2e3a6a45 --- /dev/null +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/date-missing-redirect.spec.ts @@ -0,0 +1,20 @@ +import {test} from '@playwright/test'; +import {pagesThatRedirectIfDateMissing} from "../shared/urls-to-check"; +import {startJourney, checkUrl} from '../shared/processLogic'; + +test.describe('A spec used to check that if the user skips entering the date of the qual, then they are redirected back to the date selection page', () => { + + test.beforeEach(async ({ + page, + context + }) => { + await startJourney(page, context); + }); + + pagesThatRedirectIfDateMissing.forEach((url) => { + test(`navigating to ${url} should redirect the user to the date selection page`, async ({page}) => { + await page.goto(url); + checkUrl(page, "/questions/when-was-the-qualification-started"); + }) + }); +}); \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/deny-public-access.spec.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/deny-public-access.spec.ts new file mode 100644 index 00000000..acfaad19 --- /dev/null +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/deny-public-access.spec.ts @@ -0,0 +1,14 @@ +import {test} from '@playwright/test'; +import { + checkUrl, + checkValue +} from '../shared/processLogic'; + +test.describe('A spec used to check a new user is challenged to enter the secret', () => { + test("should redirect the user to the challenge page", async ({page}) => { + await page.goto("/"); + checkUrl(page, "/challenge?redirectAddress=%2F"); + checkValue(page, "#redirectAddress", "/"); + checkValue(page, "#PasswordValue", ''); + }); +}); \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/journey.spec.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/journey.spec.ts new file mode 100644 index 00000000..ec04a8f7 --- /dev/null +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/journey/journey.spec.ts @@ -0,0 +1,145 @@ +import { + test, + expect +} from '@playwright/test'; + +import { + startJourney, + checkUrl, + checkValue, + checkText, + clickBackButton, + refineQualificationSearch, + whereWasTheQualificationAwarded, + whenWasQualificationStarted, + whatLevelIsTheQualification, + whatIsTheAwardingOrganisation, + selectQualification, + confirmQualificiation, + processAdditionalRequirement, + confirmAdditonalRequirementsAnswers, + checkDetailsPage +} from '../shared/processLogic'; + +test.describe('A spec used to test the various routes through the journey', () => { + test.beforeEach(async ({page, context}) => { + await startJourney(page, context); + }); + + test("should redirect the user when they select qualification was awarded outside the UK", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#outside-uk"); + checkUrl(page, "/advice/qualification-outside-the-united-kingdom"); + }); + + test("should redirect the user when they select qualification was awarded in Scotland", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#scotland"); + checkUrl(page, "/advice/qualifications-achieved-in-scotland"); + }); + + test("should redirect the user when they select qualification was awarded in Wales", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#wales"); + checkUrl(page, "/advice/qualifications-achieved-in-wales"); + }); + + test("should redirect the user when they select qualification was awarded in Northern Ireland", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#northern-ireland"); + checkUrl(page, "/advice/qualifications-achieved-in-northern-ireland"); + }); + + test("should redirect the user when they select qualification was awarded in England", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#england"); + await whenWasQualificationStarted(page, "6", "2022"); + await whatLevelIsTheQualification(page, 3); + await whatIsTheAwardingOrganisation(page, 1); + await selectQualification(page, "EYQ-240"); + await confirmQualificiation(page, "#yes"); + await processAdditionalRequirement(page, "EYQ-240", 1, "#yes"); + await processAdditionalRequirement(page, "EYQ-240", 2, "#yes"); + await confirmAdditonalRequirementsAnswers(page, "EYQ-240"); + checkDetailsPage(page, "EYQ-240"); + }); + + test("Selecting the 'Qualification is not on the list' link on the qualification list page should navigate to the correct advice page", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#england"); + await whenWasQualificationStarted(page, "6", "2022"); + await whatLevelIsTheQualification(page, 3); + await whatIsTheAwardingOrganisation(page, 1); + + // qualifications page - click a qualification in the list to move us on + checkUrl(page, "/qualifications"); + + // click not on the list link + await page.locator('a[href="/advice/qualification-not-on-the-list"]').click(); + + // qualification not on the list page + checkUrl(page, "/advice/qualification-not-on-the-list"); + checkText(page, "#advice-page-heading", "This is the level 3 page"); + + // check back button goes back to the qualifications list page + await clickBackButton(page); + checkUrl(page, "/qualifications"); + }); + + test("Selecting qualification level 7 started after 1 Sept 2014 should navigate to the level 7 post 2014 advice page", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#england"); + await whenWasQualificationStarted(page, "8", "2015"); + await whatLevelIsTheQualification(page, 7); + checkUrl(page, "/advice/level-7-qualification-post-2014"); + await clickBackButton(page); + checkUrl(page, "/questions/what-level-is-the-qualification"); + }); + + test("Should remove the search criteria when a user goes to the awarding organisation page and back again", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#england"); + await whenWasQualificationStarted(page, "6", "2022"); + await whatLevelIsTheQualification(page, 3); + await whatIsTheAwardingOrganisation(page, 1); + checkUrl(page, "/qualifications"); + refineQualificationSearch(page, 'test'); + checkUrl(page, "/qualifications"); + await clickBackButton(page); + await whatIsTheAwardingOrganisation(page, 1); + checkUrl(page, "/qualifications"); + checkValue(page, "#refineSearch", ''); + }); + + [ + ['09', '2014'], + ['06', '2017'], + ['08', '2019'], + ].forEach((date) => { + const [month, year] = date; + + test(`should redirect when qualification is level 2 and startMonth is ${month} and startYear is ${year}`, async ({page}) => { + await whereWasTheQualificationAwarded(page, "#england"); + await whenWasQualificationStarted(page, month, year); + await whatLevelIsTheQualification(page, 2); + checkUrl(page, "/advice/level-2-qualifications-started-between-1-sept-2014-and-31-aug-2019"); + }); + }); + + test("should bypass remaining additional requirement question when answering yes to the Qts question", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#england"); + await whenWasQualificationStarted(page, "6", "2022"); + await whatLevelIsTheQualification(page, 6); + await whatIsTheAwardingOrganisation(page, 1); + await selectQualification(page, "EYQ-108"); + await confirmQualificiation(page, "#yes"); + await processAdditionalRequirement(page, "EYQ-108", 1, "#yes"); + await confirmAdditonalRequirementsAnswers(page, "EYQ-108"); + checkDetailsPage(page, "EYQ-108"); + }); + + test("should not bypass remaining additional requirement question when answering no to the Qts question", async ({page}) => { + await whereWasTheQualificationAwarded(page, "#england"); + await whenWasQualificationStarted(page, "6", "2022"); + await whatLevelIsTheQualification(page, 6); + await whatIsTheAwardingOrganisation(page, 1); + await selectQualification(page, "EYQ-108"); + await confirmQualificiation(page, "#yes"); + await processAdditionalRequirement(page, "EYQ-108", 1, "#no"); + await processAdditionalRequirement(page, "EYQ-108", 2, "#yes"); + await confirmAdditonalRequirementsAnswers(page, "EYQ-108"); + checkDetailsPage(page, "EYQ-108"); + }); +}); \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/processLogic.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/processLogic.ts new file mode 100644 index 00000000..8f23cab0 --- /dev/null +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/processLogic.ts @@ -0,0 +1,96 @@ +import {expect} from "@playwright/test"; + + +export async function startJourney(page: any, context: any) { + await context.addCookies([ + { + name: 'auth-secret', + value: process.env.AUTH_SECRET, + path: '/', + domain: process.env.DOMAIN + } + ]); + await page.goto("/"); + await expect(page.locator("#start-now-button")).toBeVisible(); + await page.locator("#start-now-button").click(); +} + +export function checkUrl(page: any, expectedUrl: string) { + expect(page.url()).toContain(expectedUrl); +} + +export function checkText(page: any, locator: string, expectedText: string) { + expect(page.locator(locator)).toHaveText(expectedText); +} + +export function checkValue(page: any, locator: string, expectedValue: any) { + expect(page.locator(locator)).toHaveValue(expectedValue); +} + +export async function clickBackButton(page: any) { + await page.locator("#back-button").click(); +} + +export async function whereWasTheQualificationAwarded(page: any, location: string) { + checkUrl(page, "/questions/where-was-the-qualification-awarded"); + await page.locator(location).click(); + await page.locator("#question-submit").click(); +} + +export async function whenWasQualificationStarted(page: any, month: string, year: string) { + checkUrl(page, '/questions/when-was-the-qualification-started'); + await page.locator("#date-started-month").fill(month); + await page.locator("#date-started-year").fill(year); + await page.locator("#question-submit").click(); +} + +export async function whatLevelIsTheQualification(page: any, level: number) { + // what-level-is-the-qualification page - valid level moves us on + checkUrl(page, "/questions/what-level-is-the-qualification"); + await page.locator('input[id="' + level + '"]').click(); + await page.locator("#question-submit").click(); +} + +export async function whatIsTheAwardingOrganisation(page: any, dropdownIndex: number) { + // what-is-the-awarding-organisation page - valid awarding organisation moves us on + checkUrl(page, "/questions/what-is-the-awarding-organisation"); + await page.locator("#awarding-organisation-select").selectOption({index: dropdownIndex}); + await page.locator("#question-submit").click(); +} + +export async function selectQualification(page: any, qualificationId: string) { + // qualifications page - click a qualification in the list to move us on + checkUrl(page, "/qualifications"); + await page.locator("a[href=\"/confirm-qualification/" + qualificationId + "\"]").click(); + checkUrl(page, "/confirm-qualification/" + qualificationId); +} + +export async function confirmQualificiation(page: any, answer: string) { + // confirm qualification page + await page.locator(answer).click(); + await page.locator('#confirm-qualification-button').click(); + +} + +export async function processAdditionalRequirement(page: any, qualificationId: string, additionalRequirementIndex: number, answer: string) { + // check additional questions first page + checkUrl(page, "/qualifications/check-additional-questions/" + qualificationId + "/" + additionalRequirementIndex); + await page.locator(answer).click(); + await page.locator("#additional-requirement-button").click(); + +} + +export async function confirmAdditonalRequirementsAnswers(page: any, qualificationId: string) { + checkUrl(page, "/qualifications/check-additional-questions/" + qualificationId + "/confirm-answers"); + await page.locator("#confirm-answers").click(); +} + +export function checkDetailsPage(page: any, qualificationId: string) { + checkUrl(page, "/qualifications/qualification-details/" + qualificationId); +} + +export async function refineQualificationSearch(page: any, searchTerm: string) { + await page.locator("#refineSearch").fill(searchTerm); + checkValue(page, "#refineSearch", searchTerm); + await page.locator("#refineSearchButton").click(); +} diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/urls-to-check.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/urls-to-check.ts new file mode 100644 index 00000000..8ad06ff0 --- /dev/null +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/urls-to-check.ts @@ -0,0 +1,58 @@ +export const pages = [ + "/", + "/accessibility-statement", + "/cookies", + "/questions/where-was-the-qualification-awarded", + "/questions/when-was-the-qualification-started", + "/questions/what-level-is-the-qualification", + "/questions/what-is-the-awarding-organisation", + "/qualifications", + "/confirm-qualification/EYQ-240", + "/qualifications/qualification-details/EYQ-240", + "/qualifications/check-additional-questions/EYQ-240/1", + "/advice/qualification-outside-the-united-kingdom", + "/advice/level-2-qualifications-started-between-1-sept-2014-and-31-aug-2019", + "/advice/qualifications-achieved-in-scotland", + "/advice/qualifications-achieved-in-wales", + "/advice/qualifications-achieved-in-northern-ireland", + "/advice/qualification-not-on-the-list", + "/advice/level-7-qualification-post-2014" +]; + +export const pagesWithForms = [ + "/questions/where-was-the-qualification-awarded", + "/questions/when-was-the-qualification-started", + "/questions/what-level-is-the-qualification", + "/questions/what-is-the-awarding-organisation", + "/cookies", + "/qualifications", + "/confirm-qualification/EYQ-240", + "/qualifications/check-additional-questions/EYQ-240/1" +]; + +export const pagesWithoutFormsOrRedirects = [ + "/", + "/accessibility-statement", + "/advice/qualification-outside-the-united-kingdom", + "/advice/qualifications-achieved-in-scotland", + "/advice/qualifications-achieved-in-wales", + "/advice/qualifications-achieved-in-northern-ireland", + "/advice/qualification-not-on-the-list", +] + +export const pagesWithoutFormsWithRedirects = [ + "/qualifications/qualification-details/EYQ-240", + "/advice/level-2-qualifications-started-between-1-sept-2014-and-31-aug-2019", + "/advice/level-7-qualification-post-2014" +] + +export const pagesThatRedirectIfDateMissing = [ + "/questions/what-level-is-the-qualification", + "/questions/what-is-the-awarding-organisation", + "/qualifications", + "/confirm-qualification/EYQ-240", + "/qualifications/qualification-details/EYQ-240", + "/qualifications/check-additional-questions/EYQ-240/1", + "/advice/level-2-qualifications-started-between-1-sept-2014-and-31-aug-2019", + "/advice/level-7-qualification-post-2014" +] \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/.env b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/.env new file mode 100644 index 00000000..041b038f --- /dev/null +++ b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/.env @@ -0,0 +1,3 @@ +WEBAPP_URL={URL OF THE HOME PAGE} +AUTH_SECRET={PASSWORD FOR ENVIRONMENT} +DOMAIN={DOMAIN FOR COOKIE TO BE ADDED TO (when local: localhost)} \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/package-lock.json b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/package-lock.json index e24e4cf9..d4b91a6e 100644 --- a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/package-lock.json +++ b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/package-lock.json @@ -10,7 +10,8 @@ "license": "ISC", "devDependencies": { "@playwright/test": "^1.48.2", - "@types/node": "^22.9.0" + "@types/node": "^22.9.0", + "dotenv": "^16.4.7" } }, "node_modules/@playwright/test": { @@ -39,6 +40,19 @@ "undici-types": "~6.19.8" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", diff --git a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/package.json b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/package.json index ac4d7f85..ed162174 100644 --- a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/package.json +++ b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/package.json @@ -9,6 +9,7 @@ "description": "", "devDependencies": { "@playwright/test": "^1.48.2", - "@types/node": "^22.9.0" + "@types/node": "^22.9.0", + "dotenv": "^16.4.7" } } diff --git a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/playwright.config.ts b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/playwright.config.ts index 28b95afc..423f82ed 100644 --- a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/playwright.config.ts +++ b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/playwright.config.ts @@ -8,6 +8,7 @@ import { defineConfig, devices } from '@playwright/test'; /** * See https://playwright.dev/docs/test-configuration. */ +require('dotenv').config(); export default defineConfig({ testDir: './tests', /* Run tests in files in parallel */ diff --git a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/tests/smoke-tests.spec.ts b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/tests/smoke-tests.spec.ts index f82a808a..dc09606f 100644 --- a/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/tests/smoke-tests.spec.ts +++ b/tests/Dfe.EarlyYearsQualification.SmokeTests/playwright/tests/smoke-tests.spec.ts @@ -2,21 +2,21 @@ import { test, expect } from '@playwright/test'; test.describe("A spec used to smoke test the environment once a deployment has happened", () => { test("should return search results", async ({ page, context }) => { - + // attempt to set cookie and navigate to start page - await context.addCookies([ - { name: 'auth-secret', value: process.env.AUTH_SECRET, path: '/', domain: process.env.WEBAPP_URL } - ]); - + await context.addCookies([ + { name: 'auth-secret', value: process.env.AUTH_SECRET, path: '/', domain: process.env.DOMAIN } + ]); + await page.goto("/"); - + //if we end up navigated to the challenge page, then fill in the password and continue if (page.url().includes("challenge")) { await page.locator("#PasswordValue").fill(process.env.AUTH_SECRET); await page.locator("#question-submit").click(); await page.waitForURL("/"); } - + // home page await expect(page.locator("#start-now-button")).toBeVisible(); await page.locator("#start-now-button").click();