Skipping intro screens with Xamarin UITest using page objects
A common approach to keep your tests readable and maintainable when writing UITests is to make use of the Page Object Pattern. Now another common approach when onboarding users in apps is to show some introduction screens or have them accept some terms. Now essentially every test should or can be run in any order against a pristine state of the app meaning these screens could show on every test. Although I think this is debatable in the context of acceptance testing it is not the point of this post. Let’s assume you are neatly writing gherkin acceptance criteria, you don’t really want to start every scenario with:
Given I have accepted usage terms And I have read the first time introduction
Although you might have a test covering the appearance of these screens keeping them out of the setup of other tests if preferable since it’s essentially duplication, which stinks.
When using the concept of pages, you do know the order in which pages appear. This is after all part of the design phase and might even be reflected by your iOS story board. For example an standard introduction pages usually preceedes the main page of your app. Another example is that you always get the login page when you start the app in a pristine state before you’re going to the main page (Although here you might wanna have a setup step specifying the user that is logged in). If you then have a step saying: ‘Given I’m on the main page’ you need the following to automatically skip possible preceeding pages:
- Knowing which pages you want to skip automatically, let’s call them Skippable.
- Knowing which Skippable pages preceed which other pages.
- A mechanism that skips Skippable pages when they’re shown in the context of testing the page they preceed.
1. Skippable pages
For skippable pages you need to know how to detect them, and how to actually skip them. For that we can define a simple ISkippable interface:
Example of a disclaimer page a user needs to accept the first time he starts the app:
2. Which ISkippable preceeds what other pages
There’s various options here, but since I wanted to be able to skip pages before constructing the actual Page I chose to create an attribute which can be used to decorate a page.
3. A Page load auto skipping mechanism
For now all my pages need is the actual IApp instance of the UITest Framework. This means I can fairly easy construct pages using an Activator and pass the IApp instance. Using a generic extension method on IApp you get the app instance plus the type of the Page you want to test against.
4. Using it is now simple
Now where ever you need a page you can simply do:
var mainPage = App.WaitForPage<MainPage>();
LEAVE A COMMENT