From 9b4f957c5f534f6d3cbe292e88ce52f48784f9a7 Mon Sep 17 00:00:00 2001 From: adrianneOXD <107157705+adrianneOXD@users.noreply.github.com> Date: Mon, 29 Jul 2024 08:58:57 -0700 Subject: [PATCH] Refactor test to add step in beforeeach --- tests/homepage.spec.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/homepage.spec.js b/tests/homepage.spec.js index ff4d41f1a..97bcb9406 100644 --- a/tests/homepage.spec.js +++ b/tests/homepage.spec.js @@ -6,12 +6,12 @@ test.describe('Home page tests', ()=>{ const baseURL = 'https://bcparks.ca/'; test.beforeEach(async ({page})=>{ - await page.goto(baseURL, { timeout: 90000 }); + await page.goto(baseURL); + await page.waitForLoadState('domcontentloaded'); }) // Check that user can reach the home page test('Check that the page has connected', async ({page}) =>{ - await page.waitForLoadState('domcontentloaded'); await expect(page).toHaveTitle('Home | BC Parks'); await expect(page).toHaveURL(baseURL); }); @@ -20,7 +20,6 @@ test.describe('Home page tests', ()=>{ // Checks the section headings on the home page test('Verify the h2 headings are visible on the home page', async ({page}) =>{ - await page.waitForLoadState('domcontentloaded'); 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(); @@ -28,7 +27,6 @@ test.describe('Home page tests', ()=>{ // Checks the 'Find a park' search box test('Verify the Find a Park search box is present', async ({page}) =>{ - await page.waitForLoadState('domcontentloaded'); 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(); @@ -37,7 +35,6 @@ test.describe('Home page tests', ()=>{ // 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('domcontentloaded'); await page.getByLabel('By park name').click(); await expect(page.getByLabel('menu-options')).toBeVisible(); await page.getByLabel('By park name').fill('G'); @@ -50,7 +47,6 @@ test.describe('Home page tests', ()=>{ // 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('domcontentloaded'); await page.getByLabel('Near a city').click(); await expect(page.getByLabel('menu-options')).toBeVisible(); await expect(page.getByRole('option', { name: 'Current location' })).toBeVisible(); @@ -63,7 +59,6 @@ test.describe('Home page tests', ()=>{ // 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('domcontentloaded'); 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'); @@ -72,14 +67,12 @@ test.describe('Home page tests', ()=>{ // Checks redirect works when clicking search button test('Search for a park with no search terms', async ({page})=>{ - await page.waitForLoadState('domcontentloaded'); await page.getByRole('button', { name: 'Search'}).click(); await expect(page).toHaveURL(baseURL + '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('domcontentloaded'); await page.getByRole('link', { name: 'See flood advisories'}).click(); await expect(page).toHaveURL(baseURL + 'active-advisories/?type=Flood'); await expect(page).toHaveTitle('Active advisories | BC Parks'); @@ -133,7 +126,6 @@ test.describe('Home page tests', ()=>{ // 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('domcontentloaded'); await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight)); await expect(page.getByRole('link', { name: 'BC Parks Logo' })).not.toBeInViewport(); await expect(page.getByLabel('scroll to top')).toBeVisible();