Skip to content

Commit 22bffc7

Browse files
committed
Tests: Make test less flaky
1 parent 11c2f35 commit 22bffc7

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

tests/src/cards.spec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ test.describe('Testing for cards shortcode', () => {
55
test.beforeEach(async ({ page }) => {
66
const cardsUrl = 'test-product/cards/permitted';
77
await page.goto(`/${cardsUrl}`);
8+
await page.waitForLoadState('networkidle');
89
await waitFor(async () => await handleConsentPopup(page));
910
});
1011

1112
test('basic section', async ({ page }) => {
12-
const section = await page.getByTestId('cards-test__basic');
13-
const showAsCardCode = await section.getByTestId('card-section-content');
13+
const section = page.getByTestId('cards-test__basic');
14+
const showAsCardCode = section.getByTestId('card-section-content');
1415

1516
expect(await showAsCardCode.count()).toBe(0);
1617
});
1718

1819
test('featured section', async ({ page }) => {
19-
const section = await page.getByTestId('cards-test__featuredSection');
20-
const featuredSection = await section.getByTestId(
20+
const section = page.getByTestId('cards-test__featuredSection');
21+
const featuredSection = section.getByTestId(
2122
'card-section__featured-section'
2223
);
23-
const cards = await (await featuredSection.getByTestId('card')).all();
24+
const cards = await featuredSection.getByTestId('card').all();
2425

2526
// Test featured section exists AND there are less than or equal to 3 cards.
2627
expect(await featuredSection.count()).toBeTruthy();

tests/src/footer.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { handleConsentPopup, waitFor } from './util';
44
test.describe('Smoke test for footer', () => {
55
test.beforeEach(async ({ page }) => {
66
await page.goto('/test-product');
7+
await page.waitForLoadState('networkidle');
78
await waitFor(async () => await handleConsentPopup(page));
89
});
910

tests/src/header.spec.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { handleConsentPopup, waitFor } from './util';
44
test.describe('Smoke test for header', () => {
55
test.beforeEach(async ({ page }) => {
66
await page.goto('/test-product');
7+
await page.waitForLoadState('networkidle');
78
await waitFor(async () => await handleConsentPopup(page));
89
});
910

@@ -18,13 +19,13 @@ test.describe('Smoke test for header', () => {
1819
});
1920

2021
test('header control works', async ({ page }) => {
21-
const sidebarButtonClose = await page.getByTestId(
22+
const sidebarButtonClose = page.getByTestId(
2223
'header__control--sidebar--close'
2324
);
24-
const sidebarButtonOpen = await page.getByTestId(
25+
const sidebarButtonOpen = page.getByTestId(
2526
'header__control--sidebar--open'
2627
);
27-
const sidebar = await page.getByTestId('sidebar');
28+
const sidebar = page.getByTestId('sidebar');
2829

2930
// Close the sidebar
3031
await expect(sidebarButtonClose).toBeVisible();
@@ -44,9 +45,11 @@ test.describe('Smoke test for header', () => {
4445
});
4546

4647
test('F5 Sites button works', async ({ page }) => {
47-
const f5SitesButton = await page.getByTestId('header__f5sites_button');
48-
await f5SitesButton.click();
49-
const f5SitesContent = await page.getByTestId('header__f5sites_content');
50-
await expect(f5SitesContent.count()).toBeTruthy();
48+
const f5SitesButton = page.getByTestId('header__f5sites_button');
49+
await expect(async () => {
50+
await f5SitesButton.click();
51+
const f5SitesContent = page.getByTestId('header__f5sites_content');
52+
await expect(f5SitesContent).toBeVisible();
53+
}).toPass();
5154
});
5255
});

tests/src/product-landing.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ test.describe('Smoke test for landing page', () => {
77

88
for (const product of products) {
99
await page.goto(`/${product}/`);
10+
await page.waitForLoadState('networkidle');
1011
await runSmokeTestOnPage(page);
1112
}
1213
});

tests/src/sidebar.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function openPage(page, sidebarPage) {
3535

3636
// Click on the page
3737
await sidebarPage.click();
38-
const content = await page.getByTestId('content');
38+
const content = page.getByTestId('content');
3939
await content.waitFor();
4040
}
4141

@@ -45,6 +45,7 @@ test.describe('Smoke test for sidebar', () => {
4545

4646
test.beforeEach(async ({ page }) => {
4747
await page.goto('/test-product/');
48+
await page.waitForLoadState('networkidle');
4849
});
4950

5051
test('sidebar renders', async ({ page }) => {

tests/src/tabs.spec.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@ test.describe('Testing for tabs shortcode', () => {
55
test.beforeEach(async ({ page }) => {
66
const tabsUrl = 'test-product/tab-group/tab-group/';
77
await page.goto(`/${tabsUrl}`);
8+
await page.waitForLoadState('networkidle');
89
await waitFor(async () => await handleConsentPopup(page));
910
});
1011

1112
test('tabs render', async ({ page }) => {
12-
const section = await page.getByTestId('tabs-test__basic');
13-
const tabsContainer = await section.getByTestId('tabs-container');
14-
const tabLabels = await tabsContainer.getByTestId('tab-labels');
15-
const tabContents = await tabsContainer.getByTestId('tab-contents');
13+
const section = page.getByTestId('tabs-test__basic');
14+
const tabsContainer = section.getByTestId('tabs-container');
15+
const tabLabels = tabsContainer.getByTestId('tab-labels');
16+
const tabContents = tabsContainer.getByTestId('tab-contents');
1617

1718
expect(await tabsContainer.count()).toBeTruthy();
1819
expect(await tabLabels.count()).toBeTruthy();
1920
expect(await tabContents.count()).toBeTruthy();
2021
});
2122

2223
test('tabs shift content when clicked', async ({ page }) => {
23-
const section = await page.getByTestId('tabs-test__basic');
24-
const tabsContainer = await section.getByTestId('tabs-container');
25-
const tabLabels = await tabsContainer.getByTestId('tab-labels');
26-
const tabContents = await tabsContainer.getByTestId('tab-contents');
24+
const section = page.getByTestId('tabs-test__basic');
25+
const tabsContainer = section.getByTestId('tabs-container');
26+
const tabLabels = tabsContainer.getByTestId('tab-labels');
27+
const tabContents = tabsContainer.getByTestId('tab-contents');
2728

2829
const tabsList = await tabLabels.locator('li').all();
2930
for (const tab of tabsList) {

0 commit comments

Comments
 (0)