Create UI Tests with Xamarin Test Recorder

Create UI Tests with Xamarin Test Recorder


Short introduction

I am not sure if you saw my previous articles about Xamarin Test Cloud but it is worth to see. UI tests for mobile applications are very important (like Unit Tests). I showed how to write UI Tests and how to use REPL console. In this article I would like to show you how to record interaction with UI and create automatic tests.

What do I need to start?

1) Visual Studio Enterprise

2) Xamarin Test Recorder (either for Windows or MAC)


Let’s start

In this article we can use my previous sample available on my GitHub.

For Visual Studio Xamarin Test Recorder is created as extension.


Record your first test

I will show how to use Xamarin Test Recorder with Android app. Remember to disable “Mono Shared Runitime” before building project and creating test:


1) Open “Tests.cs” file. You should see small icon on the left near “TestFixture” attribute:


2) Launch Android emulator:


3) Click the icon and select “Select APK”. It is located in the “bin->debug folder”:


4) You should see that application is launched on the emulator. Now you can start using it as a normal user. Type name of the product and click “Add” button. Look in the Visual Studio – all your steps are recorded:

 public void NewTest()
    app.Tap(x => x.Marked("AddProductButton"));
    app.Tap(x => x.Marked("ProductNameEntry"));
    app.EnterText(x => x.Marked("ProductNameEntry"), "New product");
    app.Tap(x => x.Marked("AddProductButton"));
    app.ClearText(x => x.Marked("ProductNameEntry"));
    app.Tap(x => x.Text("Not bought").Index(1));



Sum up

As you can see creating UI Tests with Xamarin Test Recorder is really simple. If you would like to create tests for iOS you need to connect Build Agent (requires MAC machine). Remember also that Test Recorder is still in preview (or was during creation of this article) so some functionality can work not always properly. It is also available for macOS.