0 Comments
 

Zurich Xamarin User Group Logo

I had a great time on Thursday the 15. September 2016 at the Xamarin User Group in Zurich. Though having a little struggle with the latest updates which seemed to have a “minor” impact on my UI Tests to run on Windows i.e. Visual Studio I had a great time presenting and some interesting questions to chew on during answering.

Image of my talk at our great location at the impact hub.

After the Meetup there was the typical Pizza, Sweets, Beer, Water discussions that always spawn some new insights on topics. I want to thank all those who came to the talk and I’m looking forward hopefully seeing you dear reader at one of the upcoming Xamarin Meetups in Zurich.

Image of a Pizza - which made me hungry while just looking at it... well done to past-mark...

Plus I am thrilled to announce that I’m now a Co-Organizer of the Meetup together with Thomas Charrière and Reto Senn. So if you have any topics you would like to present or see presented be sure to reach out to me via  Twitter or just write a comment down bellow. If you simply wish to support our effort by providing some beverages do neither hesitate to contact me or one of my co-organizers Winking smile

Talk Content

You can find my slides here and the code on GitHub.

0 Comments
 

I recently wrote a UI test for an app which displayed a CSS ID which included a colon. The UI tree from the REPL looked like this:

Googling did bring me closer to a possible solution by suggesting to escape the colon with a backslash, which ended in the following output:

So no luck, before going into any detail here is how to solve the issue:

iOS

Android

The reason why the colon has to be escaped that many times is because the string will be passed through multiple runtimes. Each will be interpreting and escaping the string anew. The differing count is due to how Xamarin UI Tests have to handle the platforms.

Reference

Many thanks to Tobias Røikjer from the Xamarin UI Testing team for pointing out how to solve this problem.

0 Comments
 

Blog title image showing github octocat and Visual Studio Logo

During this post I assume you are already familiar with GitHub. Visual Studio Team Services (VSTS) is a cloud hosted service which focuses on DevOps centric teams. You can use the integrated Git repository if you are looking for a private repository. But in case the project is already hosted on GitHub or it is an open source project. VSTS can act as a build server which supports 3rd party hosted repository. The path for integrating GitHub is one of the best predefined paths a thereby is one of those services. But it is that comes with a great support for integration.

VSTS is not a tool which is focused on a single task. It is rather a tool trying to deliver a common platform to support Teams that are living a DevOps mentality. Per default VSTS provides teams with a default tool set for source code management, build and testing. Plugins allow to bind in different tools for a certain task at hand e.g. versioning control. These plugins or external service endpoints allow to integrate GitHub as VCS with ease. I'll assume you meet the following preconditions:

  • Have a VSTS account
    • You can create your free account here.
  • Have a VSTS Project
  • Have a GitHub account
  • (Have the code repository pushed to GitHub)

Open the projects dashboard and then open the settings menu. In the Control panel of your project open the tab Services:

Tabs in the VSTS project control panel with services selected.

Then add a new service endpoint and select GitHub:

Adding a new service endpoint which includes a GitHub option.

In the following dialog give the connection a name I.e. GitHub. Note that if you are already logged in to GitHub with an account, this account will be used to make the connection. If you want to use another account. Try using the private mode of your browser while performing these steps.

Dialog for configuring the external GitHub service, simply select Authorize to proceed.

After tapping on Authorize your VSTS will be connected to your GitHub account. When configuring the build configuration for a project. It now is possible to select GitHub as the repository type I.e. select a repository hosted on GitHub.

Screen shot showing the repository tab in a build config which allows selecting GitHub as repository type.

Conclusion

In this post we saw how we can add GitHub as an external service to a VSTS project. After adding GitHub as a service. It is possible to select a GitHub repository within a build configuration. So you can now build source code from GitHub via VSTS. The integration at the time of writing is still limited to only the build process. It currently is not possible to reference code from GitHub in the planning part. Or see the repository in the code part of the VSTS web dashboard.

0 Comments
 

image

In this post we will look at how we can write UI tests for a Xamarin.Android app. The app which we are testing is a basic app based on the MVVM pattern. You can find a detailed blog post on the in and outs of the app under test here.

Assuming you already have a Xamarin Test Cloud (XTC) project added to your solution. As described in this former post. Lets get started by preparing the app for UI testing.

Enabling your Android app for the XTC tests

You do not have to do anything to enable your app to be compatible with XTC. That being said when writing a test with Xamarin Test Cloud. The test should not recognize a control by the content it is displaying. Rather it identifies a control via an ID which is not visible to the end user but rather a invisible ID. Setting this ID is best done via the accessibility label attribute. You can set this in the AXML code of your view i.e. control:

