-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[playwright] feat: Page object examples (#41)
* [playwright] feat: Page object examples
- Loading branch information
1 parent
cb37717
commit 9ca3046
Showing
15 changed files
with
319 additions
and
103 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Page } from '@playwright/test'; | ||
|
||
class LoginPage { | ||
private page: Page; | ||
private defaultTimeout: number = 60 * 1000; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
usernameInput = () => this.page.getByTestId('username'); | ||
passwordInput = () => this.page.getByTestId('password'); | ||
loginButton = () => this.page.getByRole('button', { name: 'Login' }); | ||
signupLink = () => this.page.getByRole('link', { name: 'Sign up' }); | ||
|
||
async goto() { | ||
await this.page.goto('/'); | ||
await this.page.waitForLoadState('domcontentloaded'); | ||
await this.loginButton().waitFor({ timeout: this.defaultTimeout }); | ||
} | ||
|
||
async login(username: string, password: string) { | ||
await this.usernameInput().fill(username); | ||
await this.passwordInput().fill(password); | ||
await this.page.click('button[type=submit]'); | ||
} | ||
} | ||
|
||
export default 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,52 @@ | ||
import { Page } from '@playwright/test'; | ||
|
||
class NotesPage { | ||
private page: Page; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
|
||
spinnerContainer = () => this.page.getByTestId('spinner-container'); | ||
addNewNoteButton = () => | ||
this.page.getByRole('button', { name: 'Add a Note' }); | ||
addNoteTitleInput = () => this.page.getByPlaceholder('Title'); | ||
addNoteContentInput = () => this.page.getByPlaceholder('Content'); | ||
addNoteButton = () => this.page.getByRole('button', { name: 'Add Note' }); | ||
noteTitle = () => this.page.getByTestId('note-title'); | ||
noteContent = () => this.page.getByTestId('note-content'); | ||
deleteNoteButton = () => this.page.getByTestId('note-delete-button'); | ||
note = () => this.page.getByTestId('note'); | ||
saveNoteButton = () => this.page.getByRole('button', { name: 'Save' }); | ||
closeNoteModalButton = () => | ||
this.page.locator('[class*="modal-close"]').first(); | ||
|
||
async goto() { | ||
await this.page.goto('/'); | ||
await this.page.waitForLoadState('domcontentloaded'); | ||
await this.spinnerContainer().waitFor({ | ||
state: 'hidden', | ||
timeout: 60 * 1000, | ||
}); | ||
} | ||
|
||
async addNote(options: { title: string; content: string }) { | ||
await this.addNewNoteButton().click(); | ||
await this.addNoteTitleInput().fill(options.title); | ||
await this.addNoteContentInput().fill(options.content); | ||
await this.addNoteButton().click(); | ||
} | ||
|
||
async deleteNote() { | ||
await this.deleteNoteButton().first().click(); | ||
} | ||
|
||
async editNote(options: { title: string; content: string }) { | ||
await this.note().first().click(); | ||
await this.addNoteTitleInput().fill(options.title); | ||
await this.addNoteContentInput().fill(options.content); | ||
await this.saveNoteButton().click(); | ||
} | ||
} | ||
|
||
export default NotesPage; |
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,61 @@ | ||
import { Page } from '@playwright/test'; | ||
|
||
class RegistrationPage { | ||
/** | ||
* @param {Page} page - Playwright page | ||
*/ | ||
|
||
private page: Page; | ||
private defaultTimeout: number = 60 * 1000; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
} | ||
usernameInput = () => this.page.locator('input[name="username"]'); | ||
emailInput = () => this.page.locator('input[name="email"]'); | ||
passwordInput = () => this.page.locator('input[name="password"]'); | ||
confirmPasswordInput = () => | ||
this.page.locator('input[name="confirmPassword"]'); | ||
registerButton = () => this.page.getByRole('button', { name: 'Register' }); | ||
successMessage = () => | ||
this.page.locator('text="Account created successfully!"'); | ||
accountHeader = () => | ||
this.page.getByRole('heading', { name: 'Register new account' }); | ||
errorMessage = () => this.page.locator('.registration-form-error'); | ||
|
||
goto = async () => { | ||
await this.page.goto('/register'); | ||
await this.page.waitForLoadState('domcontentloaded'); | ||
await this.registerButton().waitFor({ timeout: this.defaultTimeout }); | ||
}; | ||
|
||
/** | ||
* Register a new user | ||
* @param options - Registration options | ||
* @param options.username - Username | ||
* @param options.email - Email | ||
* @param options.password - Password | ||
* @param options.expectFailure - Expect registration to fail | ||
*/ | ||
register = async (options: { | ||
username: string; | ||
email: string; | ||
password: string; | ||
expectFailure?: boolean; | ||
timeout?: number; | ||
}) => { | ||
await this.usernameInput().fill(options.username); | ||
await this.emailInput().fill(options.email); | ||
await this.passwordInput().fill(options.password); | ||
await this.confirmPasswordInput().fill(options.password); | ||
await this.registerButton().click(); | ||
|
||
if (!options.expectFailure) { | ||
await this.successMessage().waitFor({ | ||
timeout: options.timeout || this.defaultTimeout, | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
export default RegistrationPage; |
Oops, something went wrong.
9ca3046
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.
Coverage for this commit
Coverage Report
9ca3046
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.
Coverage for this commit
Coverage Report