Skip to content

Commit 7c568de

Browse files
committed
Expand POM model
1 parent 66b7d60 commit 7c568de

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

site/e2e/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
export const username = "admin"
33
export const password = "password"
44
export const organization = "acme-crop"
5-
export const email = "admin@coder.com"
5+
export const email = "admin@coder.com"

site/e2e/pom/BasePom.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Page } from "@playwright/test"
2+
3+
export abstract class BasePom {
4+
abstract readonly url: string
5+
6+
protected page: Page
7+
protected baseURL: string | undefined
8+
9+
constructor(baseURL: string | undefined, page: Page) {
10+
this.page = page
11+
this.baseURL = baseURL
12+
}
13+
}

site/e2e/pom/ProjectsPage.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Page } from "@playwright/test"
2+
import { BasePom } from "./BasePom"
3+
4+
export class ProjectsPage extends BasePom {
5+
public get url(): string {
6+
return this.baseURL + "/projects"
7+
}
8+
9+
constructor(baseURL: string | undefined, page: Page) {
10+
super(baseURL, page)
11+
}
12+
}

site/e2e/pom/SignInPage.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Page } from "@playwright/test"
2+
import { BasePom } from "./BasePom"
23

3-
export class SignInPage {
4-
private page: Page
4+
export class SignInPage extends BasePom {
5+
public get url(): string {
6+
return this.baseURL + "/login"
7+
}
58

6-
constructor(page: Page) {
7-
this.page = page
9+
constructor(baseURL: string | undefined, page: Page) {
10+
super(baseURL, page)
811
}
912

1013
async submitBuiltInAuthentication(email: string, password: string): Promise<void> {

site/e2e/tests/login.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { test } from "@playwright/test"
22
import { SignInPage } from "../pom"
33
import { email, password } from "../constants"
4+
import ProjectPage from "../../pages/projects/[organization]/[project]"
45

5-
test("Login takes user to /projects", async ({ page, baseURL }) => {
6+
test("Login takes user to /projects", async ({ baseURL, page }) => {
67
await page.goto(baseURL + "/", { waitUntil: "networkidle" })
78

89
// Log-in with the default credentials we set up in the development server
9-
const signInPage = new SignInPage(page)
10+
const signInPage = new SignInPage(baseURL, page)
1011
await signInPage.submitBuiltInAuthentication(email, password)
1112

12-
await page.waitForNavigation({ url: baseURL + "/projects", waitUntil: "networkidle" })
13+
const projectsPage = new ProjectPage(baseURL, page)
14+
await page.waitForNavigation({ url: projectsPage.url, waitUntil: "networkidle" })
1315

1416
await page.waitForSelector("text=Projects")
1517
})

0 commit comments

Comments
 (0)