Skip to content

Commit 36cc94d

Browse files
author
Triona Doyle
committed
Address coderabbit suggestion: ensure Playwright context closes cleanly on failure
Signed-off-by: Triona Doyle <tekton@example.com>
1 parent c0d3b2b commit 36cc94d

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

test/ui-e2e/tests/admin-login.spec.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@ test('Log into Argo CD as local admin', async ({ browser }) => {
3232
ignoreHTTPSErrors: true
3333
});
3434

35-
//Navigate and wait for the page to be loaded
36-
const page = await context.newPage();
37-
const loginUrl = `https://${routeUrl}/login?dex=none`;
38-
await page.goto(loginUrl, { waitUntil: 'load' });
39-
40-
const userField = page.getByLabel(/username/i);
41-
await userField.waitFor({ state: 'visible', timeout: 20000 });
42-
43-
//Fill and Sign In
44-
await userField.fill('admin');
45-
await page.locator('input[type="password"]').fill(password);
46-
await page.getByRole('button', { name: /sign in/i }).click();
47-
48-
//Verify we're logged in
49-
await expect(page.locator('.sidebar, [data-testid="sidebar"]').first()).toBeVisible({ timeout: 20000 });
50-
51-
await context.close();
52-
});
35+
try {
36+
//Navigate and wait for the page to be loaded
37+
const page = await context.newPage();
38+
const loginUrl = `https://${routeUrl}/login?dex=none`;
39+
await page.goto(loginUrl, { waitUntil: 'load' });
40+
41+
const userField = page.getByLabel(/username/i);
42+
await userField.waitFor({ state: 'visible', timeout: 20000 });
43+
44+
//Fill and Sign In
45+
await userField.fill('admin');
46+
await page.locator('input[type="password"]').fill(password);
47+
await page.getByRole('button', { name: /sign in/i }).click();
48+
49+
//Verify we're logged in
50+
await expect(page.locator('.sidebar, [data-testid="sidebar"]').first()).toBeVisible({ timeout: 20000 });
51+
} finally {
52+
// This guarantees the context closes even if an assertion fails above!
53+
await context.close();
54+
}
55+
});

0 commit comments

Comments
 (0)