UI Testing with Xamarin Test Cloud


As you may or may not know, Xamarin has released version 1.0
of Xamarin Test Cloud. With that on top of the 60 min a month base Xamarin
gives you to test how your app looks on more than 1,700 devices spanning
android and iOS tablets and phones. This intrigued me, so I decided I wanted to
learn more about how to integrate TC into my projects.

As luck would have it, I have just the demo app I want to
try it out on: my networking & connectivity talk for Xamarin Dev Days
Madison. (For more info see https://ti.to/xamarin/dev-days-madison)
Unfortunately this project is incomplete, but that’s okay because you can keep
updating your code to match, which is awesome as it is not reliant on you to
keep regenerating new projects or code to keep it up to date. While there are
many ways to get your apps into test cloud and your tests started, I started
out by adding a UITest Project to my app in Xamarin Studio. 

You can add it

  1. In iOS Ctrl + Click on the solution of the app
    you wish to add the UITest to > Add > Add New Project
  2. From here a window pops up asking you to choose
    a new project. Click on “Tests” in the Cross-Platform Section.
  3. If it is not already Click on UITest Project in
    Xamarin Test Cloud.
  4. Click Next to continue
  5. Name your project and click continue. I like to
    follow the format of appname.platform. so in this case, it would be

Now that we have our UITest Project created, we can start getting it set up. There are 2 main files in a new UITest Project Solution, Tests.cs and AppInitializer.cs. The AppInitializer Helps the UITest & Test Cloud find the apk and the ipa for your app for its respective platforms to be run. You can configure it by entering in
.AppBundle (“../../../iOS/bin/iPhoneSumulator/debug/XamarinForms.iOS.app”) ” as an example for iOS. You may have to edit the path to match your environment and avoid and issues along the way and allowing your project to be seen and built. The Test.cs is where the UITests will be stored and run.

You can test for many things in your code from simply “How does it look” to walking through every strep a user would take while using the app. While I recommend looking at the API for the full list of functionality that you can do with UITesting, You can use it to check more complex things like Scrolling Strategy, Change the GPS of the device to simulate physical movement happening, and even the ability to query certain view elements to make a match.

Once your test is built and to your liking, you are ready to move on to getting it deployed to test cloud. For this blog post, I chose to use Xamarin Studio on iOS and deploy to Xamarin test cloud with an iOS app to test with. However if you are more comfortable in the command line, you can deploy it to test cloud from there. You can also deploy to Test Cloud via Calabash which runs in ruby. They both have their own ways to write tests and push code, so use what you are most comfortable with.

To deploy to Test Cloud from Xamarin Studio, you must first must go into the Unit Tests tab on the right hand side of Xamarin Studio. If you do not see it there, you can get to it from the top navigation menu of OSX and go to View -> Sketch (also found by View->Pads->Unit Tests). Once you are there, Ctrl + Click on Test Apps (You can find it by looking for a blue circle with the play symbol inside of it) and choose “Add App Project”. You should see a window pop up that has a list of your projects on it. This shows a list of all compatible project types. Select the projects you wish to deploy to test cloud. (In this case it would be only iOS as that is what I am doing in the demo, however checking both or just android will not affect your results. Once you have selected the projects you wish to run, click okay and you will see that the projects are now listed with info about what target, os, device type it is set to.

Once your project is added to the test list, you can Ctrl + Click on your UI test project (if you are following my naming convention form earlier you would be looking for the one that is .UITest) and chose deploy to test cloud. If you have not already done so, you may want to go to the test cloud site and get your app set up.

NOTE: This is where I got stuck and had to do some research. When I would try to build, it kept failing saying that it could not find my .ipa file. Make sure you Xamarin Studio is set to Debug (nothing after it) and navigate to your [iOS Proj]/Bin/Debug/ folder and look to see if it was there. If not you have to do a build to get it to work. With me, I had done a build but it named the project LoginWithMasterDetailiOS.10.ipa making XS not able to find it. Once you have successfully built the ios app. rename the .ipa file to not have that 10 in the name and you should successfully build.

And that’s it. The rest is rather strait forward, following the steps, choosing what devices and waiting for it to run. Happy Testing!

Unleash Your Inner UI Monkey with Xamarin Test Cloud

For those of you who have not yet heard, all Xamarin Subscriptions
Include Xamarin Test Cloud Device Minutes. This is awesome as any android developer
will know, it’s hard to know what your app will look like when your device
looks proper on all the Android devices in existence (currently there are over
7,000) combine that with all the windows, and ios devices,  it’s hard to know how your app will turn out
looking UI wise.

Now you might be saying “But Mitch, I use <insert one of
the many UI testing services here>, I don’t want to use Xamarin test cloud.”
And you are in your own right to use whatever
service you want, but here are some reasons you would want to.

You already have time paid for

Xamarin Test Cloud is an awesome product that
the Xamarin team has been hard at work to develop.

If you use Calabash or Xamarin UI Test, You are
not getting the full range of devices unless you own them that you could be
with Xamarin Test Cloud.

A lot of the services out there are mostly for
Phone Gap app UI Testing.

You can test Xamarin, iOS, & Android apps

I could blab on more about test cloud, but why not try it out
for yourself!  https://xamarin.com/test-cloud