Mobile application automation testing is a challenging activity when compared to web automation testing. There are a number of factors that influence mobile application automation testing, including platform fragmentation, restrictions imposed by mobile device operating systems and the ever-increasing complexity of modern mobile applications.

Moreover, with the increasing demands from enterprises to deliver high-quality products with fewer resources and in limited time can be a huge challenge for software TCOE’s. Further, enterprises are now more focused on keeping software testing cost under check without compromising on the quality. Considering these challenges, it becomes critical to choose the right testing tools and frameworks to gain predictability, reduce costs and improve quality on variant mobile platforms.

In this blog post, we will explore how to automate mobile application testing on Xamarin Test Cloud Platform.

Xamarin UI Test Overview

It defines the automated UI acceptance testing framework based on calabash, where a software tester can develop and execute scripts in C#. Here, NUnit is the framework that validates the functionality of Android and iOS Apps. Xamarin provides capabilities to test thousands of physical devices, where a software tester can assess most versions and devices.

There are two different types of approaches to proceed with mobile application automation testing:

  • Mobile App project completely developed using Xamarin solution and a Xamarin UI Test project
  • Xamarin UI Test project with an external IPA/APK files.

Xamarin UI Test ProjectNote: Windows does not support iOS Apps for Xamarin UI Test

Pre-Requirements
  • Visual Studio (Latest)
  • N Unit
  • N Unit Adapter for N Unit
  • Android SDK
  • Java Development Kit
  • Xamarin Test Cloud Account

Environment Setup

Before proceeding with the project, we need to setup the environment with the below-mentioned prerequisites. The first step is to download and install Visual Studio. During installation, select mobile development with .NET for Xamarin setup. The following screenshot would be helpful during the installation process.

Summary

Adding New C# Project for UI Tests

  • Select File > New Project
  • From the Visual C# Templates, select the test category and the UI Test App template

C# Project

  • Edit the Test.cs file and develop scripts

Solutions Explorer

  • Here is the code snippet for reference
[java]using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Queries;
using Xamarin.UITest.Android;
namespace SampleTest
{
[TestFixture]
public class Tests
{
AndroidApp app;
[SetUp]
public void BeforeEachTest()
{
app = ConfigureApp
.Android
.ApkFile ("../../../<apk/ipa Path >");
}
[Test]
public void LaunchApp()
{
// Launch the application
app.StartApp();
// Wait / Sleep
System.Threading.Thread.Sleep(10000);
// Capture the screenshot
app.Screenshot("First screen.");
//Input the value
app.EnterText(x => x.Id(“xxxx”),”xxxx”);
// Tap / Click
app.Tap (x => x.Id(“xxxx”));
// Find the objects
app.Repl();
}
}
}[/java]

 

How to find Objects/Elements

The ‘app.Repl();’ function helps in identifying the object ID’s of the mobile application. For example, if you need to find all the objects in the application launch screen, use the following function.

[java]
app.StartApp();
App.Repl();
[/java]

By executing the above code, software testers can launch the app and open Repl window, where all object ids are displayed in the form of a tree structure.

Note: Execute app.Repl(); at the location of capturing the objects.

Run Scripts Locally

  • Ensure that APK file directory path is provided, this is mentioned in the above sample code.
  • Make sure Android device/Emulator is connected to the PC and can be identified by the SDK tool (Default connected device will be in active mode)
  • Make sure that the solution is in the Debug mode
  • Click on Test – > Run -> All Tests

Submitting UI Test to Cloud

Before submitting the UI Test to a cloud, users must have a Xamarin Test Cloud account. Visit Xamarin’s website to create an account.

Create a Team

  • Select ‘Account Settings’ from the drop-down menu present in the upper right-hand corner of the page.
  • Click on ‘Teams & Apps’ in the menu available on the left-hand side of this screen.
  • Click on the ‘New team’ button available at the bottom of the page.
  • Proceed and create a team.
  • Now revert to the Visual Studio IDE and follow the below steps:
  • Change Debug mode to Release mode.
  • Right click on the solution and then tap on build option.
  • Make sure no errors are found in the console output.

Submitting with the command line, all commands should be run from the solution directory itself. Now, navigate to solution directory e.g.

C:\Users\Workspace\Sample\Packages\Xamarin.UITest.Version\tools\test-cloud.exe

Packages

Below is the syntax of the command line:

Test-cloud.exe submit < APK PATH > < TEAM API KEY > — devices = < DEVICES > –assembly-dir=< SOLUTION DIR > –user=< EMAIL >

Note:

  • Team API Key can be found in Xamarin test cloud (Login – > Click on Team -> Show API Key)
  • Device ID – Will be shown in Xamarin test cloud
  • Login to Xamarin Test Cloud
  • Click on New Test Run
  • Select your team
  • Select available devices
  • Proceed further
  • Email – Xamarin account email address

Conclusion

Approaching Xamarin test cloud for mobile application automation testing is completely unique and it is highly recommended when testing is undertaken across multiple platforms in one attempt. This blog was written keeping into consideration software testers, who are new to the Xamarin Test Cloud Platform.

Evoke’s – Software Testing Services

Evoke’s software testing services enable firms to optimize their software application quality and performance. Our quality assurance services are designed to ensure a seamless end-user experience with a greater focus on software performance, automation, and security. Our mature software testing frameworks and processes coupled with our smart testing methodologies help firms to improve their software applications and delight end-users. To know more about our world-class software testing services, contact us via our website or call us at +1 (937) 660-4923.

Author

  Karthik Nomula is passionate about learning and implementing advanced automation testing solutions. His area of expertise includes mobile and web application automation testing. Worked on various testing tools such as Perfecto Mobile (Automation), Selenium, Appium, See Test, and Remote Test Kit.
Please follow and share

Leave a comment