diff --git a/.gitignore b/.gitignore index 8718c4b83e2..bc5f4e702e8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ cypress/fixtures/toggles ws-nextjs-app/cypress/fixtures/toggles ws-nextjs-app/cypress/downloads ws-nextjs-app/cypress/results +ws-nextjs-app/test-results +ws-nextjs-app/test/e2e/__assets__ pack storybook_dist simorgh.report.html diff --git a/.yarn/cache/@bbc-unified-web-e2e-framework-https-7d91ac8d86-61b1045810.zip b/.yarn/cache/@bbc-unified-web-e2e-framework-https-7d91ac8d86-61b1045810.zip new file mode 100644 index 00000000000..44ceb6ba9ef Binary files /dev/null and b/.yarn/cache/@bbc-unified-web-e2e-framework-https-7d91ac8d86-61b1045810.zip differ diff --git a/.yarn/cache/@playwright-test-npm-1.57.0-d5b9717312-07f5ba4841.zip b/.yarn/cache/@playwright-test-npm-1.57.0-d5b9717312-07f5ba4841.zip new file mode 100644 index 00000000000..544b68215d9 Binary files /dev/null and b/.yarn/cache/@playwright-test-npm-1.57.0-d5b9717312-07f5ba4841.zip differ diff --git a/.yarn/cache/playwright-core-npm-1.57.0-1ccd5476ca-ec066602f0.zip b/.yarn/cache/playwright-core-npm-1.57.0-1ccd5476ca-ec066602f0.zip new file mode 100644 index 00000000000..1937453b469 Binary files /dev/null and b/.yarn/cache/playwright-core-npm-1.57.0-1ccd5476ca-ec066602f0.zip differ diff --git a/.yarn/cache/playwright-npm-1.57.0-1712c32e43-241559210f.zip b/.yarn/cache/playwright-npm-1.57.0-1712c32e43-241559210f.zip new file mode 100644 index 00000000000..c3d8f0ed6a0 Binary files /dev/null and b/.yarn/cache/playwright-npm-1.57.0-1712c32e43-241559210f.zip differ diff --git a/package.json b/package.json index ba3d648fe2e..a5b65719158 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ ], "workspaces": { "packages": [ + "ws-nextjs-app/test/e2e", "ws-nextjs-app", "src/app/routes/article/getInitialData", "src/app/routes/utils/fetchDataFromBFF", diff --git a/ws-nextjs-app/test/e2e/package.json b/ws-nextjs-app/test/e2e/package.json new file mode 100644 index 00000000000..b59597987d4 --- /dev/null +++ b/ws-nextjs-app/test/e2e/package.json @@ -0,0 +1,22 @@ +{ + "name": "e2e-tests", + "version": "1.0.0", + "description": "automation / e2e tests", + "private": true, + "packageManager": "yarn@4.12.0", + "main": "index.js", + "scripts": { + "test:e2e:chrome:playwright": "npx playwright test --project='WorldService - Chrome'", + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@bbc/unified-web-e2e-framework": "github:bbc/unified-web-e2e-framework#v3.0.0", + "@playwright/test": "1.57.0", + "@types/config": "3.3.5", + "@types/supertest": "6.0.3", + "supertest": "7.1.1", + "tsx": "4.19.4", + "typescript": "5.8.3" + } +} diff --git a/ws-nextjs-app/test/e2e/playwright.config.ts b/ws-nextjs-app/test/e2e/playwright.config.ts new file mode 100644 index 00000000000..ab814d0b67f --- /dev/null +++ b/ws-nextjs-app/test/e2e/playwright.config.ts @@ -0,0 +1,7 @@ +import { config } from '@bbc/unified-web-e2e-framework'; + +config.testDir = 'specs'; + +config.use.baseURL = 'https://www.bbc.com'; + +export default config; diff --git a/ws-nextjs-app/test/e2e/specs/homePage.spec.ts b/ws-nextjs-app/test/e2e/specs/homePage.spec.ts new file mode 100644 index 00000000000..79394f0540a --- /dev/null +++ b/ws-nextjs-app/test/e2e/specs/homePage.spec.ts @@ -0,0 +1,87 @@ +import SERVICES from '#app/lib/config/services'; +import { test } from '@bbc/unified-web-e2e-framework'; +import { expect } from '@playwright/test'; + +const SERVICES_PATTERN = SERVICES.join('|'); + +const VALID_HREF_REGEX = new RegExp( + `^https://www\\.bbc\\.com/(?:${SERVICES_PATTERN}|usingthebbc/[^/]+(?:/.*)?|programmes/[a-z0-9]{8,15})(?:/.*)?$`, +); + +const testSuites = [ + { + path: '/arabic', + service: 'arabic', + }, + { + path: '/dari', + service: 'dari', + }, + { + path: '/kyrgyz', + service: 'kyrgyz', + }, + { + path: '/magyarul', + service: 'magyarul', + expectedPath: '/magyarul/articles/cwywderkzy2o', + }, + { + path: '/polska', + service: 'polska', + }, + { + path: '/portuguese', + service: 'portuguese', + }, + { + path: '/romania', + service: 'romania', + expectedPath: '/romania/articles/c993yged1xno', + }, + { + path: '/serbian/lat', + service: 'serbian', + variant: 'lat', + }, + { + path: '/serbian/cyr', + service: 'serbian', + variant: 'cyr', + }, + { + path: '/uzbek/lat', + service: 'uzbek', + variant: 'lat', + }, + { + path: '/uzbek/cyr', + service: 'uzbek', + variant: 'cyr', + }, +]; + +testSuites.forEach(suite => { + test.describe(`Home Page - ${suite.service}${suite.variant ?? ''}`, () => { + test('all links within
element should be a valid World Service URL', async ({ + page, + }) => { + const expectedPath = suite.expectedPath || suite.path; + + await page.goto(suite.path); + await expect(page).toHaveURL(expectedPath); + + const pageLinks = await page + .locator('main a[href^="https://www.bbc.com"]') + .all(); + + // eslint-disable-next-line no-restricted-syntax + for (const link of pageLinks) { + // eslint-disable-next-line no-await-in-loop + const href = await link.getAttribute('href'); + expect(href).not.toBeNull(); + expect(href).toMatch(VALID_HREF_REGEX); + } + }); + }); +}); diff --git a/ws-nextjs-app/test/e2e/specs/setupCheck.spec.ts b/ws-nextjs-app/test/e2e/specs/setupCheck.spec.ts new file mode 100644 index 00000000000..e1fa53d00c9 --- /dev/null +++ b/ws-nextjs-app/test/e2e/specs/setupCheck.spec.ts @@ -0,0 +1,11 @@ +import { test } from '@bbc/unified-web-e2e-framework'; +import { expect } from '@playwright/test'; + +test('Verify page title', async ({ page }) => { + await page.goto('https://www.bbc.com'); + expect(await page.title()).toEqual( + expect.stringMatching( + /(BBC - Home|BBC Home - Breaking News, World News, US News, Sports, Business, Innovation, Climate, Culture, Travel, Video & Audio)/, + ), + ); +});