-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: e2e test using POM pattern (#33)
feat: e2e test using POM pattern
- Loading branch information
Showing
5 changed files
with
74 additions
and
39 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 |
---|---|---|
@@ -1,27 +1,39 @@ | ||
import { test } from './base-test' | ||
import { test } from './base-test'; | ||
import { HomePage } from './pages/home.page'; | ||
|
||
const { expect } = test | ||
const { expect } = test; | ||
|
||
test('Homepage contains Senarai title', async ({ | ||
page, | ||
queries: { getByRole }, | ||
}) => { | ||
await page.goto('/') | ||
test.describe('Senarai Homepage E2E Test', () => { | ||
let homePage: HomePage; | ||
|
||
// Expect the title to be Senari. | ||
await expect(page).toHaveTitle(/Senarai/) | ||
test.beforeEach(async ({ page }) => { | ||
homePage = new HomePage(page); | ||
await homePage.open(); | ||
await expect(page).toHaveURL('/'); | ||
await expect(page).toHaveTitle(/Senarai/); | ||
}); | ||
|
||
// Locate PAUD text (case insensitive). | ||
const paud = await getByRole('link', { | ||
name: /^paud$/i, | ||
}) | ||
test('user should be able to see all activities', async () => { | ||
await expect(homePage.activityCard).toHaveText([ | ||
`Senarai`, | ||
`PAUD`, | ||
`PAUD ke atas`, | ||
`SD`, | ||
`SD ke atas`, | ||
`SMP`, | ||
`SMP ke atas`, | ||
`SMA`, | ||
`SMA ke atas`, | ||
`Kuliah`, | ||
`Profesional`, | ||
`Semua Usia`, | ||
`For Parents`, | ||
]); | ||
}); | ||
|
||
// Expect the attribute "to be strictly equal" to the value. | ||
await expect(paud).toHaveAttribute('href', '/activities/paud') | ||
|
||
// Click the PAUD link. | ||
await paud.click() | ||
|
||
// Expects the new URL to be correct. | ||
await expect(page).toHaveURL('/activities/paud') | ||
}) | ||
test('user should be able to navigate to an activity', async ({ page }) => { | ||
await homePage.goToPaudActivity(); | ||
await expect(page).toHaveURL('/activities/paud'); | ||
await expect(page).toHaveTitle(/Senarai | Aktivitas PAUD/); | ||
}); | ||
}); |
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 { Page, Locator } from '@playwright/test'; | ||
|
||
export class HomePage { | ||
readonly page: Page; | ||
readonly activityCard: Locator; | ||
readonly paudActivity: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.activityCard = page.getByRole('heading'); | ||
this.paudActivity = page.getByRole('link', { | ||
name: /^paud$/i, | ||
}); | ||
} | ||
|
||
async open() { | ||
await this.page.goto('/'); | ||
} | ||
|
||
async goToPaudActivity() { | ||
await this.paudActivity.click(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
a962be0
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.
Successfully deployed to the following URLs:
senarai – ./
senarai-git-main-zainfathoni.vercel.app
senarai-zainfathoni.vercel.app
senarai.vercel.app