-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor E2E tests to use Page Object Model (POM), fixtures, and add additional tests #2945
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
import { test as base } from "@playwright/test" | ||
import { AuthPage } from "../pages/auth-page" | ||
import { ReportIncidentPage } from "../pages/report-incident-page" | ||
import { IncidentsPage } from "../pages/incidents-page" | ||
|
||
type DispatchFixtures = { | ||
authPage: AuthPage | ||
reportIncidentPage: ReportIncidentPage | ||
incidentsPage: IncidentsPage | ||
} | ||
|
||
export const test = base.extend<DispatchFixtures>({ | ||
authPage: async ({ page }, use) => { | ||
await use(new AuthPage(page)) | ||
}, | ||
|
||
reportIncidentPage: async ({ page }, use) => { | ||
await use(new ReportIncidentPage(page)) | ||
}, | ||
|
||
incidentsPage: async ({ page }, use) => { | ||
const incidentsPage = new IncidentsPage(page) | ||
await use(incidentsPage) | ||
}, | ||
}) | ||
export { expect } from "@playwright/test" |
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,20 @@ | ||
import { test, expect } from "./fixtures/dispatch-fixtures" | ||
import register from "./utils/register" | ||
|
||
test.describe("Authenticated Dispatch App", () => { | ||
test.beforeEach(async ({ authPage }) => { | ||
await register(authPage) | ||
}), | ||
test("The edit list should appear after clicking the incident edit kebab.", async ({ | ||
incidentsPage, | ||
}) => { | ||
await incidentsPage.goto() | ||
await incidentsPage.EditKebab.click() | ||
await expect(incidentsPage.EditMenu).toBeVisible() | ||
await expect.soft(incidentsPage.EditMenu).toBeVisible() | ||
await expect.soft(incidentsPage.EditViewEdit).toBeVisible() | ||
await expect.soft(incidentsPage.EditCreateReport).toBeVisible() | ||
await expect.soft(incidentsPage.EditRunWorkflow).toBeVisible() | ||
await expect.soft(incidentsPage.EditDelete).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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { expect, Locator, Page } from "@playwright/test" | ||
import { orgSlug, Routes } from "../routes" | ||
|
||
export class AuthPage { | ||
readonly page: Page | ||
// Login | ||
readonly loginRoute: string | ||
readonly loginHeader: Locator | ||
// Register | ||
readonly registerRoute: string | ||
readonly registerHeader: Locator | ||
readonly registerLink: Locator | ||
readonly registerButton: Locator | ||
// Shared Components | ||
readonly emailLabel: Locator | ||
readonly passwordLabel: Locator | ||
|
||
constructor(page: Page) { | ||
this.page = page | ||
// Login | ||
this.loginRoute = orgSlug + Routes.Login | ||
this.loginHeader = page.getByText("Login").first() | ||
// Register | ||
this.registerRoute = orgSlug + Routes.Register | ||
this.registerHeader = page.getByText("Register").first() | ||
this.registerLink = page.getByRole("link", { name: "Register" }) | ||
this.registerButton = page.getByRole("button", { name: "Register" }) | ||
// Shared Components | ||
this.emailLabel = page.getByLabel("Email") | ||
this.passwordLabel = page.getByLabel("Password") | ||
} | ||
|
||
async gotoLogin() { | ||
await Promise.all([ | ||
this.page.goto(this.loginRoute), | ||
await this.page.waitForURL(this.loginRoute), | ||
await expect(this.loginHeader).toBeVisible(), | ||
]) | ||
} | ||
|
||
async gotoRegisterWithLink() { | ||
await Promise.all([ | ||
/* | ||
(wshel) Directly visiting register page will redirect the user to the login page. | ||
We must by click the register button on the login page. | ||
*/ | ||
await this.gotoLogin(), | ||
await this.registerLink.first().click(), | ||
await this.page.waitForURL(this.registerRoute), | ||
await expect(this.registerHeader).toBeVisible(), | ||
]) | ||
} | ||
|
||
async registerNewUser(email: string, password: string) { | ||
await this.gotoRegisterWithLink() | ||
await this.emailLabel.first().click() | ||
await this.emailLabel.fill(email) | ||
|
||
await this.passwordLabel.first().click() | ||
await this.passwordLabel.fill(password) | ||
|
||
await Promise.all([ | ||
this.registerButton.click(), | ||
this.page.waitForURL(orgSlug + Routes.Dashboards), | ||
]) | ||
} | ||
|
||
async pageObjectModel(email: string, password: string) { | ||
await this.registerNewUser(email, password) | ||
} | ||
} |
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,38 @@ | ||
import { Locator, Page } from "@playwright/test" | ||
import { Routes, orgSlug } from "../routes" | ||
|
||
export class IncidentsPage { | ||
readonly page: Page | ||
readonly route: string | ||
|
||
readonly SaveButton: Locator | ||
readonly CloseButton: Locator | ||
|
||
readonly CostsTab: Locator | ||
readonly CostsAmount: Locator | ||
|
||
constructor(page: Page) { | ||
this.page = page | ||
this.route = orgSlug + Routes.Incidents | ||
|
||
this.SaveButton = page.getByRole("button").filter({ hasText: "save" }) | ||
this.CloseButton = page.getByRole("button", { name: "Close" }) | ||
|
||
this.CostsTab = page.getByRole("tab", { name: "Costs" }) | ||
this.CostsAmount = page.getByLabel("Amount") | ||
} | ||
|
||
async goto(incident: string) { | ||
await Promise.all([ | ||
this.page.goto(this.route + `/${incident}`), | ||
await this.page.waitForURL(this.route), | ||
]) | ||
} | ||
|
||
async addCost(incident: string) { | ||
await this.goto(incident) | ||
await this.CostsTab.first().click() | ||
await this.CostsAmount.click() | ||
await this.CostsAmount.fill("100000") | ||
} | ||
} |
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,39 @@ | ||
import { expect, Locator, Page } from "@playwright/test" | ||
import { Routes, orgSlug } from "../routes" | ||
|
||
export class IncidentsPage { | ||
readonly page: Page | ||
readonly route: string | ||
readonly Row: Locator | ||
readonly FirstRow: Locator | ||
readonly OtherRow: Locator | ||
readonly NextPage: Locator | ||
readonly EditKebab: Locator | ||
readonly EditMenu: Locator | ||
readonly EditViewEdit: Locator | ||
readonly EditCreateReport: Locator | ||
readonly EditRunWorkflow: Locator | ||
readonly EditDelete: Locator | ||
|
||
constructor(page: Page, incident: string = `dispatch-${orgSlug}-${orgSlug}-2`) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default incident here is a bit fragile to it being present in the table, there's probably a better way. |
||
this.page = page | ||
this.route = orgSlug + Routes.Incidents | ||
this.Row = page.locator("tr") | ||
this.NextPage = page.getByRole("button", { name: "Next page" }) | ||
this.EditKebab = page | ||
.getByRole("row", { | ||
name: incident, | ||
}) | ||
.getByRole("button") | ||
.nth(2) | ||
this.EditMenu = page.getByTestId("incident-table-edit") | ||
this.EditViewEdit = page.getByRole("menuitem", { name: "View / Edit" }) | ||
this.EditCreateReport = page.getByRole("menuitem", { name: "Create Report" }) | ||
this.EditRunWorkflow = page.getByRole("menuitem", { name: "Run Workflow" }) | ||
this.EditDelete = page.getByRole("menuitem", { name: "Delete" }) | ||
} | ||
|
||
async goto() { | ||
await Promise.all([this.page.goto(this.route), await this.page.waitForURL(this.route)]) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to consider a single SOT for these
data-testid
strings as anEnum
that we can use here and in testsPages