Skip to content
Matisse Hack edited this page Feb 6, 2017 · 6 revisions

This guide will walk you through setting up your project for cross-platform tests using the page object pattern. With minor edits you can also use this pattern for single platform tests.

  1. Create a new test project or open up your existing one

  2. Make sure the Xamarin.UITest NuGet package is fully up to date and the NUnit NuGet package is on version 2.6.4

  3. Install the Xamarin.UITest.POP NuGet package, which will add all the necessary files to your project

    Alternatively, you can manually add the following files to your project (making sure to change the namespaces to match your own):

  4. Remove AppInitializer.cs (if it exists)

  5. Edit AppManager.StartApp so that the calls to ConfigureApp point to the appropriate app binaries

    If your test project is in the same solution as your application project(s), you can skip this step since the IDE will provide the binary location information to UITest directly

    For Android:

    app = ConfigureApp
        .Android
        .ApkFile("path/to/file.apk")
        .StartApp();

    For iOS simulators:

    app = ConfigureApp
        .iOS
        .AppBundle("path/to/file.app")
        .StartApp();

    For iOS devices:

    app = ConfigureApp
        .iOS
        .InstalledApp("com.company.bundleid")
        .StartApp();
  6. Create a folder for your test classes and a folder for your page classes to help keep things organized

  7. Create a page object classes that inherits from BasePage for each page in your app

  8. Make sure that your test fixture classes inherit from BaseTestFixture. Your test fixtures should look like this:

    public class Tests : BaseTestFixture
    {
        public Tests(Platform platform)
            : base(platform)
        {
        }
    
        [Test]
        public void AppLaunches()
        {
            app.Screenshot("First screen.");
        }
    }
  9. Now, from your tests, call methods on the page objects to automate your app. For example:

    [Test]
    public void LogInTest()
    {
        new LogInPage()
            .EnterCredentials("username", "password")
            .ConfirmLogIn();
    
        new HomePage();
    }
Clone this wiki locally