flutter_page_object 0.0.9 copy "flutter_page_object: ^0.0.9" to clipboard
flutter_page_object: ^0.0.9 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.

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 BottomNavigationBar widget.
  • 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 ProgressIndicator widget.
  • 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 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.
  • SwitchPageObject - For switch widgets such as Switch / SwitchListTile.
  • TabBarPageObject - For TabBar widget. - TextFormFieldPageObject - For TextFormField widget.
  • 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.

1
likes
0
points
669
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