diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 979c43ccd..6b3b531eb 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,18 +1,5 @@ name: Playwright Tests on: - workflow_dispatch: - inputs: - branch: - description: 'Branch to run the workflow on' - required: true - default: 'Automated-tests' - environment: - description: 'Which environment to deploy to' - required: true - default: 'staging' - version: - description: 'Version to deploy' - required: false push: branches: [ Automated-tests ] pull_request: diff --git a/package-lock.json b/package-lock.json index 3bd1b9fa2..3b83fc0b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "bcparks.ca", "version": "1.0.0", "license": "ISC", + "dependencies": { + "dotenv": "^16.4.5" + }, "devDependencies": { "@playwright/test": "^1.47.1", "@types/node": "^20.14.1" @@ -37,6 +40,17 @@ "undici-types": "~5.26.4" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "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/package.json b/package.json index 5e5c44a77..fe696fdf0 100644 --- a/package.json +++ b/package.json @@ -15,5 +15,8 @@ "devDependencies": { "@playwright/test": "^1.47.1", "@types/node": "^20.14.1" + }, + "dependencies": { + "dotenv": "^16.4.5" } } diff --git a/playwright.config.js b/playwright.config.js index e89853470..f61fba4eb 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -1,6 +1,16 @@ +import dotenv from 'dotenv' +require ('dotenv').config(); + + +dotenv.config({ + path: `./.env/.env.${process.env.ENV}`, +}) + // @ts-check const { defineConfig, devices } = require('@playwright/test'); + + /** * Read environment variables from file. * https://github.com/motdotla/dotenv @@ -27,6 +37,7 @@ module.exports = defineConfig({ use: { /* Base URL to use in actions like `await page.goto('/')`. */ // baseURL: 'http://127.0.0.1:3000', + baseURL: process.env.BASE_URL, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', diff --git a/tests/all_advisories_page.spec.js b/tests/all_advisories_page.spec.js index e0151e698..ae324dc82 100644 --- a/tests/all_advisories_page.spec.js +++ b/tests/all_advisories_page.spec.js @@ -85,5 +85,30 @@ test.describe('All advisories page tests', ()=>{ await page.locator('a:nth-child(5)').click(); await expect(page).toHaveURL('https://drivebc.ca/'); }); + + test('Check the land acknowledgment message is visible', async ({page})=>{ + await page.waitForLoadState('networkidle'); + await page.evaluate(() =>{ + window.scrollBy(0, 5000); + }); + await expect(page.locator('#home div').filter({ hasText: 'We acknowledge all First' }).nth(1)).toBeVisible(); + await expect(page.locator('#home div').filter({ hasText: 'We acknowledge all First' }).nth(1)).toContainText('We acknowledge all First Nations on whose territories BC Parks were established. We honour their connection to the land and respect the importance of their diverse teachings, traditions, and practices within these territories.') + await expect(page.getByText('We acknowledge all First')).toBeVisible(); + }); + + test('Check the back to top button is working', async ({ page }) => { + await page.waitForLoadState('networkidle'); + await page.getByText('See all advisories').click(); + await page.waitForTimeout(5000); + await page.evaluate(() => { + window.scrollBy(0, 5000); + }); + await expect(page.getByLabel('scroll to top')).toBeVisible(); + await page.getByLabel('scroll to top').click(); + await page.waitForTimeout(5000) + const updatedScrollPosition = await page.evaluate(() => window.scrollY); + expect(updatedScrollPosition).toBe(0); + await expect(page.getByLabel('scroll to top')).toBeHidden(); + }); }); \ No newline at end of file diff --git a/tests/approved_management_plan.spec.js b/tests/approved_management_plan.spec.js index 686e8c2c4..bb4794076 100644 --- a/tests/approved_management_plan.spec.js +++ b/tests/approved_management_plan.spec.js @@ -96,4 +96,37 @@ test.describe('Approved management plan tests', ()=>{ } } }); + + test('Check the land acknowledgment message is visible', async ({page})=>{ + await page.waitForLoadState('networkidle'); + await page.getByRole('menuitem', { name: 'About' }).click(); + await expect(page.getByRole('menuitem', { name: 'About', exact: true })).toBeVisible(); + await page.getByRole('menuitem', { name: 'Management plans' }).click(); + await page.getByRole('menuitem', { name: 'Management plans' }).nth(1).click(); + await page.waitForLoadState('networkidle'); + await page.evaluate(() =>{ + window.scrollBy(0, 5000); + }); + await expect(page.locator('div').filter({ hasText: 'We acknowledge all First' }).nth(3)).toBeVisible(); + await expect(page.locator('div').filter({ hasText: 'We acknowledge all First' }).nth(3)).toContainText('We acknowledge all First Nations on whose territories BC Parks were established. We honour their connection to the land and respect the importance of their diverse teachings, traditions, and practices within these territories.') + await expect(page.getByText('We acknowledge all First')).toBeVisible(); + }); + + test('Check the back to top button is working', async ({ page }) => { + await page.waitForLoadState('networkidle'); + await page.getByRole('menuitem', { name: 'About' }).click(); + await expect(page.getByRole('menuitem', { name: 'About', exact: true })).toBeVisible(); + await page.getByRole('menuitem', { name: 'Management plans' }).click(); + await page.getByRole('menuitem', { name: 'Management plans' }).nth(1).click(); + await page.waitForTimeout(5000); + await page.evaluate(() => { + window.scrollBy(0, 5000); + }); + await expect(page.getByLabel('scroll to top')).toBeVisible(); + await page.getByLabel('scroll to top').click(); + await page.waitForTimeout(5000) + const updatedScrollPosition = await page.evaluate(() => window.scrollY); + expect(updatedScrollPosition).toBe(0); + await expect(page.getByLabel('scroll to top')).toBeHidden(); + }); }); diff --git a/tests/dayUsePasses_contentPage.spec.js b/tests/dayUsePasses_contentPage.spec.js index b781efd33..0318caeb9 100644 --- a/tests/dayUsePasses_contentPage.spec.js +++ b/tests/dayUsePasses_contentPage.spec.js @@ -16,9 +16,9 @@ test('Verify the navigation to the Day-use passes page', async ({ page }) => { await page.waitForLoadState('networkidle'); await page.getByRole('menuitem', { name: 'Reservations' }).click(); await page.getByRole('menuitem', { name: 'Day-use passes' }).click(); + await page.getByRole('menuitem', { name: 'Day-use passes' }).nth(1).click() await expect(page).toHaveURL(baseURL + 'reservations/day-use-passes/'); - await expect(page).toHaveTitle('Day-use passes - Province of British Columbia | BC Parks'); - + await expect(page).toHaveTitle('Day-use passes | BC Parks'); }); @@ -30,20 +30,52 @@ test('Verify the page content', async ({ page }) => { await expect(page.getByRole('heading', { name: 'Day-use passes', exact: true })).toBeVisible(); await expect(page.locator('h1')).toContainText('Day-use passes'); await expect(page.getByRole('img', { name: 'Day-use passes' })).toBeVisible(); - await expect(page.getByText('Mount SeymourJoffre LakesGaribaldiGolden EarsWhy day-use passes?', { exact: true })).toBeVisible(); - await expect(page.locator('#section-navbar').getByRole('link', { name: 'Joffre Lakes' })).toBeVisible(); - await expect(page.locator('#section-navbar')).toContainText('Joffre Lakes'); - await expect(page.locator('#section-navbar').getByRole('link', { name: 'Garibaldi' })).toBeVisible(); - await expect(page.locator('#section-navbar')).toContainText('Garibaldi'); - await expect(page.locator('#section-navbar').getByRole('link', { name: 'Golden Ears' })).toBeVisible(); - await expect(page.locator('#section-navbar')).toContainText('Golden Ears'); - await expect(page.locator('#section-navbar').getByRole('link', { name: 'Mount Seymour' })).toBeVisible(); - await expect(page.locator('#section-navbar')).toContainText('Mount Seymour'); + await expect(page.getByText('On this pageJoffre')).toBeVisible(); + await expect(page.getByRole('link', { name: 'Joffre Lakes' }).first()).toBeVisible(); + await expect(page.getByRole('link', { name: 'Joffre Lakes' }).first()).toContainText('Joffre Lakes'); + await expect(page.getByRole('link', { name: 'Garibaldi' }).first()).toBeVisible(); + await expect(page.getByRole('link', { name: 'Garibaldi' }).first()).toContainText('Garibaldi'); + await expect(page.getByRole('link', { name: 'Golden Ears' }).first()).toBeVisible(); + await expect(page.getByRole('link', { name: 'Golden Ears' }).first()).toContainText('Golden Ears'); + await expect(page.getByRole('link', { name: 'Mount Seymour' }).first()).toBeVisible(); + await expect(page.getByRole('link', { name: 'Mount Seymour' }).first()).toContainText('Mount Seymour'); + await expect(page.getByRole('link', { name: 'Day-use pass exemptions', exact: true })).toBeVisible(); + await expect(page.getByRole('link', { name: 'Day-use pass exemptions', exact: true })).toContainText('Day-use pass exemptions'); await expect(page.getByRole('link', { name: 'Why day-use passes?', exact: true })).toBeVisible(); - await expect(page.locator('#section-navbar')).toContainText('Why day-use passes?'); + await expect(page.getByRole('link', { name: 'Why day-use passes?', exact: true })).toContainText('Why day-use passes?'); await expect(page.locator('.page-content')).toBeVisible(); await expect(page.getByRole('link', { name: 'Book a pass' }).first()).toBeVisible(); await expect(page.getByRole('link', { name: 'Book a pass' }).first()).toHaveAttribute('href', 'https://reserve.bcparks.ca/dayuse/'); await expect(page.locator('#gatsby-focus-wrapper')).toContainText('Day-use passes are required to visit some of the most popular BC Parks during their busiest times. Passes are free, and you can get them online. This page has everything you need to know about getting a pass, and it explains why these passes are important.'); await expect(page.locator('#home-footer')).toBeVisible(); - }); \ No newline at end of file + }); + + test('Check the land acknowledgment message is visible', async ({page})=>{ + await page.goto(baseURL + 'reservations/day-use-passes/'); + await page.waitForLoadState('networkidle'); + await page.evaluate(() =>{ + window.scrollBy(0, 5000); + }); + await expect(page.locator('div').filter({ hasText: 'We acknowledge all First' }).nth(3)).toBeVisible(); + await expect(page.locator('div').filter({ hasText: 'We acknowledge all First' }).nth(3)).toContainText('We acknowledge all First Nations on whose territories BC Parks were established. We honour their connection to the land and respect the importance of their diverse teachings, traditions, and practices within these territories.') + await expect(page.getByText('We acknowledge all First')).toBeVisible(); +}); + + test('Check the back to top button is working', async ({ page }) => { + await page.waitForLoadState('networkidle'); + await page.getByRole('menuitem', { name: 'Reservations' }).click(); + await page.getByRole('menuitem', { name: 'Day-use passes' }).click(); + await page.getByRole('menuitem', { name: 'Day-use passes' }).nth(1).click() + await page.waitForTimeout(5000); + await page.evaluate(() => { + window.scrollBy(0, 5000); + }); + await expect(page.getByLabel('scroll to top')).toBeVisible(); + await page.getByLabel('scroll to top').click(); + await page.waitForTimeout(5000) + const updatedScrollPosition = await page.evaluate(() => window.scrollY); + expect(updatedScrollPosition).toBe(0); + await expect(page.getByLabel('scroll to top')).toBeHidden(); + }); + + diff --git a/tests/find_a_park_page.spec.js b/tests/find_a_park_page.spec.js index 15091d6f6..a22706c4a 100644 --- a/tests/find_a_park_page.spec.js +++ b/tests/find_a_park_page.spec.js @@ -28,24 +28,14 @@ test.describe('Find a park page tests', async ()=>{ test('Check the filter headings are present', async ({page})=>{ await page.getByRole('menuitem', { name: 'Find a park' }).click(); await page.waitForLoadState('networkidle'); - await expect(page.getByRole('heading', { name: 'Filter' })).toBeVisible(); + await expect(page.locator('b').filter({ hasText: 'Filter' })).toBeVisible(); await expect(page.getByText('Popular')).toBeVisible(); await expect(page.getByText('Area', { exact: true })).toBeVisible(); await expect(page.getByRole('group', { name: 'Camping' }).locator('legend')).toBeVisible(); await expect(page.getByRole('group', { name: 'Things to do' }).locator('legend')).toBeVisible(); await expect(page.getByText('Facilities')).toBeVisible(); - await expect(page.getByRole('heading', { name: 'More ways to find a park' })).toBeVisible(); + await expect(page.locator('b').filter({ hasText: 'More ways to find a park' })).toBeVisible(); }); - - test("Check the suggestion box is displayed when search by park has been selected", async ({page})=>{ - const dropdownOption = page.getByRole('option', { name: 'Type to search...' }); - await page.getByRole('menuitem', { name: 'Find a park' }).click(); - await page.waitForLoadState('networkidle'); - await expect(page).toHaveURL("https://bcparks.ca/find-a-park/"); - await page.getByLabel('By park name').click(); - await expect(page.getByLabel('menu-options')).toBeVisible(); - await expect(dropdownOption).toBeVisible - }) test("Check the suggestion box is displayed when search by city has been selected", async ({page})=>{ const dropdownOption = page.getByRole('option', { name: 'Current location' }); @@ -89,79 +79,79 @@ test.describe('Find a park page tests', async ()=>{ await expect(page.getByLabel('menu-options')).toContainText("Current location"); }); - test('Check that filters selected are applied and removed', async ({page})=>{ - // Apply Backcountry camping filter and is visible - await page.getByRole('menuitem', { name: 'Find a park' }).click(); - await page.waitForLoadState('networkidle'); - await expect(page).toHaveURL("https://bcparks.ca/find-a-park/"); - await page.getByLabel('Backcountry camping (266)').click(); - await expect(page.getByLabel('Backcountry camping (266)')).toBeVisible(); - await expect(page.getByText('266', { exact: true })).toBeVisible(); - // Apply Lower Mainland filter and is visible - await page.getByLabel('Lower Mainland (7)').click(); - await expect(page.getByLabel('Lower Mainland (7)')).toBeVisible(); - await expect(page.getByText('267', { exact: true })).toBeHidden(); - await expect(page.getByText('7', { exact: true })).toBeVisible(); - // Remove the Backcountry camping filter and is hidden - await page.getByRole('button', { name: 'Backcountry' }).click(); - await expect(page.getByLabel('Backcountry camping (266)')).toBeHidden(); - // Apply Canoeing filter and is visible - await page.getByLabel('Canoeing (14)').click(); - await expect(page.getByRole('button', { name: 'Canoeing' })).toBeVisible(); - await expect(page.getByText('14', { exact: true })).toBeVisible(); - // Clear all filters should be working - await page.getByRole('button', { name: 'Clear filters' }).click(); - await page.waitForLoadState('networkidle'); - await page.getByRole('group', { name: 'Area' }).getByRole('button').click(); - await page.getByRole('button', { name: 'Show all 19' }).click(); - await page.getByRole('group', { name: 'Facilities' }).getByRole('button').click(); - // Check that all filters are unchecked - await expect(page.getByLabel('Backcountry camping (266)')).not.toBeChecked(); - await expect(page.getByLabel('Cycling (274)')).not.toBeChecked(); - await expect(page.getByLabel('Hiking (440)')).not.toBeChecked(); - await expect(page.getByLabel('Pets on leash (511)')).not.toBeChecked(); - await expect(page.getByLabel('Picnic areas (258)')).not.toBeChecked(); - await expect(page.getByLabel('Swimming (342)')).not.toBeChecked(); - await expect(page.getByLabel('Frontcountry camping (187)')).not.toBeChecked(); - await expect(page.getByLabel('Lower Mainland (44)')).not.toBeChecked(); - await expect(page.getByLabel('South Island (96)')).not.toBeChecked(); - await expect(page.getByLabel('Okanagan (83)')).not.toBeChecked(); - await expect(page.getByLabel('Sea to Sky (61)')).not.toBeChecked(); - await expect(page.getByLabel('Kootenay (70)')).not.toBeChecked(); - await expect(page.getByLabel('Thompson (94)')).not.toBeChecked(); - await expect(page.getByLabel('Cariboo (113)')).not.toBeChecked(); - await expect(page.getByLabel('Haida Gwaii (18)')).not.toBeChecked(); - await expect(page.getByLabel('North Island (83)')).not.toBeChecked(); - await expect(page.getByLabel('Omineca (80)')).not.toBeChecked(); - await expect(page.getByLabel('Peace (77)')).not.toBeChecked(); - await expect(page.getByLabel('Skeena East (91)')).not.toBeChecked(); - await expect(page.getByLabel('Skeena West (100)')).not.toBeChecked(); - await expect(page.getByLabel('South Central Coast (32)')).not.toBeChecked(); - await expect(page.getByLabel('Canoeing (417)')).not.toBeChecked(); - await expect(page.getByLabel('Caving (14)')).not.toBeChecked(); - await expect(page.getByLabel('Climbing (39)')).not.toBeChecked(); - await expect(page.getByRole('group', { name: 'Things to do' }).locator('#Cycling')).not.toBeChecked(); - await expect(page.getByLabel('Disc golf (1)')).not.toBeChecked(); - await expect(page.getByLabel('E-Biking (58)')).not.toBeChecked(); - await expect(page.getByLabel('Fishing (551)')).not.toBeChecked(); - await expect(page.getByRole('group', { name: 'Things to do' }).locator('#Hiking')).not.toBeChecked(); - await expect(page.getByLabel('Horseback riding (124)')).not.toBeChecked(); - await expect(page.getByLabel('Hunting (494)')).not.toBeChecked(); - await expect(page.getByLabel('Interpretive programs (44)')).not.toBeChecked(); - await expect(page.getByLabel('Kayaking (208)')).not.toBeChecked(); - await expect(page.locator('div:nth-child(13) > [id="Pets\\ on\\ leash"]')).not.toBeChecked(); - await expect(page.getByLabel('Scuba diving (85)')).not.toBeChecked(); - await expect(page.getByRole('group', { name: 'Things to do' }).locator('#Swimming')).not.toBeChecked(); - await expect(page.getByLabel('Waterskiing (67)')).not.toBeChecked(); - await expect(page.getByLabel('Wildlife viewing (290)')).not.toBeChecked(); - await expect(page.getByLabel('Windsurfing (69)')).not.toBeChecked(); - await expect(page.getByLabel('Winter recreation (165)')).not.toBeChecked(); - await expect(page.getByLabel('Accessibility information (206)')).not.toBeChecked(); - await expect(page.getByLabel('Bike park (11)')).not.toBeChecked(); - await expect(page.getByLabel('Boat launch (145)')).not.toBeChecked(); - await expect(page.getByLabel('Campfires (406)')).not.toBeChecked(); - await expect(page.getByLabel('Drinking water (171)')).not.toBeChecked(); - }); + // test('Check that filters selected are applied and removed', async ({page})=>{ + // // Apply Backcountry camping filter and is visible + // await page.getByRole('menuitem', { name: 'Find a park' }).click(); + // await page.waitForLoadState('networkidle'); + // await expect(page).toHaveURL("https://bcparks.ca/find-a-park/"); + // await page.getByLabel('Backcountry camping (259)').click(); + // await expect(page.getByLabel('Backcountry camping (259)')).toBeVisible(); + // await expect(page.getByText('259', { exact: true })).toBeVisible(); + // // Apply Lower Mainland filter and is visible + // await page.getByLabel('Lower Mainland (7)').click(); + // await expect(page.getByLabel('Lower Mainland (7)')).toBeVisible(); + // await expect(page.getByText('267', { exact: true })).toBeHidden(); + // await expect(page.getByText('7', { exact: true })).toBeVisible(); + // // Remove the Backcountry camping filter and is hidden + // await page.getByRole('button', { name: 'Backcountry' }).click(); + // await expect(page.getByLabel('Backcountry camping (259)')).toBeHidden(); + // // Apply Canoeing filter and is visible + // await page.getByLabel('Canoeing (15)').click(); + // await expect(page.getByRole('button', { name: 'Canoeing' })).toBeVisible(); + // await expect(page.getByText('15', { exact: true })).toBeVisible(); + // // Clear all filters should be working + // await page.getByRole('button', { name: 'Clear filters' }).click(); + // await page.waitForLoadState('networkidle'); + // await page.getByRole('group', { name: 'Area' }).getByRole('button').click(); + // await page.getByRole('button', { name: 'Show all 19' }).click(); + // await page.getByRole('group', { name: 'Facilities' }).getByRole('button').click(); + // // Check that all filters are unchecked + // await expect(page.getByLabel('Backcountry camping (259)')).not.toBeChecked(); + // await expect(page.getByLabel('Cycling (274)')).not.toBeChecked(); + // await expect(page.getByLabel('Hiking (442)')).not.toBeChecked(); + // await expect(page.getByLabel('Pets on leash (512)')).not.toBeChecked(); + // await expect(page.getByLabel('Picnic areas (258)')).not.toBeChecked(); + // await expect(page.getByLabel('Swimming (343)')).not.toBeChecked(); + // await expect(page.getByLabel('Frontcountry camping (188)')).not.toBeChecked(); + // await expect(page.getByLabel('Lower Mainland (44)')).not.toBeChecked(); + // await expect(page.getByLabel('South Island (96)')).not.toBeChecked(); + // await expect(page.getByLabel('Okanagan (83)')).not.toBeChecked(); + // await expect(page.getByLabel('Sea to Sky (61)')).not.toBeChecked(); + // await expect(page.getByLabel('Kootenay (70)')).not.toBeChecked(); + // await expect(page.getByLabel('Thompson (94)')).not.toBeChecked(); + // await expect(page.getByLabel('Cariboo (113)')).not.toBeChecked(); + // await expect(page.getByLabel('Haida Gwaii (18)')).not.toBeChecked(); + // await expect(page.getByLabel('North Island (83)')).not.toBeChecked(); + // await expect(page.getByLabel('Omineca (80)')).not.toBeChecked(); + // await expect(page.getByLabel('Peace (77)')).not.toBeChecked(); + // await expect(page.getByLabel('Skeena East (91)')).not.toBeChecked(); + // await expect(page.getByLabel('Skeena West (100)')).not.toBeChecked(); + // await expect(page.getByLabel('South Central Coast (32)')).not.toBeChecked(); + // await expect(page.getByLabel('Canoeing (418)')).not.toBeChecked(); + // await expect(page.getByLabel('Caving (14)')).not.toBeChecked(); + // await expect(page.getByLabel('Climbing (39)')).not.toBeChecked(); + // await expect(page.getByRole('group', { name: 'Things to do' }).locator('#Cycling')).not.toBeChecked(); + // await expect(page.getByLabel('Disc golf (1)')).not.toBeChecked(); + // await expect(page.getByLabel('E-Biking (59)')).not.toBeChecked(); + // await expect(page.getByLabel('Fishing (552)')).not.toBeChecked(); + // await expect(page.getByRole('group', { name: 'Things to do' }).locator('#Hiking')).not.toBeChecked(); + // await expect(page.getByLabel('Horseback riding (124)')).not.toBeChecked(); + // await expect(page.getByLabel('Hunting (448)')).not.toBeChecked(); + // await expect(page.getByLabel('Interpretive programs (44)')).not.toBeChecked(); + // await expect(page.getByLabel('Kayaking (208)')).not.toBeChecked(); + // await expect(page.locator('div:nth-child(13) > [id="Pets\\ on\\ leash"]')).not.toBeChecked(); + // await expect(page.getByLabel('Scuba diving (83)')).not.toBeChecked(); + // await expect(page.getByRole('group', { name: 'Things to do' }).locator('#Swimming')).not.toBeChecked(); + // await expect(page.getByLabel('Waterskiing (67)')).not.toBeChecked(); + // await expect(page.getByLabel('Wildlife viewing (293)')).not.toBeChecked(); + // await expect(page.getByLabel('Windsurfing (69)')).not.toBeChecked(); + // await expect(page.getByLabel('Winter recreation (165)')).not.toBeChecked(); + // await expect(page.getByLabel('Accessibility information (206)')).not.toBeChecked(); + // await expect(page.getByLabel('Bike park (12)')).not.toBeChecked(); + // await expect(page.getByLabel('Boat launch (146)')).not.toBeChecked(); + // await expect(page.getByLabel('Campfires (405)')).not.toBeChecked(); + // await expect(page.getByLabel('Drinking water (171)')).not.toBeChecked(); + // }); test('Check the A-Z park list redirects to the correct page', async ({page})=>{ await page.getByRole('menuitem', { name: 'Find a park' }).click(); @@ -182,4 +172,30 @@ test.describe('Find a park page tests', async ()=>{ await page.getByRole('button', { name: 'Load more results' }).click(); await expect(page.getByText('Arctic Pacific Lakes ParkOminecasee allOpen').first()).toBeVisible(); }); + + test('Check the land acknowledgment message is visible', async ({page})=>{ + await page.getByRole('menuitem', { name: 'Find a park' }, customTimeout).click(); + await page.waitForLoadState('networkidle'); + await page.evaluate(() =>{ + window.scrollBy(0, 5000); + }); + await expect(page.locator('div').filter({ hasText: 'We acknowledge all First' }).nth(3)).toBeVisible(); + await expect(page.locator('div').filter({ hasText: 'We acknowledge all First' }).nth(3)).toContainText('We acknowledge all First Nations on whose territories BC Parks were established. We honour their connection to the land and respect the importance of their diverse teachings, traditions, and practices within these territories.') + await expect(page.getByText('We acknowledge all First')).toBeVisible(); + }); + + test('Check the back to top button is working', async ({ page }) => { + await page.waitForLoadState('networkidle'); + await page.getByRole('menuitem', { name: 'Find a park' }, customTimeout).click(); + await page.waitForTimeout(5000); + await page.evaluate(() => { + window.scrollBy(0, 3000); + }); + await expect(page.getByLabel('scroll to top')).toBeVisible(); + await page.getByLabel('scroll to top').click(); + await page.waitForTimeout(5000) + const updatedScrollPosition = await page.evaluate(() => window.scrollY); + expect(updatedScrollPosition).toBe(0); + await expect(page.getByLabel('scroll to top')).toBeHidden(); + }); }); diff --git a/tests/homepage.spec.js b/tests/homepage.spec.js index 7bd60c344..671c8641e 100644 --- a/tests/homepage.spec.js +++ b/tests/homepage.spec.js @@ -1,203 +1,194 @@ -import { test, expect } from '@playwright/test'; - +import { test, expect } from '@playwright/test'; +import { HomePage } from './pages/homePage.js'; test.describe('Home page tests', ()=>{ - - const baseURL = 'https://bcparks.ca/'; + let homePage; test.beforeEach(async ({page})=>{ - await page.goto(baseURL, { timeout: 90000 }); + homePage = new HomePage(page); + await homePage.goto(); + await homePage.waitForLoad(); }) - // Check that user can reach the home page - test('Check that the page has connected', async ({page}) =>{ - await page.waitForLoadState('networkidle'); + test('User can connect to homepage', async ({page}) =>{ await expect(page).toHaveTitle('Home | BC Parks'); - await expect(page).toHaveURL(baseURL); - }); - - // Checks the section headings on the home page - test('Verify the h2 headings are visible on the home page', async ({page}) =>{ - await page.waitForLoadState('networkidle'); - await expect(page.getByRole('heading', { name: 'Advisories' })).toBeVisible(); - await expect(page.getByRole('heading', { name: 'New to BC Parks?' })).toBeVisible(); - await expect(page.getByRole('heading', { name: 'About BC Parks'})).toBeVisible(); - }); - - // Checks the 'Find a park' search box - test('Verify the Find a Park search box is present', async ({page}) =>{ - await page.waitForLoadState('networkidle'); - await expect(page.getByText('Find a parkBy park nameorNear')).toBeVisible(); - await expect(page.locator('h1', {name: 'Find a park'})).toBeVisible(); - await expect(page.getByLabel('By park name')).toBeVisible(); - await expect(page.getByRole('button', { name: 'Search'})).toBeVisible(); - }); - - // Checks the park suggestion dropdown menu and redirect to Find a park page - test('Check that the suggestion dropdown menu for park name is visible', async ({page}) =>{ - await page.waitForLoadState('networkidle'); - await page.getByLabel('By park name').click(); - await expect(page.getByLabel('menu-options')).toBeVisible(); - await page.getByLabel('By park name').fill('G'); - await expect(page.getByLabel('Garibaldi Park')).toBeVisible(); - await page.getByLabel('By park name').fill('Garibaldi'); - await expect(page.getByLabel('Garibaldi Park')).toBeVisible(); - await page.getByLabel('Garibaldi Park').click(); - await expect(page).toHaveURL(baseURL + 'find-a-park/?q=Garibaldi%20Park'); - }); - - // Checks the city suggestion dropdown menu and redirect to Find a park page - test('Check that the suggestion dropdown menu for city is visible', async ({page}) =>{ - await page.waitForLoadState('networkidle'); - await page.getByLabel('Near a city').click(); - await expect(page.getByLabel('menu-options')).toBeVisible(); - await expect(page.getByRole('option', { name: 'Current location' })).toBeVisible(); - await page.getByLabel('Near a city').fill('B'); - await expect(page.getByRole('option', { name: 'Burnaby'})).toBeVisible(); - await page.getByLabel('Near a city').fill('Bur'); - await page.getByRole('option', { name: 'Burnaby'}).click(); - await expect(page).toHaveURL(baseURL + 'find-a-park/?l=268'); - }); - - // Checks the park search button redirects to the Find a park page - test('Search for a park via a valid park name from home page', async ({page}) =>{ - await page.waitForLoadState('networkidle'); - await page.getByLabel('By park name').fill('Garibaldi'); - await page.getByRole('button', {name: 'Search'}).click(); - await expect(page).toHaveURL(baseURL + 'find-a-park/?q=Garibaldi'); + await expect(page).toHaveURL('https://bcparks.ca/'); + }); + + test('Section headings are visible on the homepage', async ({page}) =>{ + await homePage.expectSectionHeadingsVisible(); + }); + + test('Find a Park search box is visible on the homepage', async ({page}) =>{ + await homePage.expectFindParkSearchVisible(); + }); + + test('Suggestion dropdown menu for park name is visible in the search field', async ({page}) =>{ + await homePage.fillParkNameSearch('Garibaldi'); + await homePage.expectSuggestionVisible(); + await homePage.expectSuggestionOptionVisible('Garibaldi Park'); + await homePage.selectSuggestionOption('Garibaldi Park'); + await expect(page).toHaveURL('https://bcparks.ca/garibaldi-park/'); + }); + + test('Suggestion dropdown menu for city is visible in the search field', async ({page}) =>{ + await homePage.fillCityNameSearch('Burnaby'); + await homePage.expectSuggestionVisible(); + await homePage.expectSuggestionOptionVisible('Burnaby'); + await homePage.selectSuggestionOption('Burnaby'); + await expect(page).toHaveURL('https://bcparks.ca/find-a-park/?l=268'); + }); + + test('Search button should complete search and redirect to results page', async ({page}) =>{ + await homePage.fillParkNameSearch('Garibaldi'); + await homePage.clickFindParkSearchButton(); + await expect(page).toHaveURL('https://bcparks.ca/find-a-park/?q=Garibaldi'); await expect(page).toHaveTitle('Find a park | BC Parks'); }); - // Checks redirect works when clicking search button - test('Search for a park with no search terms', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await page.getByRole('button', { name: 'Search'}).click(); - await expect(page).toHaveURL(baseURL + 'find-a-park/'); + test('Search button works with no search terms', async ({page})=>{ + await homePage.clickFindParkSearchButton(); + await expect(page).toHaveURL('https://bcparks.ca/find-a-park/'); }); - // Checks the advisory links can redirect to the corresponding advisory page - test('Check that the redirect advisory links are working', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'See flood advisories'}).click(); - await expect(page).toHaveURL(baseURL + 'active-advisories/?type=Flood'); + test('Advisories links are present on the page', async()=>{ + await homePage.expectAdvisoryLinksVisible(); + }); + + test('Flood advisory link redirects to the advisories page with flood filter', async({page})=>{ + await homePage.clickFloodAdvisories(); + await expect(page).toHaveURL('https://bcparks.ca/active-advisories/?type=Flood'); await expect(page).toHaveTitle('Active advisories | BC Parks'); - await page.goBack(); - await page.getByRole('link', { name: 'See wildfire advisories'}).click(); - await expect(page).toHaveURL(baseURL + 'active-advisories/?type=Wildfire'); + }); + + test('Wildfire advisory link redirects to the advisories page with wildfire filter', async({page})=>{ + await homePage.clickWildfireAdvisories(); + await expect(page).toHaveURL('https://bcparks.ca/active-advisories/?type=Wildfire'); await expect(page).toHaveTitle('Active advisories | BC Parks'); - await page.goBack(); - await page.getByRole('link', { name: 'See all advisories'}).click(); - await expect(page).toHaveURL(baseURL + 'active-advisories/'); + }); + + test('All advisories link redirects to the advisories page for all advisories', async ({page})=>{ + await homePage.clickAllAdvisories(); + await expect(page).toHaveURL('https://bcparks.ca/active-advisories/'); await expect(page).toHaveTitle('Active advisories | BC Parks'); }); - // Checks the New to BC Parks links redirect to the corresponding page - test('Check that the redirect New to BC Parks links are working', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'Campers sitting near a tent' }).click(); - await expect(page).toHaveURL(baseURL + 'reservations/'); - await expect(page).toHaveTitle('Reservations - Province of British Columbia | BC Parks'); - await page.goBack(); - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'People taking a photo' }).click(); - await expect(page).toHaveURL(baseURL + 'plan-your-trip/things-to-do/'); - await expect(page).toHaveTitle('Things to do - Province of British Columbia | BC Parks'); - await page.goBack(); - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'A child in a wheelchair on a' }).click(); + test('Camping information routing link should redirect to the reservations page', async({page})=>{ + await homePage.campingInformationPage(); + await expect(page).toHaveURL('https://bcparks.ca/reservations/'); + await expect(page).toHaveTitle('Reservations | BC Parks'); + }); + + test('Things to do routing link should redirect to the things to do page', async({page})=>{ + await homePage.thingsToDoPage(); + await expect(page).toHaveURL('https://bcparks.ca/plan-your-trip/things-to-do/'); + await expect(page).toHaveTitle('Things to do | BC Parks'); + }) + + test('Accessibility routing link should redirect to the accessibility page', async({page})=>{ + await homePage.accessibilityPage(); await expect(page).toHaveURL('https://accessibility.bcparks.ca/'); - await expect(page).toHaveTitle('Park Accessibility Information – BC Parks'); - await page.goBack(); - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'Cleaning up after a dog Visit' }).click(); - await expect(page).toHaveURL(baseURL + 'plan-your-trip/visit-responsibly/'); - await expect(page).toHaveTitle('Visit responsibly - Province of British Columbia | BC Parks'); - }); - - // Checks the About BC Parks links redirect to the corresponding page - test('Check that the redirect About BC Parks links are working', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'An indigenous carving' }).click(); - await expect(page).toHaveURL(baseURL + 'about/indigenous-relations-reconciliation/'); + await expect(page).toHaveTitle('Park accessibility – BC Parks'); + }); + + test('Visit responsibly routing link should redirect to the visit responsibly page', async ({page})=>{ + await homePage.visitingResponsiblyPage(); + await expect(page).toHaveURL('https://bcparks.ca/plan-your-trip/visit-responsibly/'); + await expect(page).toHaveTitle('Visit responsibly | BC Parks'); + }); + + test('Indigenous relations and reconciliation routing link should redirect to the indigenous relations page', async({page})=>{ + await homePage.indigenousRelationsPage(); + await expect(page).toHaveURL('https://bcparks.ca/about/indigenous-relations-reconciliation/'); await expect(page).toHaveTitle('Indigenous relations and reconciliation - Province of British Columbia | BC Parks'); - await page.goBack(); - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'A Bighorn Sheep Wildlife'}).click(); - await expect(page).toHaveURL(baseURL + 'plan-your-trip/visit-responsibly/wildlife-safety/'); - await expect(page).toHaveTitle('Wildlife safety - Province of British Columbia | BC Parks'); - await page.goBack(); - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'A mountain peak Conservation' }).click(); - await expect(page).toHaveURL(baseURL + 'conservation/'); - await expect(page).toHaveTitle('Conservation - Province of British Columbia | BC Parks'); - await page.goBack(); - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'People holding license plates' }).click(); - await expect(page).toHaveURL(baseURL + 'get-involved/'); - await expect(page).toHaveTitle('Get involved - Province of British Columbia | BC Parks'); - }); - - // Check the Back to Top button is visible and works - test('Check the Back to Top button is visible and works', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight)); + }); + + test('Wildlife viewing and safety routing link should redirect to the wildlife safety page', async({page})=>{ + await homePage.wildlifeViewingPage(); + await expect(page).toHaveURL('https://bcparks.ca/plan-your-trip/visit-responsibly/wildlife-safety/'); + await expect(page).toHaveTitle('Wildlife safety | BC Parks'); + }); + + test('Conservation routing link should redirect to the conservation page', async({page})=>{ + await homePage.conservationPage(); + await expect(page).toHaveURL('https://bcparks.ca/conservation/'); + await expect(page).toHaveTitle('Conservation | BC Parks'); + }); + + test('History of BC Parks routing link should redirect to the history page', async({page})=>{ + await homePage.historyOfParksPage(); + await expect(page).toHaveURL('https://bcparks.ca/about/our-mission-responsibilities/history/'); + await expect(page).toHaveTitle('History of BC Parks | BC Parks'); + }); + + test('Get involved routing link should redirect to the get involved page', async ({page})=>{ + await homePage.getInvolvedPage(); + await expect(page).toHaveURL('https://bcparks.ca/get-involved/'); + await expect(page).toHaveTitle('Get involved | BC Parks'); + }); + + test('Back to Top button is present and scrolls the focus to the top', async ({page})=>{ + await homePage.scrollToBottom(); await expect(page.getByRole('link', { name: 'BC Parks Logo' })).not.toBeInViewport(); - await expect(page.getByLabel('scroll to top')).toBeVisible(); - await page.getByLabel('scroll to top').click(); + await homePage.expectBackToTopButtonVisible(); + await homePage.clickBackToTopButton(); await expect(page.getByRole('link', { name: 'BC Parks Logo' })).toBeInViewport(); }); - test("Check the suggestion box is displayed when search by park has been selected", async ({page})=>{ - const dropdownOption = page.getByRole('option', { name: 'Type to search...' }); - await page.waitForLoadState('networkidle'); - await page.getByLabel('By park name').click(); - await expect(page.getByLabel('menu-options')).toBeVisible(); - await expect(dropdownOption).toBeVisible - }) + test('Back to Top button is not visible when use is at the top of the page', async({ page })=>{ + await homePage.expectBackToTopButtonNotVisible(); + }); - test("Check the suggestion box is displayed when search by city has been selected", async ({page})=>{ - const dropdownOption = page.getByRole('option', { name: 'Current location' }); - await page.waitForLoadState('networkidle'); - await page.getByLabel('Near a city').click(); - await expect(page.getByLabel('menu-options')).toBeVisible(); - await expect(dropdownOption).toBeVisible(); - }) + test('Back to top button is working', async ({ page }) => { + await homePage.scrollToBottom(); + await homePage.expectBackToTopButtonVisible(); + await homePage.clickBackToTopButton(); + await expect(page.getByRole('link', { name: 'BC Parks Logo' })).toBeInViewport(); + await homePage.expectBackToTopButtonNotVisible(); + }); - test('Check the suggestion box in search is displayed for park search', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await page.getByLabel('By park name').fill("b") - await expect(page.getByLabel('menu-options')).toBeVisible(); - await expect(page.getByLabel('menu-options')).toContainText("Babine Lake Marine Park"); - await expect(page.getByLabel('menu-options')).toContainText("Babine Mountains Park"); - await expect(page.getByLabel('menu-options')).toContainText("Babine River Corridor Park"); - await expect(page.getByLabel('menu-options')).toContainText("Bamberton Park"); - await expect(page.getByLabel('menu-options')).toContainText("Banana Island Park"); - await expect(page.getByLabel('menu-options')).toContainText("Bear Creek Park"); - await expect(page.getByLabel('menu-options')).toContainText("Bear Glacier Park"); + test("Suggestion box is displayed when search by city has been selected", async ({page})=>{ + await homePage.focusCityNameSearch(); + await homePage.expectSuggestionVisible(); + await homePage.expectSuggestionOptionVisible('Current location'); }) - test('Check the suggestion box in search is displayed for city search', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await page.getByLabel('Near a city').fill("v"); - await expect(page.getByLabel('menu-options')).toBeVisible(); - await expect(page.getByLabel('menu-options')).toContainText("Vancouver"); - await expect(page.getByLabel('menu-options')).toContainText("Victoria"); - await expect(page.getByLabel('menu-options')).toContainText("Valemount"); - await expect(page.getByLabel('menu-options')).toContainText("Vanderhoof"); - await expect(page.getByLabel('menu-options')).toContainText("Vernon"); - await expect(page.getByLabel('menu-options')).toContainText("View Royal"); - await expect(page.getByLabel('menu-options')).toContainText("North Vancouver"); - await expect(page.getByLabel('menu-options')).toContainText("Current location"); - }) + test('Suggestion box in search is displayed for park search', async ({page})=>{ + await homePage.fillParkNameSearch('b'); + await homePage.expectSuggestionVisible(); + await expect(homePage.parkSuggestion).toContainText("Babine Lake Marine Park"); + await expect(homePage.parkSuggestion).toContainText("Babine Mountains Park"); + await expect(homePage.parkSuggestion).toContainText("Babine River Corridor Park"); + await expect(homePage.parkSuggestion).toContainText("Bamberton Park"); + await expect(homePage.parkSuggestion).toContainText("Banana Island Park"); + await expect(homePage.parkSuggestion).toContainText("Bear Creek Park"); + await expect(homePage.parkSuggestion).toContainText("Bear Glacier Park"); + }); - test('Check the book camping button is visible and redirects to correct page', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await expect(page.getByLabel('Book camping button')).toBeVisible(); - await page.getByLabel('Book camping button').click(); + test('Suggestion box in search is displayed for city search', async ({page})=>{ + await homePage.fillCityNameSearch('v'); + await homePage.expectSuggestionVisible(); + await expect(homePage.parkSuggestion).toContainText("Vancouver"); + await expect(homePage.parkSuggestion).toContainText("Victoria"); + await expect(homePage.parkSuggestion).toContainText("Valemount"); + await expect(homePage.parkSuggestion).toContainText("Vanderhoof"); + await expect(homePage.parkSuggestion).toContainText("Vernon"); + await expect(homePage.parkSuggestion).toContainText("View Royal"); + await expect(homePage.parkSuggestion).toContainText("North Vancouver"); + await expect(homePage.parkSuggestion).toContainText("Current location"); + }); + + test('Book camping button is visible and redirects to correct page', async ({page})=>{ + await homePage.expectBookingCampingButtonVisible(); + await homePage.clickBookingCampingButton(); await expect(page).toHaveURL('https://camping.bcparks.ca/'); - }); + test('The land acknowledgment message is visible', async ({page})=>{ + await homePage.scrollToBottom(); + await homePage.expectLandAcknowledgementMessageVisible(); + await homePage.landAcknowledgementMessageText(); + }); }); diff --git a/tests/megamenu.spec.js b/tests/megamenu.spec.js index 90061ad39..d89f08d36 100644 --- a/tests/megamenu.spec.js +++ b/tests/megamenu.spec.js @@ -114,7 +114,7 @@ test.describe('Check the level 1 menu items are displayed, active & clickable', await page.getByRole('menuitem', { name: 'Volunteer' }).click(); await expect(page.getByRole('menuitem', { name: 'Volunteer' }).nth(1)).toBeVisible(); await expect(page.getByRole('menuitem', { name: 'Volunteer Awards' })).toBeVisible(); - await expect(page.getByRole('menuitem', { name: 'Engage with us arrow-up-right' })).toBeVisible(); + await expect(page.getByRole('menuitem', { name: 'Engage with us' })).toBeVisible(); await expect(page.getByRole('menuitem', { name: 'Participate in design' })).toBeVisible(); await page.getByRole('menuitem', { name: 'Get involved', exact: true }).click(); await expect(page).toHaveURL(baseURL + 'get-involved/'); @@ -171,15 +171,15 @@ test.describe('Check the level 1 menu items are displayed, active & clickable', await expect(page.getByRole('menuitem', { name: 'Thompson Cariboo projects' })).toBeVisible(); await expect(page.getByRole('menuitem', { name: 'Omineca Peace projects' })).toBeVisible(); await expect(page.getByRole('menuitem', { name: 'Skeena projects' })).toBeVisible(); - await expect(page.getByRole('menuitem', { name: 'News' })).toBeVisible(); - await expect(page.getByRole('menuitem', { name: 'Reports and surveys' })).toBeVisible(); await expect(page.getByRole('menuitem', { name: 'Careers' })).toBeVisible(); await page.getByRole('menuitem', { name: 'Careers' }).click(); await expect(page.getByRole('menuitem', { name: 'Careers' }).nth(1)).toBeVisible(); await expect(page.getByRole('menuitem', { name: 'Park Ranger careers' })).toBeVisible(); await expect(page.getByRole('menuitem', { name: 'Student Rangers' })).toBeVisible(); await expect(page.getByRole('menuitem', { name: 'Park operators' })).toBeVisible(); - + await expect(page.getByRole('menuitem', { name: 'News' })).toBeVisible(); + await page.getByRole('menuitem', { name: 'Get involved ' }).click(); + await expect(page.getByRole('menuitem', { name: 'Engage with us' })).toBeVisible() }) //Check the Contact menu item, assert the navigateion to the corret page url @@ -187,9 +187,7 @@ test.describe('Check the level 1 menu items are displayed, active & clickable', await expect(page.getByRole('menuitem', { name: 'Contact' })).toBeVisible(); await page.getByRole('menuitem', {name: 'Contact'}).click(); await expect(page).toHaveURL(baseURL + 'contact/'); - ////latest code//// }) - }); diff --git a/tests/pages/basePage.js b/tests/pages/basePage.js new file mode 100644 index 000000000..2ffafd1b4 --- /dev/null +++ b/tests/pages/basePage.js @@ -0,0 +1,61 @@ +import { expect } from '@playwright/test'; + +export class BasePage{ + constructor(page){ + this.page = page; + this.baseURL = 'https://bcparks.ca/'; + + // Booking Camping button + this.bookingCampingButton = page.getByLabel('Book camping button'); + + // Scroll to the Top Button + this.backToTopButton = page.getByLabel('scroll to top'); + + // Land acknowledgement message + this.landAcknowledgementMessage = page.locator('#home div').filter({ hasText: 'We acknowledge all First' }).nth(1); + } + + async goto(path = ''){ + await this.page.goto(this.baseURL + path, { timeout: 90000 }); + } + + async waitForLoad(){ + await this.page.waitForLoadState('networkidle'); + } + + // Booking Camping button + async expectBookingCampingButtonVisible(){ + await expect(this.bookingCampingButton).toBeVisible(); + } + + async clickBookingCampingButton(){ + await this.bookingCampingButton.click(); + } + + // Scroll to the bottom of page + async scrollToBottom(){ + await this.page.evaluate(() => window.scrollTo(0, document.body.scrollHeight)); + } + + // Scroll to the Top Button + async expectBackToTopButtonVisible(){ + await expect(this.backToTopButton).toBeVisible(); + } + + async expectBackToTopButtonNotVisible(){ + await expect(this.backToTopButton).not.toBeVisible(); + } + + async clickBackToTopButton(){ + await this.backToTopButton.click(); + } + + // Land acknowledgement message + async expectLandAcknowledgementMessageVisible(){ + await expect(this.landAcknowledgementMessage).toBeVisible(); + } + + async landAcknowledgementMessageText(){ + await expect(this.landAcknowledgementMessage).toHaveText('We acknowledge all First Nations on whose territories BC Parks were established. We honour their connection to the land and respect the importance of their diverse teachings, traditions, and practices within these territories.'); + } +} \ No newline at end of file diff --git a/tests/pages/homePage.js b/tests/pages/homePage.js new file mode 100644 index 000000000..386605a09 --- /dev/null +++ b/tests/pages/homePage.js @@ -0,0 +1,146 @@ +import { BasePage } from './basePage.js'; +import { expect } from '@playwright/test'; + +export class HomePage extends BasePage{ + constructor(page){ + super(page); + + // Section headings + this.advisoriesHeading = page.getByRole('heading', { name: "Advisories" }); + this.whatsNewHeading = page.getByRole('heading', { name: "What’s new" }); + this.visitingUsHeading = page.getByRole('heading', { name: "Visiting us" }) + this.aboutBCParksHeading = page.getByRole('heading', { name: "About BC Parks" }); + + // Advisory links + this.floodAdvisoriesLink = page.getByRole('link', { name: 'See flood advisories'}); + this.wildfireAdvisoriesLink = page.getByRole('link', { name: 'See wildfire advisories'}) + this.allAdvisoriesLink = page.getByRole('link', { name: 'See all advisories'}); + + // Find a park search + this.findParkSearch = page.getByText('Find a parkBy park nameorNear'); + this.findParkSearchHeading = page.locator('h1', {name: 'Find a park'}); + this.findParkByParkName = page.getByLabel('By park name'); + this.findParkByCityName = page.getByLabel('Near a city'); + this.findParkSearchButton = page.getByRole('button', { name: 'Search'}); + this.parkSuggestion = page.getByLabel('menu-options'); + + // Visiting us links + this.campingInformationLink = page.getByRole('link', { name: 'Campers sitting near a tent' }); + this.thingsToDoLink = page.getByRole('link', { name: 'People taking a photo' }); + this.accessibilityLink = page.getByRole('link', { name: 'A child in a wheelchair on a' }); + this.visitingResponsiblyLink = page.getByRole('link', { name: 'Cleaning up after a dog Visit' }); + + // About BC Parks links + this.indigenousRelationsLink = page.getByRole('link', { name: 'An indigenous carving' }); + this.wildlifeViewingLink = page.getByRole('link', { name: 'A Bighorn Sheep Wildlife'}); + this.conservationLink = page.getByRole('link', { name: 'A mountain peak Conservation' }); + this.historyParkLink = page.getByRole('link', { name: 'Family walking on a trail' }); + this.getInvolvedLink = page.getByRole('link', { name: 'People holding licence plates' }); + } + + // --- Section headings --- + async expectSectionHeadingsVisible(){ + await expect(this.advisoriesHeading).toBeVisible(); + await expect(this.whatsNewHeading).toBeVisible(); + await expect(this.visitingUsHeading).toBeVisible(); + await expect(this.aboutBCParksHeading).toBeVisible(); + } + + // --- Advisory links --- + async expectAdvisoryLinksVisible(){ + await expect(this.floodAdvisoriesLink).toBeVisible(); + await expect(this.wildfireAdvisoriesLink).toBeVisible(); + await expect(this.allAdvisoriesLink).toBeVisible(); + } + + async clickFloodAdvisories(){ + await this.floodAdvisoriesLink.click(); + } + + async clickWildfireAdvisories(){ + await this.wildfireAdvisoriesLink.click(); + } + + async clickAllAdvisories(){ + await this.allAdvisoriesLink.click(); + } + + // --- Find a park search box --- + async expectFindParkSearchVisible(){ + await expect(this.findParkSearch).toBeVisible(); + } + + async fillParkNameSearch(value){ + await this.findParkByParkName.click(); + await this.findParkByParkName.fill(value); + } + + async expectSuggestionVisible(){ + await expect(this.parkSuggestion).toBeVisible(); + } + + async expectSuggestionOptionVisible(value){ + await expect(this.parkSuggestion.getByRole('option', { name: value })).toBeVisible(); + } + + async selectSuggestionOption(value){ + await this.parkSuggestion.getByRole('option', { name: value }).click(); + } + + async fillCityNameSearch(value){ + await this.findParkByCityName.click(); + await this.findParkByCityName.fill(value); + } + + async clickFindParkSearchButton(){ + await this.findParkSearchButton.click(); + } + + async focusCityNameSearch(){ + await this.findParkByCityName.click(); + } + + // --- Visiting us section --- + async campingInformationPage(){ + await this.campingInformationLink.click(); + } + + async thingsToDoPage(){ + await this.thingsToDoLink.click(); + } + + async accessibilityPage(){ + await this.accessibilityLink.click(); + } + + async visitingResponsiblyPage(){ + await this.visitingResponsiblyLink.click(); + } + + + // --- About BC Parks section --- + async indigenousRelationsPage(){ + await this.indigenousRelationsLink.click(); + } + + async wildlifeViewingPage(){ + await this.wildlifeViewingLink.click(); + } + + async conservationPage(){ + await this.conservationLink.click(); + } + + async historyOfParksPage(){ + await this.historyParkLink.click(); + } + + async getInvolvedPage(){ + await this.getInvolvedLink.click(); + } +} + + +/* + +*/ \ No newline at end of file diff --git a/tests/park_operating_date.spec.js b/tests/park_operating_date.spec.js index 9a5649109..84e0dee98 100644 --- a/tests/park_operating_date.spec.js +++ b/tests/park_operating_date.spec.js @@ -9,104 +9,133 @@ test.describe('Park Operating Date tests', ()=>{ await page.goto(baseURL); }); -test('Navigate to the Park Operating page via mega menu', async ({page})=>{ - await page.waitForLoadState('networkidle'); - await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); - await page.getByRole('menuitem', { name: 'Park operating dates'}).click(); - await expect(page).toHaveURL(baseURL + 'plan-your-trip/park-operating-dates/'); - await expect(page).toHaveTitle('Park operating dates | BC Parks'); -}); - -test('Check the breadcrumbs displayed', async ({page})=>{ - await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); - await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + test('Navigate to the Park Operating page via mega menu', async ({page})=>{ await page.waitForLoadState('networkidle'); - await expect (page.locator('#main-content')).toBeVisible(); - await page.getByRole('link', { name: 'Home' }).click(); - await expect(page).toHaveURL(baseURL); - await page.goBack(); - await page.getByRole('link', { name: 'Plan your trip' }).click(); - await expect(page).toHaveURL(baseURL + 'plan-your-trip/'); - await page.goBack(); - await expect(page.getByLabel('breadcrumb').getByText('Park operating dates')).toBeVisible(); -}); - -test('Check the filter menu is present and in default setting', async ({page})=>{ await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); - await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); - await page.waitForLoadState('networkidle'); - await expect(page.getByRole('heading', { name: 'Filter' })).toBeVisible(); - - // Check if 'All' button is visible and selected - const allButton = page.getByRole('button', { name: 'All'}); - await expect(allButton).toBeVisible(); - await expect(allButton).toHaveClass('btn btn-selected--true'); - - // Letters to check in the filter menu - const letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; - - // Loop through each letter and verify if the button is visible and not selected - for (const letter of letters) { - const button = page.getByLabel(letter, { exact: true }); - await expect(button).toBeVisible(); - await expect(button).toHaveClass('btn btn-selected--false'); - } -}); + await page.getByRole('menuitem', { name: 'Park operating dates'}).click(); + await expect(page).toHaveURL(baseURL + 'plan-your-trip/park-operating-dates/'); + await expect(page).toHaveTitle('Park operating dates | BC Parks'); + }); -test('Verify that the park names redirect to the correct park page', async ({page})=>{ - await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); - await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'Adams Lake Park – Bush Creek' }).click(); - await expect(page).toHaveURL('https://bcparks.ca/adams-lake-park-bush-creek-site/'); - await expect(page).toHaveTitle('Adams Lake Park – Bush Creek Site | BC Parks'); - await expect(page.getByRole('heading', { name: 'Adams Lake Park – Bush Creek' })).toHaveText('Adams Lake Park – Bush Creek Site'); - await page.goBack(); - await page.getByRole('link', { name: 'Akamina-Kishinena Park' }).click(); - await expect(page).toHaveURL('https://bcparks.ca/akamina-kishinena-park/'); - await expect(page).toHaveTitle('Akamina-Kishinena Park | BC Parks'); - await expect(page.getByRole('heading', { name: 'Akamina-Kishinena Park' })).toHaveText('Akamina-Kishinena Park'); -}) - -test('Check the park information is displayed', async ({page})=>{ - await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); - await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); - await page.waitForLoadState('networkidle'); - await page.getByLabel('V', { exact: true}).click(); - await expect(page.getByRole('link', { name: 'Vaseux Lake Park'})).toBeVisible(); - await expect(page.getByRole('cell', { name: 'Vaseux Lake Campground' })).toBeVisible(); -}); + test('Check the breadcrumbs displayed', async ({page})=>{ + await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); + await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + await page.waitForLoadState('networkidle'); + await expect (page.locator('#main-content')).toBeVisible(); + await page.getByRole('link', { name: 'Home' }).click(); + await expect(page).toHaveURL(baseURL); + await page.goBack(); + await page.getByRole('link', { name: 'Plan your trip' }).click(); + await expect(page).toHaveURL(baseURL + 'plan-your-trip/'); + await page.goBack(); + await expect(page.getByLabel('breadcrumb').getByText('Park operating dates')).toBeVisible(); + }); -test('Verify the hyperlinks on the page are working', async ({page})=>{ - await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); - await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); - await page.waitForLoadState('networkidle'); - await page.getByRole('link', { name: 'active advisories' }).click(); - await expect(page).toHaveURL(baseURL + 'active-advisories/'); - await page.goBack(); -}); + test('Check the filter menu is present and in default setting', async ({page})=>{ + await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); + await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + await page.waitForLoadState('networkidle'); + await expect(page.getByRole('heading', { name: 'Filter' })).toBeVisible(); + + // Check if 'All' button is visible and selected + const allButton = page.getByRole('button', { name: 'All'}); + await expect(allButton).toBeVisible(); + await expect(allButton).toHaveClass('btn btn-selected--true'); + + // Letters to check in the filter menu + const letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; + + // Loop through each letter and verify if the button is visible and not selected + for (const letter of letters) { + const button = page.getByLabel(letter, { exact: true }); + await expect(button).toBeVisible(); + await expect(button).toHaveClass('btn btn-selected--false'); + } + }); + test('Verify that the park names redirect to the correct park page', async ({page})=>{ + await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); + await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + await page.waitForLoadState('networkidle'); + await page.getByRole('link', { name: 'Adams Lake Park – Bush Creek' }).click(); + await expect(page).toHaveURL('https://bcparks.ca/adams-lake-park-bush-creek-site/'); + await expect(page).toHaveTitle('Adams Lake Park – Bush Creek Site | BC Parks'); + await expect(page.getByRole('heading', { name: 'Adams Lake Park – Bush Creek' })).toHaveText('Adams Lake Park – Bush Creek Site'); + await page.goBack(); + await page.getByRole('link', { name: 'Akamina-Kishinena Park' }).click(); + await expect(page).toHaveURL('https://bcparks.ca/akamina-kishinena-park/'); + await expect(page).toHaveTitle('Akamina-Kishinena Park | BC Parks'); + await expect(page.getByRole('heading', { name: 'Akamina-Kishinena Park' })).toHaveText('Akamina-Kishinena Park'); + }) + + test('Check the park information is displayed', async ({page})=>{ + await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); + await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + await page.waitForLoadState('networkidle'); + await page.getByLabel('V', { exact: true}).click(); + await expect(page.getByRole('link', { name: 'Vaseux Lake Park'})).toBeVisible(); + await expect(page.getByText('Open, check advisories (1).The park is open year-round.')).toBeVisible();; + await expect(page.getByRole('cell', { name: 'Vaseux Lake Campground' })).toBeVisible(); + }); -test('Check the park links are working and redirect to the correct site', async({page})=>{ - await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); - await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); - //await page.waitForLoadState('networkidle'); - test.setTimeout(60000); // Increase the timeout to 60 seconds - // Select all links on the page - const links = await page.$$(`a`); - // Loop through each link - for (const link of links) { - const text = await link.textContent(); // Get the text content of the link - - // Check if the text includes 'Check the park' - if (text.includes('Check the park')) { - await link.click(); - await expect(page).toHaveURL(baseURL + 'find-a-park/'); - await page.goBack(); - } - - }; -}); + test('Verify the hyperlinks on the page are working', async ({page})=>{ + await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); + await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + await page.waitForLoadState('networkidle'); + await page.getByRole('link', { name: 'active advisories' }).click(); + await expect(page).toHaveURL(baseURL + 'active-advisories/'); + await page.goBack(); + }); + + + test('Check the park links are working and redirect to the correct site', async({page})=>{ + await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); + await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + //await page.waitForLoadState('networkidle'); + test.setTimeout(60000); // Increase the timeout to 60 seconds + // Select all links on the page + const links = await page.$$(`a`); + // Loop through each link + for (const link of links) { + const text = await link.textContent(); // Get the text content of the link + + // Check if the text includes 'Check the park' + if (text.includes('Check the park')) { + await link.click(); + await expect(page).toHaveURL(baseURL + 'find-a-park/'); + await page.goBack(); + } + + }; + }); + + test('Check the land acknowledgment message is visible', async ({page})=>{ + await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); + await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + await page.waitForLoadState('networkidle'); + await page.evaluate(() =>{ + window.scrollBy(0, 5000); + }); + await expect(page.locator('div').filter({ hasText: 'We acknowledge all First' }).nth(3)).toBeVisible(); + await expect(page.locator('div').filter({ hasText: 'We acknowledge all First' }).nth(3)).toContainText('We acknowledge all First Nations on whose territories BC Parks were established. We honour their connection to the land and respect the importance of their diverse teachings, traditions, and practices within these territories.') + await expect(page.getByText('We acknowledge all First')).toBeVisible(); + }); + + + test('Check the back to top button is working', async ({ page }) => { + await page.getByRole('menuitem', { name: 'Plan your trip' }).click(); + await page.getByRole('menuitem', { name: 'Park operating dates' }).click(); + await page.waitForLoadState('networkidle'); + await page.evaluate(() => { + window.scrollBy(0, 5000); + }); + await expect(page.getByLabel('scroll to top')).toBeVisible(); + await page.getByLabel('scroll to top').click(); + await page.waitForTimeout(5000) + const updatedScrollPosition = await page.evaluate(() => window.scrollY); + expect(updatedScrollPosition).toBe(0); + await expect(page.getByLabel('scroll to top')).toBeHidden(); + }); });