flutter_page_object 0.2.0 copy "flutter_page_object: ^0.2.0" to clipboard
flutter_page_object: ^0.2.0 copied to clipboard

Helps to implement the Page Object pattern in a Flutter app.

flutter_page_object codecov #

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 BottomNavigationBar widget.
  • 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 Drawer widget.
  • DropdownPageObject - For dropdown widgets such as DropdownButton / DropdownButtonFormField.
  • ImagePageObject - For Image widget.
  • NavButtonPageObject - For button widgets which navigate to another route.
  • ProgressIndicatorPageObject - For ProgressIndicator widget.
  • 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 also IsScrollable mixin if your page object is scrollable.
  • SlidablePageObject - For slidable widgets such as PageView / TabView. There is IsSlidable mixin if your page object is slidable.
  • SliderPageObject - For Slider widget.
  • SnackBarPageObject - For SnackBar widget.
  • SwitchPageObject - For switch widgets such as Switch / SwitchListTile / CupertinoSwitch.
  • TabBarPageObject - For TabBar widget.
  • TextFieldPageObject - For TextField widget.
  • TextFormFieldPageObject - For TextFormField widget.
  • TextPageObject - For Text / RichText widget.
  • TristateCheckboxPageObject - For checkbox widgets which are in tristate mode such as Checkbox / CheckboxListTile / CupertinoCheckbox.
  • TextFieldPageObject - For TextField widgets whose text can be parsed into a typed value.
  • TypedTextFormFieldPageObject - For TextFormField widgets whose text can be parsed into a typed value.
  • TypedTextPageObject - For Text / RichText widgets 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.

1
likes
0
points
645
downloads

Publisher

unverified uploader

Weekly Downloads

Helps to implement the Page Object pattern in a Flutter app.

Repository (GitHub)
View/report issues

Topics

#page-object #testing #test-automation

License

unknown (license)

Dependencies

flutter, flutter_test

More

Packages that depend on flutter_page_object