flutter_page_object 0.1.0+1
flutter_page_object: ^0.1.0+1 copied to clipboard
Helps to implement the Page Object pattern in a Flutter app.
flutter_page_object
#
Flutter library allowing to write page objects for your application using the PageObject pattern. Using it make your tests easier to write, read and maintain.
Usage #
See example for a complete example.
Your tests will look like this:
testWidgets('form completed and tap login button --> navigates to home page', (t) async {
await t.pumpWidget(const MaterialApp(home: LoginPage()));
final loginPage = LoginPageObject(t);
await loginPage.completeForm();
expect(loginPage.loginButton.isEnabled, isTrue);
final homePage = await loginPage.loginButton.tapNavAndSettle();
expect(homePage, findsOne);
expect(homePage.greetingText, findsOne);
});
While the page object will look like this:
class LoginPageObject extends PageObject {
late final username = d.byKey.stringTextFormField(const Key('username'));
late final password = d.byKey.stringTextFormField(const Key('password'));
late final loginButton =
d.byKey.navButton(const Key('login_button'), HomePageObject(t));
LoginPageObject(WidgetTester t) : super(t, _finder);
Future<void> completeForm() async {
await username.setText('username');
await password.setText('password');
await t.pump();
}
}
Creating your own page object #
You can create your own page object by simply extending the PageObject base class.
Supported page objects #
- BottomNavigationBarPageObject - For
BottomNavigationBarwidget. - ButtonPageObject - For button widgets such as
ElevatedButton/TextButton/IconButton. - CheckboxPageObject - For checkbox widgets such as
Checkbox/CheckboxListTile. - DropdownPageObject - For dropdown widgets such as
DropdownButton/DropdownButtonFormField. - NavButtonPageObject - For button widgets which navigate to another route.
- ProgressIndicatorPageObject - For
ProgressIndicatorwidget. - RadioGroupPageObject - For radio group.
- RadioPageObject - For radio widgets such as
Radio/RadioListTile. - ScrollableListPageObject - For scrollable list widgets such as
ListView/GridView. - ScrollablePageObject - For scrollable widgets such as
SingleChildScrollView/ListView. The is alsoIsScrollablemixin if your page object is scrollable. - SlidablePageObject - For slidable widgets such as
PageView/TabView. There isIsSlidablemixin if your page object is slidable. - SliderPageObject - For
Sliderwidget. - SwitchPageObject - For switch widgets such as
Switch/SwitchListTile. - TabBarPageObject - For
TabBarwidget. - TextFormFieldPageObject - For
TextFormFieldwidget. - TristateCheckboxPageObject - For checkbox widgets which are in tristate mode such as
Checkbox/CheckboxListTile. - WidgetListPageObject - For list of widgets such as
Column/Row. - WidgetPageObject - Generic page object for any widget.
Contribution #
Your contribution is more than welcome, feel free to contact me on any matter.