-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixtures.ts
More file actions
40 lines (32 loc) · 1.53 KB
/
Copy pathfixtures.ts
File metadata and controls
40 lines (32 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { test as baseTest, expect } from '@playwright/test';
import fs from 'fs';
import { baseURL, GRID } from './playwright.config';
export * from '@playwright/test';
export const test = baseTest.extend<{}, { workerStorageState: string }>({
// Use the same storage state for all tests in this worker.
storageState: ({ workerStorageState }, use) => use(workerStorageState),
// Authenticate once per worker with a worker-scoped fixture.
workerStorageState: [async ({ browser }, use) => {
// Use parallelIndex as a unique identifier for each worker.
const fileName = `.auth/${GRID}-cookies.json`;
if (fs.existsSync(fileName)) {
// Reuse existing authentication state if any.
await use(fileName);
return;
}
// Important: make sure we authenticate in a clean environment by unsetting storage state.
const page = await browser.newPage({ storageState: undefined });
await page.goto(baseURL);
await page.getByRole('link', { name: 'CAC / GEOAxIS Signup / Login' }).click();
await page.getByRole('link', { name: 'Sign in with PKI Certificate' }).click();
// Wait for user input
await page.waitForTimeout(10000);
await page.getByText('Continue to application').click();
// Wait until the page receives the cookies.
await expect(page.locator('#navbarToggle').getByRole('link', { name: 'Map' })).toBeVisible();
// End of authentication steps.
await page.context().storageState({ path: fileName });
await page.close();
await use(fileName);
}, { scope: 'worker' }],
});