Skip to content

Latest commit

 

History

History
122 lines (101 loc) · 4.39 KB

exercise4.md

File metadata and controls

122 lines (101 loc) · 4.39 KB

Automated Testing using Xamarin Test Cloud

Learnings

  1. How to sign up for a Xamarin Test Cloud account
  2. Create a coded UI test
  3. Run tests in the cloud
  4. Record an UI test by using Xamarin Test Recorder

Sign up for a free trial of Xamarin Test Cloud

  1. Open Xamarin Website
  2. Choose Products > Xamarin Test Cloud
  3. Click on "Start your free trial" Xamarin Cloud Free Trial
  4. Register
    Xamarin Cloud Free Register

Create a new Test Project in Visual Studio

  1. Open Visual Studio

  2. Open the Hanselman.Forms solution

  3. Add a new Class Library Project called "Hanselman.Tests" Create a Class Library

  4. Rename Class1.cs to Tests.cs

  5. Add NuGet packages
    Important: choose the specified versions: Xamarin.UITest requires NUnit 2.6.3 or higher. Xamarin.UITest is not compatible with NUnit 3.0.

    • Install-Package NUnit -Version 2.6.4
    • Install-Package NUnitTestAdapter -Version 2.0.0
    • Install-Package Xamarin.UITest -Version 1.3.8

    Add NuGet packages

Create your first test

[TestFixture]
public class Tests
{
    private IApp app;

    [SetUp]
    public void BeforeEachTest()
    {
        app = ConfigureApp
            .Android
            .StartApp();
    }

    [Test]
    public void AppLaunches()
    {
        app.Screenshot("First screen.");
    }
}

Create a more advanced test

Detailed functionality can be found at Xamarin.UITest.IApp, e.g.

  • Back
  • Tap / DoubleTap
  • EnterText
  • PressEnter
  • PinchToZoomIn
  • SetOrientationLandscape / SetOrientationPortrait
  • SwipeLeft / SwipeRight
  • Screenshot
[Test]
public void ClickThroughTest()
{
    this.TestMenuItem("About");
    this.TestMenuItem("Blog");
    this.TestMenuItem("Twitter");
    this.TestMenuItem("Hanselminutes");
    this.TestMenuItem("Ratchet");
    this.TestMenuItem("Developers Life");
}

private void TestMenuItem(string name)
{
    app.WaitForElement(x => x.Marked("OK"));
    app.Tap(x => x.Marked("OK"));

    app.WaitForElement(x => x.Marked(name));
    app.Tap(x => x.Text(name));

    app.Screenshot(name);
}

Run tests

  1. Make a release build of the app
  2. Create an .apk file
    Create an apk file
  3. Publish to Xamarin Test Cloud
    Publish to Xamarin Test Cloud
  4. Select target devices for the test (Note: Using the trial edition restricts the amount of parallel tested devices to 3.) Device selection

Record tests using Test Recorder

Important: This feature is only available in Visual Studio Enterprise edition. Explain the idea or show the following steps live.

  1. Install the Xamarin Test Recorder through Visual Studio > Tools > Extensions and Updates
  2. Open the properties of your Hanselman.Android project and disable Use Shared Runtime
    Use shared runtime
  3. Open the Tests.cs class from your UI test project
  4. Click on the Test Recorder icon and select Record new test > Build Hanselman.Android project
    Test Recorder
  5. The app is started in the emulator, wait until it is loaded completely.
  6. Click through several pages in the app, you will see the recorded actions live in Visual Studio
  7. Go to Visual Studio to stop the current test case.
    Stop Test Recorder

Relevant Links: