Post on 06-Apr-2017
transcript
Xamarin UI Test And
Xamarin Test Cloud
Gavin Bryan (Freelance Certified Xamarin Developer)
Overview
• Xamarin UI Test• How and where Xamarin UI Tests can be run• Xamarin Test Cloud
What is Xamarin UI Test?
• Automation Test Library• Automate mobile device and application• Automated UI Acceptance Tests written in
nunit (2.6.x) to be run against iOS and Android• Can be used on Xamarin Apps, iOS (objective-c
/ Swift Apps) and Native Android Apps• XTC does not support WP or Xamarin Forms
WP
Creating a Xamarin.UITest Project Xamarin Studio has 3 Project Templates1. MultiPlatform
Creating a Xamarin.UITest Project
2. IOS Template
Creating a Xamarin.UITest Project
3. Android Template
Most Simple Test• [Test]• public void MyFirstUITest()• {• var app = ConfigureApp• .Android• .ApkFile("MyApkFile.apk")• .StartApp();• • app.EnterText("NameField", ”John Smith");• app.Tap("SubmitButton");• }
UITest Anatomy
• Uses a client / server communication using http and json.
• Http server runs on the device• Communicates with UI Test Client Agent
Android
• Xamarin Test Cloud Agent Server runs in it’s own separate process
• Process is signed with the same keystore as your application so it can drive it with the Android Automation APIs
iOS
• Due to iOS restrictions on iOS the Xamarin Test Cloud Agent has to be shipped with your app in the bundle
• This allows it to access the iOS automation APIs
• Xamarin Test Cloud Agent nuget needs to be installed
Quick Example
app.Tap (c => c.Marked (”New"));
app.EnterText(c => c.Class("UITextField").Index(0), ”John Smith");
app.Tap (c => c.Marked ("Save"));
nUnit
• Test Fixture• 3 A’s (Arrange / Act / Assert)• Categories• Demo – Create Android / IOS Project
UI Test Workflow
• Write automation tests while developing feature
• Write tests, run locally to validate functionality• Create Test run to run in CI / XTC etc.
UI Test Infrastructure
• Tests rely heavily on queries to locate UI elements
• Different techniques to share test logic between platforms
• Your tests can be cross-platform if you write them in similar manner to cross-platform apps.
Setting UI Elements
• Need a way for UI Test to identify UI Elements• UI Test use different UI element ID on Android
and iOS• Can you just text to identify element, but not a
good practice.
Android IDs
• Generally your normal android:id tag is best identifier.
• e.g. android:id="@+id/submitButton"
• This is then used by UI Test• app.Tap (x => x.Id ("submitButton"))
iOS Element IDs
• UI Element Accessibility Identifier • UI Element Accessibility Label• Can set in XCode Identity Inspector or in Code
Identifying UI Elements
• REPL (read, eval, print, loop)• Android - Dump View Hierarchy for UI
Automator• DEMO 1
UI Test Basics
• IApp – different implementations on Android and iOS
• Use ConfigApp fluent builder to create implementation on each platform
• Lots of methods and properties
Xamarin Test Recorder
• A tool for recording automated user interface tests.
• Can be used on Android and iOS• Android runs as standalone app• iOS embeds a plugin into your app bundle to
run (make this is removed on app submission)• Demo 2
Where Can You Run Your Tests
• Locally (devices or emulators / simulators)• CI environments (TeamCity, VSTS, VSMC,
Jenkins, Bitrise etc.)• Xamarin Test Cloud (XTC)
Command Line
• Run locally :-nunit-console.exe in nuget package Nunit.Runners (2.6.4)
• Send to Test Cloud :-• test-cloud.exe
Find Device Ids
• Android :- adb devices• iOS - xcrun instruments -s devices (ios get local
devices) or Xcode• Demo 3
Xamarin Test Cloud
• Test your app on hundreds of actual devices in the Cloud (2000)
• Select Subset of devices to test on• Very detailed analysis of your app• Upload APK, IPA with UI Test Project• iOS IPA are re-signed by Xamarin using their
own provisioning profiles
XTC
• Xamarin resigns your iOS app with their provisioning profile so they can run on their devices.
Some XTC Analysis
• Screenshots• Memory Usage Profiling• CPU Usage• Test logs• Device logs• Demo 4
Thank You
• Any Questions ?