diff --git a/.github/actions/run-playwright-e2e-tests/action.yml b/.github/actions/run-playwright-e2e-tests/action.yml index e39dfe97..2c902f6d 100644 --- a/.github/actions/run-playwright-e2e-tests/action.yml +++ b/.github/actions/run-playwright-e2e-tests/action.yml @@ -37,7 +37,7 @@ runs: working-directory: ./tests/Dfe.EarlyYearsQualification.E2ETests/playwright env: CI: true - run: WEBAPP_URL="${{ inputs.webapp_url }}" AUTH_SECRET=${{ inputs.auth_secret }} DOMAIN="127.0.0.1" npx playwright test + run: WEBAPP_URL="http://localhost:3000" AUTH_SECRET=${{ inputs.auth_secret }} DOMAIN="localhost" npx playwright test - uses: actions/upload-artifact@v4 if: ${{ !cancelled() }} with: diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env index 041b038f..875cbb25 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/.env @@ -1,3 +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 +WEBAPP_URL='http://localhost:3000' +AUTH_SECRET=ABC +DOMAIN=localhost \ No newline at end of file diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/playwright.config.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/playwright.config.ts index 4b6359ef..62ab7319 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/playwright.config.ts +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/playwright.config.ts @@ -13,8 +13,6 @@ import {defineConfig, devices} from '@playwright/test'; */ require('dotenv').config(); -const baseUrl = 'http://localhost:5025' - export default defineConfig({ testDir: './tests', /* Run tests in files in parallel */ @@ -30,14 +28,13 @@ export default defineConfig({ /* 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: baseUrl, + 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, }, - testMatch: '**/back-button.spec.ts', /* Configure projects for major browsers */ projects: [ { @@ -79,8 +76,8 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: 'cd ../../../src/Dfe.EarlyYearsQualification.Web && dotnet run --project ./Dfe.EarlyYearsQualification.Web.csproj --UseMockContentful=true', - url: baseUrl, + 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, }, }); diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/processLogic.ts b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/processLogic.ts index d6ec55b0..f40b5512 100644 --- a/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/processLogic.ts +++ b/tests/Dfe.EarlyYearsQualification.E2ETests/playwright/tests/shared/processLogic.ts @@ -10,8 +10,15 @@ export async function authorise(context: BrowserContext) { export async function startJourney(page: Page, context: BrowserContext) { await authorise(context); await page.goto("/", {waitUntil: 'domcontentloaded'}); - console.log(await page.title()); - console.log(await page.innerHTML('body')); + await context.addCookies([ + { + name: 'auth-secret', + value: process.env.AUTH_SECRET, + path: '/', + domain: process.env.DOMAIN + } + ]); + await page.goto("/", { waitUntil: 'domcontentloaded'}); await page.waitForFunction(() => document.title === "Start - Check an Early Years qualification") //expect(await page.title()).toBe("Start - Check an Early Years qualification"); await expect(page.locator("#start-now-button")).toBeVisible(); @@ -62,6 +69,19 @@ export function checkHeaderValue(response: APIResponse, headerName: string, head export function checkHeaderExists(response: APIResponse, headerName: string, shouldExist: boolean) { expect(response.headers()[headerName]).toBeUndefined(); +import {BrowserContext, Page, expect, APIResponse} from "@playwright/test"; +export const cookiePreferencesCookieName = "cookies_preferences_set"; +export const journeyCookieName = 'user_journey'; + +export async function authorise(context: BrowserContext) { + await setCookie(context, process.env.AUTH_SECRET, 'auth-secret'); +} +export function checkText(page: any, locator: string, expectedText: string, contain: boolean = false) { + if (contain) { + expect(page.locator(locator)).toContainText(expectedText); + } else { + expect(page.locator(locator)).toHaveText(expectedText); + } } export async function whereWasTheQualificationAwarded(page: any, location: string) {