Page class abstract
A page object representing a specific page in a web application.
Implements the Page Object Pattern by encapsulating page structure, elements, and interactions for a specific page. Helps separate test logic from page implementation details.
Example
class LoginPage extends Page {
LoginPage(Browser browser) : super(browser);
@override
String get url => '/login';
// Page elements
String get emailInput => 'input[name="email"]';
String get passwordInput => 'input[name="password"]';
String get submitButton => 'button[type="submit"]';
// Page interactions
Future<void> login({required String email, required String password}) async {
await browser.type(emailInput, email);
await browser.type(passwordInput, password);
await browser.click(submitButton);
}
// Page assertions
Future<void> assertHasError(String message) async {
await browser.assertSeeIn('.error-message', message);
}
}
Usage in Tests
void main() {
browserTest('user can log in', (browser) async {
final loginPage = LoginPage(browser);
await loginPage.navigate();
await loginPage.login(
email: 'user@example.com',
password: 'password123',
);
// Assert we're redirected to dashboard
await DashboardPage(browser).assertOnPage();
});
}
Properties
Methods
-
assertOnPage(
) → Future< void> - Asserts that the browser is currently on this page.
-
clickButton(
String selector) → FutureOr< void> - Clicks a button element.
-
fillField(
String selector, String value) → FutureOr< void> - Fills a form field with the specified value.
- Navigates to this page's URL.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
waitForLoad(
{Duration? timeout}) → FutureOr< void> - Waits for the page to fully load.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited