-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add loginpage and reviewer auth to e2e setup
- Loading branch information
1 parent
63abb97
commit 4e0ab98
Showing
8 changed files
with
64 additions
and
32 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 |
---|---|---|
|
@@ -14,4 +14,4 @@ build_run | |
.turbo | ||
coverage | ||
lambda_layer.zip | ||
**/.auth/user.json | ||
**/.auth/*.json |
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 @@ | ||
export * from "./loginPage"; |
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,21 @@ | ||
import { Page, expect } from "@playwright/test"; | ||
|
||
export class LoginPage { | ||
constructor(private readonly page: Page) {} | ||
|
||
async goto() { | ||
await this.page.goto("/"); | ||
await this.page.getByRole("button", { name: "Sign In" }).click(); | ||
} | ||
|
||
async login(email: string, password: string) { | ||
await this.goto(); | ||
await this.page.getByRole("textbox", { name: "[email protected]" }).fill(email); | ||
await this.page.getByRole("textbox", { name: "Password" }).fill(password); | ||
await this.page.getByRole("button", { name: "submit" }).click(); | ||
await this.page.waitForLoadState("networkidle"); | ||
expect( | ||
await this.page.getByRole("link", { name: "Dashboard" }) | ||
).toBeVisible(); | ||
} | ||
} |
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,17 +1,21 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import AxeBuilder from "@axe-core/playwright"; | ||
|
||
// this could be repeated for every page we want to test a11y for. | ||
// we could also have a list of paths to test and loop through them ie ['/', 'dashboard', 'faq'] etc | ||
const staticRoutes = ["/", "/dashboard", "/faq", "/profile"]; | ||
|
||
test.describe("homepage", () => { | ||
test("should not have any automatically detectable accessibility issues", async ({ | ||
page, | ||
}) => { | ||
await page.goto("/"); | ||
await page.waitForLoadState("networkidle"); // playwright is so fast this is sometimes helpful to slow it down to view results | ||
const accessibilityScanResults = await new AxeBuilder({ page }).analyze(); | ||
console.log("violations: ", accessibilityScanResults.violations.length); | ||
expect(accessibilityScanResults.violations).toEqual([]); | ||
}); | ||
test.describe("test a11y on static routes", () => { | ||
for (const route of staticRoutes) { | ||
test(`${route} should not have any automatically detectable accessibility issues`, async ({ | ||
page, | ||
}) => { | ||
await page.goto(route); | ||
await page.waitForLoadState("networkidle"); // playwright is so fast this is sometimes helpful to slow it down to view results | ||
const accessibilityScanResults = await new AxeBuilder({ page }).analyze(); | ||
console.log( | ||
`${route} violations: `, | ||
accessibilityScanResults.violations.length | ||
); | ||
expect(accessibilityScanResults.violations).toEqual([]); | ||
}); | ||
} | ||
}); |
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,6 +1,7 @@ | ||
import { test as setup } from "@playwright/test"; | ||
import * as Libs from "../../../../libs/secrets-manager-lib"; | ||
import { testUsers } from "./users"; | ||
import { LoginPage } from "../pages"; | ||
|
||
const stage = | ||
process.env.STAGE_NAME === "production" || process.env.STAGE_NAME === "val" | ||
|
@@ -13,18 +14,22 @@ const password = (await Libs.getSecretsValue( | |
secretId | ||
)) as string; | ||
|
||
const authFile = "playwright/.auth/user.json"; | ||
const stateSubmitterAuthFile = "playwright/.auth/state-user.json"; | ||
|
||
setup("authenticate", async ({ page }) => { | ||
await page.goto("/"); | ||
await page.getByRole("button", { name: "Sign In" }).click(); | ||
await page | ||
.getByRole("textbox", { name: "[email protected]" }) | ||
.fill(testUsers.state); | ||
await page.getByRole("textbox", { name: "Password" }).fill(password); | ||
await page.getByRole("button", { name: "submit" }).click(); | ||
await page.getByRole("link", { name: "Dashboard" }).click(); | ||
// End of authentication steps. | ||
setup("authenticate state submitter", async ({ page, context }) => { | ||
const loginPage = new LoginPage(page); | ||
await loginPage.goto(); | ||
|
||
await page.context().storageState({ path: authFile }); | ||
await loginPage.login(testUsers.state, password); | ||
await context.storageState({ path: stateSubmitterAuthFile }); | ||
}); | ||
|
||
const reviewerAuthFile = "playwright/.auth/reviewer-user.json"; | ||
|
||
setup("authenticate cms reviewer", async ({ page, context }) => { | ||
const loginPage = new LoginPage(page); | ||
await loginPage.goto(); | ||
|
||
await loginPage.login(testUsers.reviewer, password); | ||
await context.storageState({ path: reviewerAuthFile }); | ||
}); |
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,4 +1,4 @@ | ||
export const testUsers = { | ||
state: "[email protected]", | ||
cmsAdmin: "cmsadmin@example.com" | ||
}; | ||
state: "[email protected]", | ||
reviewer: "reviewer@example.com", | ||
}; |
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