Skip to content

Commit

Permalink
Refactor test to add step in beforeeach
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianneOXD committed Jul 29, 2024
1 parent 704bb32 commit 9b4f957
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions tests/homepage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -20,15 +20,13 @@ 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();
});

// 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();
Expand All @@ -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');
Expand All @@ -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();
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9b4f957

Please sign in to comment.