This ID will not have to change if the locale changes. Even if the location of the UI element changes it will still be found by the test. Thus IDs should be generally used to identify controls as they allow for higher resilient test code.

Writing Test(s)

After tuning our the UI code we can start writing the test. One way is to use the XTC recorder. While this tool brings a great benefit when starting off with or smaller apps (as it would be the case in this post). I usually prefer to use the REPL which is easy to use and can be invoked at any point in the test code.

When the UI is prepared accordingly we can start writing the test. One way is to use the XTC recorder. While this tool brings a great benefit when starting of with or smaller apps (as it would be the case in this post), I usually prefer to use the REPL which is easy to use and can be inserted to be started at any point in your code.

The REPL is especially useful once you have a large testing framework. Having a framework i.e. helpers in place you can run those before firing up the REPL. So you can start exploring and interacting with the UI right were you need to.

XtcTreeWithIds_thumb

Starting the REPL is as easy as adding the following line to your test method:

You can see the entire apps visual tree outlined.

Now we can define the steps we want to perform in our test:

Note how the test takes screenshots at every stage. This allows to easily identify the steps on the Xamarin test cloud and give them a label. While this might seem to be a bit of an overkill for such a small sample. When writing larger tests naming your steps i.e. screen shots will help you narrowing down where an error is happening.
One good thing about the tests is that they also run well on your local machine. So using e.g. the al Studio we can execute the tests over the NUnit Runner:

shows resharper testrunner in visual studio after executing a test

You can choose to run the tests on an emulator or device as you like. Just select the desired target as you would when starting the application. Or submit it to the test cloud i.e. integrate it in our build process.

Conclusion

This post described how to get started writing automated UI tests with Xamarin Test Cloud for a Xamarin.Android. Showing you how to adopt your UI for writing resilient test. Based on NUnit the tests are running on a stable and battle proven foundation.

Keep in mind that UI tests should not be the only testing you rely on for testing your app. But in combination with Unit and Integration tests they can provide great value to your project. Running them on Xamarin Test Cloud allows you to run them on a sea of devices. Along with different versions of Android i.e. vendor flavours.

You can find the entire sample on GitHub.

0 Comments
 

Title image showing the xamarin test cloud and ios logo

In this post we will look at how we can test a Xamarin.iOS app which is based on a storyboard. The app which we are testing is a basic app based on the MVVM pattern. You can find a detailed blog post on the in and outs of the app under test here.

Assuming you already have a Xamarin Test Cloud (XTC) project added to your solution as described in this former post. Lets get started by preparing the app to be tested.

Preparing the iOS for the XTC tests

When writing a test with Xamarin Test Cloud the test ideally does not recognize a control by the content it is displaying but rather via an ID which is not visible to the end user but rather a invisible ID. Setting this ID is best done via the accessibility label attribute which can be set in the storyboard under properties:

Shows where under properties the label can be enabled.

This ID will not have to change if the locale changes or the UI element is moved to a different location and therefore will allow you to write more resilient test code.

Writing Test(s)

When the UI is prepared accordingly we can start writing the test. One way is to use the XTC recorder. While this tool brings a great benefit when starting of with or smaller apps (as it would be the case in this post), I usually prefer to use the REPL which is easy to use and can be inserted to be started at any point in your code.

The REPL is especially useful once you have a substantial testing framework written because it allows you to execute it after executing some prearranged steps to get to a certain point which you would like to test.

Shows repl output of the app

Starting the REPL is as easy as adding the following line to your test method:

You can see the entire apps visual tree nicely outlined.

Now we can define the steps we want to perform in our test:

Note how the test takes screenshots at every stage. This allows to easily identify the steps on the Xamarin test cloud and give them a label. While this might be a bit overkill for such a small sample on larger tests when named right the steps and screen shots will greatly help you narrowing down where an error is happening.
One good thing about the tests is that they also run well on your local machine. So using Xamarin Studio on a Mac we can simply execute the tests over the NUnit Runner:

image showing the nunit test runner of xamarin studio.

Or submit it to the test cloud i.e. integrate it in our build process.

Conclusion

This post described how to get started writing automated UI tests with Xamarin Test Cloud for a Xamarin.iOS application. After some minor adjustments to the UI a test can be written using the familiar NUnit testing framework. Keeping in mind that UI tests should not be the only testing you apply to your app since they are rather slow, they do bring a lot of value when used properly since one can easily run the tests on different devices and iOS versions with the Xamarin Test Cloud.

You can find the entire sample on GitHub.