Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

UI Testing Guidelines

DeanFaizal edited this page Mar 4, 2019 · 4 revisions

Page Object Pattern

UI Testing is implemented using the Page Object Pattern (POP) where each page corresponds to a Page class in the UITest Project.

Nuget: https://www.nuget.org/packages/Xamarin.UITest.POP

Sample: https://github.com/xamarin-automation-service/uitest-pop-example

Best practices and tips: https://blog.xamarin.com/best-practices-tips-xamarin-uitest/

Channel 9 Video for best practices and tips: https://channel9.msdn.com/Shows/XamarinShow/Best-Practices-for-User-Interface-Automation

Example flow for adding a UI Test

Let's go through the steps for adding a UITest to toggle a Switch Element on a page named HomePage as an example:

  1. Add a UI Test project to your solution
  2. Add the POP Nuget package referenced above to the project
  3. Add AutomationId values for Elements in the page to be tested and for the page itself. In this case: AutomationId="HomePage" on the main Grid, and AutomationId="LightModeSwitch" on the Switch
  4. Create the page class for the page to be tested. Eg: HomePage.cs inheriting from BasePage. Override the abstract trait property with a PlatformQuery the name of the page on each platform:
    protected override PlatformQuery Trait => new PlatformQuery
    {
        Android = x => x.Marked(nameof(HomePage)),
        iOS = x => x.Marked(nameof(HomePage))
    };
  1. Create a using alias directive for query like so:
    using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
  1. Add the query for the Switch in the constructor
    public HomePage()
    {
        LightModeSwitch = x => x.Marked(nameof(LightModeSwitch));
    }
  1. Create the method for a simple UI operation
    public void SetLightMode()
    {
        app.WaitForElement(LightModeSwitch);
        app.Tap(LightModeSwitch);
        app.Screenshot("Toggled light mode");
    }
  1. Add a Tests.cs class that inherits from BaseTestFixture and add the Test Fixture
    [Test]
    public void SetLightMode()
    {
        new HomePage()
            .SetLightMode();
    }
  1. Go to View > Test in Visual Studio and Run the UI Test

MobCAT Framework

Beyond the MobCAT Framework

Clone this wiki locally