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.
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 username = d.textFormField(_usernameFinder);
late final password = d.textFormField(_passwordFinder);
late final loginButton = d.navButton(_loginButtonFinder, HomePageObject.new);
LoginPageObject(WidgetTester t) : super(t, _finder);
}
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.username.enterText('username');
await loginPage.password.enterText('password');
await t.pump();
final homePage = await loginPage.loginButton.tapNavAndSettle();
expect(homePage, findsOne);
expect(homePage.greetingText, findsOne);
});
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/CupertinoButton/FloatingActionButton. - CheckboxPageObject - For checkbox widgets such as
Checkbox/CheckboxListTile/CupertinoCheckbox. - ChipPageObject - For chip widgets such as
ChoiceChip/InputChip/FilterChip/RawChip. - DrawerPageObject - For
Drawerwidget. - DropdownPageObject - For dropdown widgets such as
DropdownButton/DropdownButtonFormField. - ImagePageObject - For
Imagewidget. - NavButtonPageObject - For button widgets which navigate to another route.
- ProgressIndicatorPageObject - For
ProgressIndicatorwidget. - RadioGroupPageObject - For radio group.
- RadioPageObject - For radio widgets such as
Radio/RadioListTile/CupertinoRadio. - 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. - SnackBarPageObject - For
SnackBarwidget. - SwitchPageObject - For switch widgets such as
Switch/SwitchListTile/CupertinoSwitch. - TabBarPageObject - For
TabBarwidget. - TextFieldPageObject - For
TextFieldwidget. - TextFormFieldPageObject - For
TextFormFieldwidget. - TextPageObject - For
Text/RichTextwidget. - TristateCheckboxPageObject - For checkbox widgets which are in tristate mode such as
Checkbox/CheckboxListTile/CupertinoCheckbox. TypedTextFieldPageObject- ForTextFieldwidgets whose text can be parsed into a typed value.TypedTextFormFieldPageObject- ForTextFormFieldwidgets whose text can be parsed into a typed value.TypedTextPageObject- ForText/RichTextwidgets whose text can be parsed into a typed value.- 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.