Skip to content

Commit feda356

Browse files
Copilotdannystaple
andcommitted
Finalize Playwright step definitions with robust timeout handling
Co-authored-by: dannystaple <[email protected]>
1 parent b8f3de6 commit feda356

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

tests/staging/step_definitions/website_steps.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ BeforeAll(async function () {
1414
headless: true,
1515
args: ['--no-sandbox', '--disable-setuid-sandbox']
1616
});
17-
context = await browser.newContext();
17+
context = await browser.newContext({
18+
// Increase timeout for slower Docker environments
19+
timeout: 30000
20+
});
1821
});
1922

2023
AfterAll(async function () {
@@ -26,8 +29,11 @@ Given('the Staging site is started', async function () {
2629
page = await context.newPage();
2730

2831
try {
29-
// Verify that the BASE_URL can be reached
30-
const response = await page.goto(BASE_URL, { waitUntil: 'networkidle' });
32+
// Verify that the BASE_URL can be reached (allow redirects)
33+
const response = await page.goto(BASE_URL, {
34+
waitUntil: 'networkidle',
35+
timeout: 30000
36+
});
3137

3238
if (!response || !response.ok()) {
3339
throw new Error(`Failed to reach staging site at ${BASE_URL}. Status: ${response ? response.status() : 'No response'}`);
@@ -43,14 +49,17 @@ When('the index page is visited', async function () {
4349
}
4450

4551
// Navigate to the index page and ensure it loads without HTTP errors
46-
const response = await page.goto(BASE_URL, { waitUntil: 'networkidle' });
52+
const response = await page.goto(BASE_URL, {
53+
waitUntil: 'networkidle',
54+
timeout: 30000
55+
});
4756

4857
if (!response || !response.ok()) {
4958
throw new Error(`Index page failed to load. Status: ${response ? response.status() : 'No response'}`);
5059
}
5160

5261
// Verify the page has loaded by checking for basic HTML structure
53-
await page.waitForSelector('html');
62+
await page.waitForSelector('html', { timeout: 10000 });
5463
});
5564

5665
Then('the Logo should be displayed in the top left corner', async function () {
@@ -59,11 +68,11 @@ Then('the Logo should be displayed in the top left corner', async function () {
5968
}
6069

6170
// Check that favicon.png is somewhere nested under a <nav> element
62-
const faviconInNav = await page.locator('nav img[src*="favicon.png"]').first();
63-
64-
const isVisible = await faviconInNav.isVisible().catch(() => false);
65-
66-
if (!isVisible) {
71+
// This covers both relative paths (favicon.png) and absolute URLs containing favicon.png
72+
try {
73+
const faviconInNav = await page.locator('nav img[src*="favicon.png"]').first();
74+
await faviconInNav.waitFor({ state: 'visible', timeout: 10000 });
75+
} catch (error) {
6776
throw new Error('Logo (favicon.png) is not displayed in a nav element');
6877
}
6978
});

0 commit comments

Comments
 (0)