SlideShare a Scribd company logo
1 of 23
#XamExpertDay
UI Testing with
Xamarin.Forms
Codrina Merigo
_Codrina_
WHY
Unit Tests are normally written by the developers who write test code
to verify the functionalities that were developed by them.
Picture credits : https://mobilefirstcloudfirst.net/wp-content/uploads/2017/01/Test-Pyramid-1024x806.png
UI Tests This is the layer where you would be testing
the product more from an end-user’s perspective.
Your top priority would be to ensure that ‘UI Design Flow’
is in-line with the design requirements.
App Testing
Since the testing at UI level is so brittle, it is recommended to focus on these
tests to only verify ‘UI flow & interactions’ without looking into the system functionality.
Service Tests helps you ensure that the services
are working properly and give you the right data.
Fast (ui tests are slow but dev must try not to write
them even slower)
Independent(not use other tests)
Repeatable (not use constants like access tokens)
Self-validating(by using asserts)
Timely ( try not to be very complicated, maybe an
action can be split in multiple tests).
F.I.R.S.T. Principles
UI Test Project
if (platform == Platform.Android)
{
return ConfigureApp.Android
.EnableLocalScreenshots()
.DeviceSerial(DroidDeviceID)
.Debug()
.ApkFile(ApkPath)
.StartApp();
}
else
return ConfigureApp.iOS
.EnableLocalScreenshots()
.Debug()
.DeviceIdentifier(IOSDeviceID)
.AppBundle(AppPath)
.StartApp();
To find the ios device id run instruments -s devices on your mac,
for android launch adb devices from command line
ApkPath is something like "C:UsersProjectsMyAppMyApp.AndroidbinDebugmyApp.apk"
AppAPath for the ipa is something like ="../../../MyApp/MyApp.iOS/bin/iPhoneSimulator/Debug/MyApp.iOS.app"
Repl() - read-eval-print-loop
The REPL is a console-like environment in which the developer enters expressions or commands.
It will then evaluate those expressions and display the results to the user.
The REPL is helpful when creating UITests as it allows us to explore the user interface
and create the queries and statements so that the test may interact with the application.
tree
app.Query(e =>
e.All())
DEMO
Sample
Arrange, Act, Assert
public int MySum(int a, int b)
{
return a + b;
}
[Test]
public void TestMySum()
{
// Arrange
int a = 5;
int b = 7;
// Act
int result = MySum(a, b);
// Assert
Assert.AreEqual(12, result);
}
AAA Pattern
This process allows you to write tests a non-technical language that everyone can
understand (e.g. a domain-specific language like Gherkin).
BDD forms an approach for building a shared understanding on what kind of software
to build by discussing examples.
Behavior Driven Development
BDD Approach
Given When Then
As a [role]
I want [feature]
So that [benefit]
As a registered user,
I want to be able to login,
so that I can see the Application.
Scenario 1: User is able to log in.
Given that I am a registered user,
when I enter the username ‘Codrina’
and password ‘ladybug’,
then I should see
the first screen of the app.
Sample
In order to identify a control on the screen, each control needs an unique identifier called
AutomationId set to the visual element, for example:
<Label x:Name="label1" AutomationId="MyLabel" Text="Hello, Xamarin.Forms!" />
Or
var label1 = new Label {
Text = "Hello, Xamarin.Forms!",
AutomationId = "MyLabel"
};
AutomationId – your new best friend
UI Automation is supposed to run slow in order to emulate an actual user interaction - keep
that in mind that sometimes we may wait for an element to pop on the screen before we verify if
it is actually on the screen.
It’s important also to write every single action and
not take anything for granted
DEMO
Queries inside and outside Repl()
Samples
//label
bool myLabel = app.Query(e => e.Marked(“MyLabel")).Any();
app.Tap(“MyLabel");
//syncfusion element
switches = app.Query(e => e.Marked("SfSwitch Control. State changed"));
x = (float)switches[c].Rect.CenterX;
y = (float)switches[c].Rect.CenterY;
app.TapCoordinates(x, y);
//swipe gestures
app.SwipeLeftToRight();
//entry
app.Tap(“MyEntry");
app.EnterText(Constants.Value);
app.DismissKeyboard();
//inside webview
/*through Safari for iOS
and through Chrome for Android
use the browser developer tools
to visually identify
the elements inside the DOM.*/
app.Tap(c => c.WebView().Css("#element"));
DEMO
Run your tests on App Center Test Cloud
appCenter
Validation
Upload package and UI Test
using nodeJs and following
app center instruction
Wait for
devices
Run on first device when
ready
Run on second device when
ready
Run on nth device when
ready
Configure your run by selecting
Generate report for
results
Run on third device when
ready
App Center Test Cloud Reports
Add Ui Tests to DevOps using AppCenter
From app center you get:
appcenter test run uitest
--app "codrinamerigo/LadyBug"
--devices "codrinamerigo/android-test"
--app-path pathToFile.apk
--test-series "master"
--locale "en_US"
--build-dir pathToUITestBuildDir
Enable task
Add Ui Tests to your TFS
mono ../../../NUnit.Runners.2.6.3/tools/nunit-console.exe
myApp/MyApp.UITest/bin/Debug/
myApp.UITest.dll
-xml=UITestResult.xml
TFS
NUNIT
If sometimes, the iOS simulator doesn’t pop on the screen,
might be useful to delete the xdb folder inside TMPDIR (on the Mac machine) and retry.
For debug purpose, right-click on the iOS Project > Options > Compiler and add the string ENABLE_TEST_CLOUD
Try to write no more that 20 ui tests per project to run them locally…
Open the Android simulator on your Mac before running the tests
Don’t forget about your UI Test – try to keep them live
UI Tests aren't compatible with the Shared Mono Runtime, so remember to disable it for Android!
From myexperience . . .
Q & A
Thank You!
_Codrina_

More Related Content

What's hot

From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.David Aguilera
 
Illia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationIllia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationAnna Shymchenko
 
iOS UI Testing in Xcode
iOS UI Testing in XcodeiOS UI Testing in Xcode
iOS UI Testing in XcodeJz Chang
 
Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Svetlin Nakov
 
Selenium Testing Training in Bangalore
Selenium Testing Training in BangaloreSelenium Testing Training in Bangalore
Selenium Testing Training in Bangalorerajkamal560066
 
Functional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and TestersFunctional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and TestersAurélien Pupier
 
Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012Daniel Knott
 
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasySwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasyAnkit Goel
 
Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Mehdi Khalili
 
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
TestComplete – A Sophisticated Automated Testing Tool by SmartBearTestComplete – A Sophisticated Automated Testing Tool by SmartBear
TestComplete – A Sophisticated Automated Testing Tool by SmartBearSoftware Testing Solution
 
iOS UIAutomation
iOS UIAutomation iOS UIAutomation
iOS UIAutomation Jz Chang
 
Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Sameer Rathoud
 
Refactoring page objects The Screenplay Pattern
Refactoring page objects   The Screenplay Pattern Refactoring page objects   The Screenplay Pattern
Refactoring page objects The Screenplay Pattern RiverGlide
 
How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...kritikumar16
 
Getting started with_testcomplete
Getting started with_testcompleteGetting started with_testcomplete
Getting started with_testcompleteankit.das
 
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and TychoMickael Istria
 

What's hot (20)

From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
 
Illia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationIllia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot application
 
iOS UI Testing in Xcode
iOS UI Testing in XcodeiOS UI Testing in Xcode
iOS UI Testing in Xcode
 
Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021
 
Selenium Testing Training in Bangalore
Selenium Testing Training in BangaloreSelenium Testing Training in Bangalore
Selenium Testing Training in Bangalore
 
Functional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and TestersFunctional Testing made easy with SWTBot for Developers and Testers
Functional Testing made easy with SWTBot for Developers and Testers
 
Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012Mobile App Testing ScanAgile 2012
Mobile App Testing ScanAgile 2012
 
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasySwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
 
Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)Automated UI testing done right (DDDSydney)
Automated UI testing done right (DDDSydney)
 
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
TestComplete – A Sophisticated Automated Testing Tool by SmartBearTestComplete – A Sophisticated Automated Testing Tool by SmartBear
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
 
Given When Then
Given When ThenGiven When Then
Given When Then
 
 xctest
 xctest xctest
 xctest
 
Robotium Tutorial
Robotium TutorialRobotium Tutorial
Robotium Tutorial
 
iOS UIAutomation
iOS UIAutomation iOS UIAutomation
iOS UIAutomation
 
Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)Factory method pattern (Virtual Constructor)
Factory method pattern (Virtual Constructor)
 
Refactoring page objects The Screenplay Pattern
Refactoring page objects   The Screenplay Pattern Refactoring page objects   The Screenplay Pattern
Refactoring page objects The Screenplay Pattern
 
How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...How do i implement command design pattern in the java programming course with...
How do i implement command design pattern in the java programming course with...
 
Android testing part i
Android testing part iAndroid testing part i
Android testing part i
 
Getting started with_testcomplete
Getting started with_testcompleteGetting started with_testcomplete
Getting started with_testcomplete
 
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
 

Similar to Xam expertday

Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
UI Testing for Your Xamarin.Forms Apps
UI Testing for Your Xamarin.Forms AppsUI Testing for Your Xamarin.Forms Apps
UI Testing for Your Xamarin.Forms AppsCodrina Merigo
 
Xamarin Test Cloud - from zero to hero in automated ui testing
Xamarin Test Cloud - from zero to hero in automated ui testingXamarin Test Cloud - from zero to hero in automated ui testing
Xamarin Test Cloud - from zero to hero in automated ui testingGeert van der Cruijsen
 
Alexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extraAlexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extrarit2010
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testingpleeps
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NETPeter Gfader
 
Android UI Testing with Appium
Android UI Testing with AppiumAndroid UI Testing with Appium
Android UI Testing with AppiumLuke Maung
 
Mobile Quality Night Vienna 2015 - Testobject Appium in der Cloud
Mobile Quality Night Vienna 2015 - Testobject Appium in der CloudMobile Quality Night Vienna 2015 - Testobject Appium in der Cloud
Mobile Quality Night Vienna 2015 - Testobject Appium in der CloudRudolf Grötz
 
Android the Agile way
Android the Agile wayAndroid the Agile way
Android the Agile wayAshwin Raghav
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosFlutter Agency
 
Slides for Automation Testing or End to End testing
Slides for Automation Testing or End to End testingSlides for Automation Testing or End to End testing
Slides for Automation Testing or End to End testingSwapnilNarayan
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appiumPratik Patel
 
Different Android Test Automation Frameworks - What Works You the Best?
Different Android Test Automation Frameworks - What Works You the Best?Different Android Test Automation Frameworks - What Works You the Best?
Different Android Test Automation Frameworks - What Works You the Best?Bitbar
 
Espresso workshop
Espresso workshopEspresso workshop
Espresso workshopKetan Soni
 
Cucumber meets iPhone
Cucumber meets iPhoneCucumber meets iPhone
Cucumber meets iPhoneErin Dees
 

Similar to Xam expertday (20)

Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
UI Testing for Your Xamarin.Forms Apps
UI Testing for Your Xamarin.Forms AppsUI Testing for Your Xamarin.Forms Apps
UI Testing for Your Xamarin.Forms Apps
 
Mobile optimization
Mobile optimizationMobile optimization
Mobile optimization
 
Xamarin Test Cloud - from zero to hero in automated ui testing
Xamarin Test Cloud - from zero to hero in automated ui testingXamarin Test Cloud - from zero to hero in automated ui testing
Xamarin Test Cloud - from zero to hero in automated ui testing
 
Alexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extraAlexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extra
 
UI Testing
UI TestingUI Testing
UI Testing
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NET
 
Android UI Testing with Appium
Android UI Testing with AppiumAndroid UI Testing with Appium
Android UI Testing with Appium
 
Mobile Quality Night Vienna 2015 - Testobject Appium in der Cloud
Mobile Quality Night Vienna 2015 - Testobject Appium in der CloudMobile Quality Night Vienna 2015 - Testobject Appium in der Cloud
Mobile Quality Night Vienna 2015 - Testobject Appium in der Cloud
 
Coding Naked 2023
Coding Naked 2023Coding Naked 2023
Coding Naked 2023
 
Android the Agile way
Android the Agile wayAndroid the Agile way
Android the Agile way
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Slides for Automation Testing or End to End testing
Slides for Automation Testing or End to End testingSlides for Automation Testing or End to End testing
Slides for Automation Testing or End to End testing
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
Different Android Test Automation Frameworks - What Works You the Best?
Different Android Test Automation Frameworks - What Works You the Best?Different Android Test Automation Frameworks - What Works You the Best?
Different Android Test Automation Frameworks - What Works You the Best?
 
Coded ui test
Coded ui testCoded ui test
Coded ui test
 
Espresso workshop
Espresso workshopEspresso workshop
Espresso workshop
 
Cucumber meets iPhone
Cucumber meets iPhoneCucumber meets iPhone
Cucumber meets iPhone
 

Recently uploaded

CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 

Recently uploaded (7)

CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 

Xam expertday

  • 3.
  • 4. WHY
  • 5.
  • 6. Unit Tests are normally written by the developers who write test code to verify the functionalities that were developed by them. Picture credits : https://mobilefirstcloudfirst.net/wp-content/uploads/2017/01/Test-Pyramid-1024x806.png UI Tests This is the layer where you would be testing the product more from an end-user’s perspective. Your top priority would be to ensure that ‘UI Design Flow’ is in-line with the design requirements. App Testing Since the testing at UI level is so brittle, it is recommended to focus on these tests to only verify ‘UI flow & interactions’ without looking into the system functionality. Service Tests helps you ensure that the services are working properly and give you the right data.
  • 7. Fast (ui tests are slow but dev must try not to write them even slower) Independent(not use other tests) Repeatable (not use constants like access tokens) Self-validating(by using asserts) Timely ( try not to be very complicated, maybe an action can be split in multiple tests). F.I.R.S.T. Principles
  • 8. UI Test Project if (platform == Platform.Android) { return ConfigureApp.Android .EnableLocalScreenshots() .DeviceSerial(DroidDeviceID) .Debug() .ApkFile(ApkPath) .StartApp(); } else return ConfigureApp.iOS .EnableLocalScreenshots() .Debug() .DeviceIdentifier(IOSDeviceID) .AppBundle(AppPath) .StartApp(); To find the ios device id run instruments -s devices on your mac, for android launch adb devices from command line ApkPath is something like "C:UsersProjectsMyAppMyApp.AndroidbinDebugmyApp.apk" AppAPath for the ipa is something like ="../../../MyApp/MyApp.iOS/bin/iPhoneSimulator/Debug/MyApp.iOS.app"
  • 9. Repl() - read-eval-print-loop The REPL is a console-like environment in which the developer enters expressions or commands. It will then evaluate those expressions and display the results to the user. The REPL is helpful when creating UITests as it allows us to explore the user interface and create the queries and statements so that the test may interact with the application. tree app.Query(e => e.All())
  • 10. DEMO
  • 11. Sample Arrange, Act, Assert public int MySum(int a, int b) { return a + b; } [Test] public void TestMySum() { // Arrange int a = 5; int b = 7; // Act int result = MySum(a, b); // Assert Assert.AreEqual(12, result); } AAA Pattern
  • 12. This process allows you to write tests a non-technical language that everyone can understand (e.g. a domain-specific language like Gherkin). BDD forms an approach for building a shared understanding on what kind of software to build by discussing examples. Behavior Driven Development BDD Approach Given When Then As a [role] I want [feature] So that [benefit] As a registered user, I want to be able to login, so that I can see the Application. Scenario 1: User is able to log in. Given that I am a registered user, when I enter the username ‘Codrina’ and password ‘ladybug’, then I should see the first screen of the app. Sample
  • 13. In order to identify a control on the screen, each control needs an unique identifier called AutomationId set to the visual element, for example: <Label x:Name="label1" AutomationId="MyLabel" Text="Hello, Xamarin.Forms!" /> Or var label1 = new Label { Text = "Hello, Xamarin.Forms!", AutomationId = "MyLabel" }; AutomationId – your new best friend UI Automation is supposed to run slow in order to emulate an actual user interaction - keep that in mind that sometimes we may wait for an element to pop on the screen before we verify if it is actually on the screen. It’s important also to write every single action and not take anything for granted
  • 14. DEMO
  • 15. Queries inside and outside Repl() Samples //label bool myLabel = app.Query(e => e.Marked(“MyLabel")).Any(); app.Tap(“MyLabel"); //syncfusion element switches = app.Query(e => e.Marked("SfSwitch Control. State changed")); x = (float)switches[c].Rect.CenterX; y = (float)switches[c].Rect.CenterY; app.TapCoordinates(x, y); //swipe gestures app.SwipeLeftToRight(); //entry app.Tap(“MyEntry"); app.EnterText(Constants.Value); app.DismissKeyboard(); //inside webview /*through Safari for iOS and through Chrome for Android use the browser developer tools to visually identify the elements inside the DOM.*/ app.Tap(c => c.WebView().Css("#element"));
  • 16. DEMO
  • 17. Run your tests on App Center Test Cloud appCenter Validation Upload package and UI Test using nodeJs and following app center instruction Wait for devices Run on first device when ready Run on second device when ready Run on nth device when ready Configure your run by selecting Generate report for results Run on third device when ready
  • 18. App Center Test Cloud Reports
  • 19. Add Ui Tests to DevOps using AppCenter From app center you get: appcenter test run uitest --app "codrinamerigo/LadyBug" --devices "codrinamerigo/android-test" --app-path pathToFile.apk --test-series "master" --locale "en_US" --build-dir pathToUITestBuildDir Enable task
  • 20. Add Ui Tests to your TFS mono ../../../NUnit.Runners.2.6.3/tools/nunit-console.exe myApp/MyApp.UITest/bin/Debug/ myApp.UITest.dll -xml=UITestResult.xml TFS NUNIT
  • 21. If sometimes, the iOS simulator doesn’t pop on the screen, might be useful to delete the xdb folder inside TMPDIR (on the Mac machine) and retry. For debug purpose, right-click on the iOS Project > Options > Compiler and add the string ENABLE_TEST_CLOUD Try to write no more that 20 ui tests per project to run them locally… Open the Android simulator on your Mac before running the tests Don’t forget about your UI Test – try to keep them live UI Tests aren't compatible with the Shared Mono Runtime, so remember to disable it for Android! From myexperience . . .
  • 22. Q & A

Editor's Notes

  1. Good afternoon everyone!
  2. First of all I want to thank our sponsors and the organizers who picked up my session. Now please raise your hand if you are a developer…Ok, this session is also for testers, don’t worry! This is the last session of the day and it feels almost like an usual day at work. Imagine you had an one-day task – something simple, like creating a login page. So, you started in the morning, created your beautiful page, linked all the actions and services, you fine tuned the UI in order to meet all the pixel perfect stuff requested by the designer, you wrote the Unit Test and some manual tests have been performed and all went smoothly. Then, at the end of the day, you check your quality requirements or your Definition of Done check list, you read: “UI Tests to be written ” and you ask WHY?
  3. But WHO better than you to write them? The designer has created everything, but of course he doesn’t know how xaml works, what’s behind the screen really… The Product Owner know the business requirements and testers have been tapping all over you screen and everything worked OK. So, either you are the dev of the view, or you know how XAML works, The “AutomationId” will became your Best Friend! But, first of all, let’s see some basic concepts and we will be back on the “AutomationID” – doesn’t it seems very powerful ? Automation – and all goeees wowwww
  4. Mobile apps are not like web browsers – depends on various variable, os versions, configurations, customizations  So, either you are the dev of the view, or you know how XAML works, The “AutomationId” will became your Best Friend!  But, first of all, let’s see some basic concepts and we will be back on the “AutomationID” – doesn’t it seems very powerful ? Automation – and all goeees wowwww
  5. Automated UI Tests are between Unit /service tests and manual testing. From this lay4er you will completely impersonate the end-user with every action he can take and ensure that everything is displayed as it was designed. Also, UI Tests are fragile, is recommended while writing this tests to focus only on the ‘UI Flow and interactions’ and not on the functionalities – let’s leave that for the unit test. *Talking about app testing, manual tests are or should be always performed, but in the last years, an tests pyramid with focus only on the automated tests have appeared *The base base-layer of the pyramid *This test is done to make sure that interaction through the UI widgets delivers the right output on the screen
  6. UI Test as every automated test can use the FIRST Approach – each test has to be :
  7. As seen for the example, our application is identified by the keyword app and, if needed, the application is able to take screenshots, that will be stored inside the bin folder of the UITest project.
  8. One of the important tools in creating UITests is the the REPL (read-eval-print-loop).
  9. See the solution and invoce the Repl() console and test basic query on the login screen (tree and query all) Show test results pad
  10. Here we have an example of a function, that given two integers, a and b, I returns ‘a+b’ . So a simple way of using the pattern might be : Another way of writing the ui tests is using the so called feature files that are written in some cases of ‘ behavior driven development or BDD.
  11. (for example: the keyboard pops on the screen, an input text is always empty, the keyboard disappears or hides a part of the screen which contains the ‘Login’ button, the popup is shown and is completely loaded)
  12. Write simple test for the login feature and play it
  13. Write test to show more features
  14. Wide and deep testing on real devices with real expectations- same model but different ios versions