-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change tests to always register a new user before running, skip flaky…
… tests
- Loading branch information
Showing
5 changed files
with
32 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,31 @@ | ||
import { test as baseTest } from '@playwright/test'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { PLAYWRIGHT_BASE_URL } from './config'; | ||
|
||
export * from '@playwright/test'; | ||
export const test = baseTest.extend<object, { 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 id = test.info().parallelIndex; | ||
const fileName = path.resolve( | ||
test.info().project.outputDir, | ||
`.auth/${id}.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 }); | ||
|
||
// Acquire a unique account, for example create a new one. | ||
// Alternatively, you can have a list of precreated accounts for testing. | ||
// Make sure that accounts are unique, so that multiple team members | ||
// can run tests at the same time without interference. | ||
// const account = await acquireAccount(id); | ||
|
||
// TODO: Use Seeder Accounts instead of creating new ones | ||
|
||
// Perform authentication steps. Replace these actions with your own. | ||
await page.goto(PLAYWRIGHT_BASE_URL + '/register'); | ||
await page.getByLabel('Name').fill('John Doe'); | ||
await page | ||
.getByLabel('Email') | ||
.fill(`john+${Math.round(Math.random() * 10000)}@doe.com`); | ||
await page | ||
.getByLabel('Password', { exact: true }) | ||
.fill('amazingpassword123'); | ||
await page | ||
.getByLabel('Confirm Password') | ||
.fill('amazingpassword123'); | ||
await page.getByRole('button', { name: 'Register' }).click(); | ||
|
||
// Wait until the page receives the cookies. | ||
// | ||
// Sometimes login flow sets cookies in the process of several redirects. | ||
// Wait for the final URL to ensure that the cookies are actually set. | ||
await page.waitForURL(PLAYWRIGHT_BASE_URL + '/dashboard'); | ||
|
||
// End of authentication steps. | ||
|
||
await page.context().storageState({ path: fileName }); | ||
await page.close(); | ||
await use(fileName); | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
page: async ({ page }, use) => { | ||
// Perform authentication steps. Replace these actions with your own. | ||
await page.goto(PLAYWRIGHT_BASE_URL + '/register'); | ||
await page.getByLabel('Name').fill('John Doe'); | ||
await page | ||
.getByLabel('Email') | ||
.fill(`john+${Math.round(Math.random() * 10000)}@doe.com`); | ||
await page | ||
.getByLabel('Password', { exact: true }) | ||
.fill('amazingpassword123'); | ||
await page.getByLabel('Confirm Password').fill('amazingpassword123'); | ||
await page.getByLabel('I agree to the Terms of').click(); | ||
await page.getByRole('button', { name: 'Register' }).click(); | ||
|
||
// Wait until the page receives the cookies. | ||
// | ||
// Sometimes login flow sets cookies in the process of several redirects. | ||
// Wait for the final URL to ensure that the cookies are actually set. | ||
await page.waitForURL(PLAYWRIGHT_BASE_URL + '/dashboard'); | ||
|
||
// End of authentication steps. | ||
|
||
await use(page); | ||
}, | ||
}); |