-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: attempting to reuse single login across multiple tests
- Loading branch information
1 parent
b2d088d
commit abdd4d1
Showing
4 changed files
with
117 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,5 @@ ssmSetup.zsh | |
|
||
|
||
# open-next | ||
.open-next | ||
.open-next | ||
playwright/.auth |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { test as setup, expect } from "@playwright/test"; | ||
import path from "path"; | ||
|
||
const authFile = path.join(__dirname, "../playwright/.auth/user.json"); | ||
|
||
setup("authenticate", async ({ page }) => { | ||
// Perform authentication steps. Replace these actions with your own. | ||
try { | ||
expect(process.env.E2E_GITHUB_EMAIL).toBeDefined(); | ||
expect(process.env.E2E_GITHUB_PASSWORD).toBeDefined(); | ||
const email = process.env.E2E_GITHUB_EMAIL; | ||
const password = process.env.E2E_GITHUB_PASSWORD; | ||
|
||
if (!email || !password) { | ||
throw new Error( | ||
email || password | ||
? "Missing both E2E test user credentials from environment" | ||
? "Missing E2E_GITHUB_EMAIL from environment" | ||
: "Missing E2E_GITHUB_PASSWORD from environment", | ||
); | ||
} | ||
|
||
// Perform authentication steps. Replace these actions with your own. | ||
await page.goto("https://github.com/login"); | ||
await page.getByLabel("Username or email address").fill(email); | ||
await page.getByLabel("Password").fill(password); | ||
await page.getByRole("button", { name: "Sign in" }).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("https://github.com/"); | ||
|
||
// End of authentication steps. | ||
|
||
await page.goto("http://localhost:3000/get-started"); | ||
await page.getByTestId("github-login-button").click(); | ||
//await page.waitForURL("https://github.com/**"); | ||
await page.waitForLoadState(); | ||
|
||
if (await page.getByText("Authorize JohnAllenTech").isVisible()) { | ||
// await page.getByText("Authorize JohnAllenTech").click(); | ||
await page | ||
.getByRole("button", { name: "Authorize JohnAllenTech" }) | ||
.click(); | ||
|
||
await page.waitForLoadState(); | ||
} | ||
|
||
await page.waitForURL("http://localhost:3000"); | ||
|
||
await page.context().storageState({ path: authFile }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}); |
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