flutter_page_object 1.0.0
flutter_page_object: ^1.0.0 copied to clipboard
Helps to implement the Page Object pattern in a Flutter app.
Flutter Page Object Library Example #
This example demonstrates how to use flutter_page_object in your Flutter application tests.
Basic Usage #
Let's take a look on an example of a login page in your app.
You can create a LoginPageObject which will look like this:
class LoginPageObject extends PageObject {
late final usernameTextField = d.byKey.textFormField(const Key('username'));
late final passwordTextField = d.byKey.textFormField(const Key('password'));
late final loginButton = d.byKey
.navButton(const Key('login_button'), targetBuilder: HomePageObject.new);
LoginPageObject(WidgetTester t)
: super(t, find.byKey(const Key('login_page')));
Future<void> completeForm() async {
await usernameTextField.enterText('test_user');
await passwordTextField.enterText('password123');
await t.pump();
}
}
While your tests will look like this:
testWidgets('form completed and tap login button --> navigates to home page', (t) async {
await t.pumpWidget(const App());
final loginPage = LoginPageObject(t);
await loginPage.completeForm();
final homePage = await loginPage.loginButton.tapNavAndSettle();
expect(homePage, findsOne);
});