-
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.
Page Object Model for Playwright tests (#737)
Co-authored-by: benmartin-coforma <[email protected]>
- Loading branch information
1 parent
aadcbf5
commit 6ed7650
Showing
17 changed files
with
435 additions
and
141 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,56 +1,47 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { test, expect } from "../utils/fixtures/base"; | ||
import { currentYear } from "../../seeds/helpers"; | ||
import { | ||
archiveExistingWPs, | ||
firstPeriod, | ||
logInStateUser, | ||
stateAbbreviation, | ||
stateName, | ||
} from "../helpers"; | ||
|
||
// TODO: Unskip | ||
test.skip("State user can create a SAR", async ({ page }) => { | ||
test.skip("State user can create a SAR", async ({ | ||
page, | ||
stateHomePage, | ||
sarDashboard, | ||
}) => { | ||
await archiveExistingWPs(page); | ||
await logInStateUser(page); | ||
|
||
// TODO: Seed WP | ||
|
||
// View SARs | ||
await page.getByRole("button", { name: "Enter SAR online" }).click(); | ||
await expect(page).toHaveURL("/sar/"); | ||
await page.waitForResponse(`**/reports/SAR/${stateAbbreviation}`); | ||
await logInStateUser(page); | ||
await stateHomePage.sarButton.click(); | ||
|
||
// Create SAR | ||
await page | ||
.getByRole("button", { | ||
name: "Add new MFP SAR submission", | ||
}) | ||
.click(); | ||
|
||
const modal = page.getByRole("dialog"); | ||
await expect(modal).toBeVisible(); | ||
await expect(modal).toContainText("Add new MFP SAR submission"); | ||
await expect( | ||
page.getByRole("textbox", { name: "Associated MFP Work Plan" }) | ||
).toHaveValue( | ||
await sarDashboard.isReady(); | ||
await sarDashboard.createButton.click(); | ||
await expect(sarDashboard.modal).toBeVisible(); | ||
await expect(sarDashboard.modal).toContainText("Add new MFP SAR submission"); | ||
await expect(sarDashboard.associatedWP).toHaveValue( | ||
`${stateName} MFP Work Plan ${currentYear} - Period ${firstPeriod}` | ||
); | ||
|
||
await page.getByRole("radio", { name: "No" }).click(); | ||
await page.getByRole("button", { name: "Save" }).click(); | ||
await sarDashboard.createNewSAR(); | ||
|
||
// Confirm created SAR is in table | ||
await expect(page.getByRole("table")).toBeVisible(); | ||
|
||
const row = page | ||
.getByRole("row", { | ||
name: `${stateName} MFP SAR ${currentYear} - Period ${firstPeriod}`, | ||
}) | ||
.first(); | ||
await expect(sarDashboard.firstReport).toBeVisible(); | ||
|
||
const editIcon = row.getByRole("button", { name: "Edit Report" }); | ||
const editIcon = sarDashboard.firstReport.getByRole("button", { | ||
name: "Edit Report", | ||
}); | ||
await expect(editIcon).toBeVisible(); | ||
|
||
const editButton = row.getByRole("button", { name: "Edit", exact: true }); | ||
const editButton = sarDashboard.firstReport.getByRole("button", { | ||
name: "Edit", | ||
exact: true, | ||
}); | ||
await expect(editButton).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,23 @@ | ||
import { mergeTests, test as base } from "@playwright/test"; | ||
import { test as sarTest } from "./sar.ts"; | ||
import { test as wpTest } from "./wp.ts"; | ||
import StateHomePage from "../pageObjects/stateHome.page"; | ||
import AdminHomePage from "../pageObjects/adminHome.page"; | ||
|
||
type CustomFixtures = { | ||
stateHomePage: StateHomePage; | ||
adminHomePage: AdminHomePage; | ||
}; | ||
|
||
export const baseTest = base.extend<CustomFixtures>({ | ||
stateHomePage: async ({ page }, use) => { | ||
await use(new StateHomePage(page)); | ||
}, | ||
adminHomePage: async ({ page }, use) => { | ||
await use(new AdminHomePage(page)); | ||
}, | ||
}); | ||
|
||
export const test = mergeTests(baseTest, sarTest, wpTest); | ||
|
||
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,12 @@ | ||
import { test as base } from "@playwright/test"; | ||
import { SARDashboardPage } from "../pageObjects/sar/sarDashboard.page"; | ||
|
||
type SARFixtures = { | ||
sarDashboard: SARDashboardPage; | ||
}; | ||
|
||
export const test = base.extend<SARFixtures>({ | ||
sarDashboard: async ({ page }, use) => { | ||
await use(new SARDashboardPage(page)); | ||
}, | ||
}); |
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,22 @@ | ||
import { test as base } from "@playwright/test"; | ||
import { WPDashboardPage } from "../pageObjects/wp/wpDashboard.page"; | ||
import { WPGeneralInformationPage } from "../pageObjects/wp/wpGeneral.page"; | ||
import { WPReviewAndSubmitPage } from "../pageObjects/wp/wpReviewAndSubmit.page"; | ||
|
||
type WPFixtures = { | ||
wpDashboard: WPDashboardPage; | ||
wpGeneralInformation: WPGeneralInformationPage; | ||
wpReviewAndSubmit: WPReviewAndSubmitPage; | ||
}; | ||
|
||
export const test = base.extend<WPFixtures>({ | ||
wpDashboard: async ({ page }, use) => { | ||
await use(new WPDashboardPage(page)); | ||
}, | ||
wpGeneralInformation: async ({ page }, use) => { | ||
await use(new WPGeneralInformationPage(page)); | ||
}, | ||
wpReviewAndSubmit: async ({ page }, use) => { | ||
await use(new WPReviewAndSubmitPage(page)); | ||
}, | ||
}); |
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,41 @@ | ||
import { Locator, Page } from "@playwright/test"; | ||
import BasePage from "./base.page"; | ||
|
||
export default class AdminHomePage extends BasePage { | ||
public path = "/"; | ||
|
||
readonly page: Page; | ||
readonly title: Locator; | ||
readonly dropdown: Locator; | ||
|
||
constructor(page: Page) { | ||
super(page); | ||
this.page = page; | ||
this.title = page.getByRole("heading", { | ||
name: "View State/Territory Reports", | ||
}); | ||
this.dropdown = page.getByRole("combobox", { | ||
name: "List of states, including District of Columbia and Puerto Rico", | ||
}); | ||
} | ||
|
||
public async selectWP() { | ||
await this.page.getByRole("radio", { name: "MFP Work Plan" }).click(); | ||
} | ||
|
||
public async selectSAR() { | ||
await this.page | ||
.getByRole("radio", { | ||
name: "MFP Semi-Annual Progress Report (SAR)", | ||
}) | ||
.click(); | ||
} | ||
|
||
public async goToDashboard() { | ||
await this.page | ||
.getByRole("button", { | ||
name: "Go to Report Dashboard", | ||
}) | ||
.click(); | ||
} | ||
} |
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,28 @@ | ||
import { expect, Locator, Page } from "@playwright/test"; | ||
|
||
export default class BasePage { | ||
public path = "/"; | ||
|
||
readonly page: Page; | ||
readonly title: Locator; | ||
readonly continueButton: Locator; | ||
readonly previousButton: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.title = page.getByRole("heading", { | ||
name: "Money Follows the Person", | ||
}); | ||
this.continueButton = page.getByRole("button", { name: "Continue" }); | ||
this.previousButton = page.getByRole("button", { name: "Previous" }); | ||
} | ||
|
||
public async goto() { | ||
await this.page.goto(this.path); | ||
} | ||
|
||
public async isReady() { | ||
await this.title.isVisible(); | ||
return expect(this.page).toHaveURL(this.path); | ||
} | ||
} |
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,56 @@ | ||
import { Locator, Page } from "@playwright/test"; | ||
import BasePage from "../base.page"; | ||
import { firstPeriod, stateAbbreviation, stateName } from "../../../helpers"; | ||
import { currentYear } from "../../../../seeds/helpers"; | ||
|
||
export class SARDashboardPage extends BasePage { | ||
public path = "/sar"; | ||
|
||
readonly page: Page; | ||
readonly title: Locator; | ||
readonly createButton: Locator; | ||
readonly modal: Locator; | ||
readonly associatedWP: Locator; | ||
readonly firstReport: Locator; | ||
|
||
constructor(page: Page) { | ||
super(page); | ||
this.page = page; | ||
this.title = this.page.getByRole("heading", { | ||
name: `${stateName} MFP Semi-Annual Progress Report (SAR)`, | ||
}); | ||
this.createButton = this.page.getByRole("button", { | ||
name: "Add new MFP SAR submission", | ||
}); | ||
this.modal = this.page.getByRole("dialog"); | ||
this.associatedWP = this.modal.getByRole("textbox", { | ||
name: "Associated MFP Work Plan", | ||
}); | ||
this.firstReport = this.page | ||
.getByRole("row", { | ||
name: `${stateName} MFP SAR ${currentYear} - Period ${firstPeriod}`, | ||
}) | ||
.first(); | ||
} | ||
|
||
public async reportsReady() { | ||
await this.getReports(); | ||
await this.page.getByRole("rowheader", { name: "Submission name" }); | ||
} | ||
|
||
public async getReports() { | ||
await this.page.waitForResponse( | ||
(response) => | ||
response.url().includes(`/reports/SAR/${stateAbbreviation}`) && | ||
response.status() == 200 | ||
); | ||
} | ||
|
||
public async createNewSAR() { | ||
const noRadio = this.modal.getByRole("radio", { name: "No" }); | ||
const saveButton = this.modal.getByRole("button", { name: "Save" }); | ||
|
||
await noRadio.click(); | ||
await saveButton.click(); | ||
} | ||
} |
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,23 @@ | ||
import { Locator, Page } from "@playwright/test"; | ||
import BasePage from "./base.page"; | ||
|
||
export default class StateHomePage extends BasePage { | ||
public path = "/"; | ||
|
||
readonly page: Page; | ||
readonly title: Locator; | ||
readonly wpButton: Locator; | ||
readonly sarButton: Locator; | ||
|
||
constructor(page: Page) { | ||
super(page); | ||
this.page = page; | ||
this.title = page.getByRole("heading", { | ||
name: "Money Follows the Person (MFP) Portal", | ||
}); | ||
this.wpButton = page.getByRole("button", { | ||
name: "Enter Work Plan online", | ||
}); | ||
this.sarButton = page.getByRole("button", { name: "Enter SAR online" }); | ||
} | ||
} |
Oops, something went wrong.