SlideShare a Scribd company logo
1 of 38
Download to read offline
https://gaurav-singh.github.io
What is test Flakiness?
Flakiness kills automation projects
Tests passes locally
and start failing
sporadically when
running in CI”
Why should we care?
● We start ignoring test
run results
● Engineers lose
confidence with their UI
tests
● Actual bugs get
missed!!
Agenda:
1. Choose effective wait strategies 𝤿
2. Use reliable locator strategies 𝤿
3. Make tests faster 𝤿
4. Make tests reliable 𝤿
5. Get better at debugging 𝤿
6. Follow best practices 𝤿
App : API Demos
Find the Test code at GitHub
Hardcoded sleeps? 😦
@Test
public void staticHardCodedWaits() throws InterruptedException {
driver.findElementByXPath(accessibility).click();
Thread.sleep(3000);
driver.findElementByXPath(customView).click();
Thread.sleep(3000);
String text =
driver.findElementById("content").findElement(By.xpath(talkBack)
).getText();
Assert.assertTrue(text.contains("TalkBack"));
}
Implicit waits
@Test
public void implicitWaits() {
driver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
driver.findElementByXPath(accessibility).click();
driver.findElementByXPath(customView).click();
String text =
driver.findElementById("content").findElement(By.xpath(talkBack
)).getText();
Assert.assertTrue(text.contains("TalkBack"));
}
Use more of explicit waits
@Test
public void explicitWaits() {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(accessibilit
y))).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(customView))
).click();
String actualText =
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("content")))
.findElement(By.xpath(talkBack)).getText();
Assert.assertTrue(actualText.contains("TalkBack"));
}
Takeaway:
Prefer using explicit waits
Wow! 1 down. 5 more to go!
1. Choose effective wait strategies ✅
2. Use reliable locator strategies 𝤿
3. Make tests faster 𝤿
4. Make tests reliable 𝤿
5. Get better at debugging 𝤿
6. Follow best practices 𝤿
Can’t we just use Xpath?
Disadvantages of using XPath (especially in IOS):
1. Slow
2. Changes to app hierarchy can easily break tests
3. People can write crazy absolute XPaths like below:
//*[1]/*[1]/*[3]/*[2]/*[1]/*[1]
Accessibility id
● Cross platform, fast, unique. (In IOS: accessibility ID, Android:
content-desc)
driver.findElement(MobileBy.AccessibilityId("Graphics")).click
();
Predicate Strings
Predicate strings provides a query like syntax for finding IOS specific elements.
Here are the Construction Rules
@Test
public void predicateStringTest() {
driver.findElement(MobileBy.iOSNsPredicateString(
"type == 'XCUIElementTypeButton' AND value BEGINSWITH[c]
'Alert' AND visible = 1"))
.click();
}
IOS Class chain
● Appium’s wrapper over Native XCTest lookup functions.
● Hybrid between XPath and predicate strings and much faster than XPath
● Here are some construction rules
@Test
public void iosClassChainTest() {
String classChain = "XCUIElementTypeWindow[`name CONTAINS[cd]
"blabla"`]";
driver.findElement(MobileBy.iOSClassChain(classChain)).click();
}
UiSelector (Only Android)
● Appium provides a way to use Androids UiSelector API
● Valid Java code starting with new UiSelector() in string format
@Test
public void uiSelectorAndroid() {
String uiSelector = "new
UiSelector().descriptionContains("App")";
driver.findElement(MobileBy.AndroidUIAutomator(uiSelector))
.click();
}
Takeaway:
Prefer using accessibility id or
native strategies over XPath
Awesome! 2 down. 4 more to go!
1. Choose effective wait strategies ✅
2. Use reliable locator strategies ✅
3. Make tests faster 𝤿
4. Make tests reliable 𝤿
5. Get better at debugging 𝤿
6. Follow best practices 𝤿
Who doesn’t like taking shortcuts?
● User journeys on the app generally takes time to do:
● Taps
● Key presses
● Making API calls over network to a Backend service
● Show animations (Shimmers etc)
We can make our tests atomic by setting up the app in required state from where
the actual test can be executed
Android activities are your friend.
● Android activities represent different parts of an app.
● Directly launch the desired activity using either startActivity() or desired
capabilities
@Test
public void usingAndroidActivities() throws InterruptedException {
((AndroidDriver) driver).startActivity(new
Activity("io.appium.android.apis",
"io.appium.android.apis.preference.DefaultValues"));
}
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Automation");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity",
"io.appium.android.apis.preference.DefaultValues");
Use Kitchen sinks
● App devs can set up
a single view which
loads the app into
desired screen with
attached state
already setup.
Use deep links
● Essentially a URL which the app can parse and load certain state.
● With appium, we can directly use get() to hit the deeplink
driver.get("app://test/home/with_username/with_password");
Disable animations
● Animations on the app are of no use when running functional tests using
Appium
● On IOS: Settings > General > Accessibility > Reduce Motion > On (As a one
time setup)
@Test
public void usingAdbToTurnOffAnimations() throws IOException,
InterruptedException {
executeCmd("adb shell settings put global window_animation_scale 0");
executeCmd("adb shell settings put global transition_animation_scale 0");
executeCmd("adb shell settings put global animator_duration_scale 0");
driver.findElementByAccessibilityId("Animation").click();
driver.findElementByAccessibilityId("Custom Evaluator").click();
driver.findElementById("startButton").click();
driver.findElementById("startButton").click();
}
Takeaway:
Setup hooks to directly land at
the screen under test
You are on a roll. 3 down. 3 more to go!
1. Choose effective wait strategies ✅
2. Use reliable locator strategies ✅
3. Make tests faster ✅
4. Make tests reliable 𝤿
5. Get better at debugging 𝤿
6. Follow best practices 𝤿
Mock your API calls
● Backend services might change contracts or do
deployments during test runs causing tests to fail.
● Mocked API calls can return predictable responses
What could be an
approach for this?
● Setup some mock server
which returns canned
responses for specific
requests with expected
responses
● Change App to point to this
server and port or give app the
ability to set this up via UI.
● Ability to start/stop the server
before/after test suite
● Ability for mock server to
return different success,
failure responses for specific
scenarios
Takeaway:
● Mock your API’s
● Use API’s to setup data for
tests
Awesome! 4 down. 2 more to go!
1. Choose effective wait strategies ✅
2. Use reliable locator strategies ✅
3. Make tests faster ✅
4. Make tests reliable ✅
5. Get better at debugging 𝤿
6. Follow best practices 𝤿
What should you do when tests fail?
That’s simple! Just say its appiums fault and its buggy? 🤷 Right?
● Always read your test code exceptions in detail. It might give you a clue
about where the problem is.
org.openqa.selenium.WebDriverException: Connection refused
(Connection refused)
org.openqa.selenium.WebDriverException: An unknown
server-side error occurred while processing the command.
Original error: Could not find a connected Android device.
(WARNING: The server did not provide any stacktrace
information)
Appium logs are your friend!
Try to follow below approach to see Appium logs:
1. Check session start loglines to see all the capabilities were sent in as
expected.
2. The very end of the log, to see the last things Appium did (especially in the
case of an Appium crash).
3. Any stacktraces Appium has written to the logs (since these will often
have information directly related to an error).
4. Any log lines rated "warn" or "error".
2019-05-26 07:34:21:637 - [debug] [ADB] Killing adb server on port 5037
2019-05-26 07:34:21:846 - [debug] [ADB] Could not find devices, restarting adb server...
2019-05-26 07:34:21:846 - [debug] [ADB] Restarting adb
2019-05-26 07:34:21:846 - [debug] [ADB] Killing adb server on port 5037
2019-05-26 07:34:22:059 - [debug] [ADB] Could not find devices, restarting adb server...
2019-05-26 07:34:22:059 - [debug] [ADB] Restarting adb
2019-05-26 07:34:22:060 - [debug] [ADB] Killing adb server on port 5037
2019-05-26 07:34:22:271 - [debug] [AndroidDriver] Shutting down Android driver
2019-05-26 07:34:22:271 - [debug] [AndroidDriver] Called deleteSession but bootstrap wasn't active
2019-05-26 07:34:22:287 - [MJSONWP] Encountered internal error running command: Error: Could not find a
connected Android device.
at ADB.getDevices$
(/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/tools/system-calls.js:191:13)
at tryCatch
(/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke]
(/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as next]
(/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at invoke
(/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at enqueueResult
……
An example:
Takeaway:
When in doubt, Go through
Appium Logs
We have come so far! 5 down. Last one to go!
1. Choose effective wait strategies ✅
2. Use reliable locator strategies ✅
3. Make tests faster ✅
4. Make tests reliable ✅
5. Get better at debugging ✅
6. Follow best practices 𝤿
Best practices
● Store test run results
in some db
● Visualize the data
● Get involved early in
development
process and ensure
devs are building
testability into the
app from the start
Takeaway:
● Build testability from start
● Visualize your results
All done! No more flaky tests!
1. Choose effective wait strategies ✅
2. Use reliable locator strategies ✅
3. Make tests faster ✅
4. Make tests reliable ✅
5. Get better at debugging ✅
6. Follow best practices ✅
References
● Making your tests reliable, repeatable and fast - Jonathan lipps (HeadSpin
Webinar)
● Setting up desired capabilities to speed up tests even more. Read about
them here
● Know about mock server in a talk by Wim Selles
How to kill test flake in appium

More Related Content

Similar to How to kill test flake in appium

Java Test Automation for REST, Web and Mobile
Java Test Automation for REST, Web and MobileJava Test Automation for REST, Web and Mobile
Java Test Automation for REST, Web and MobileElias Nogueira
 
All levels of performance testing and monitoring in web-apps
All levels of performance testing and monitoring in web-appsAll levels of performance testing and monitoring in web-apps
All levels of performance testing and monitoring in web-appsAndrii Skrypnychenko
 
20160913 cookpad ios_en
20160913 cookpad ios_en20160913 cookpad ios_en
20160913 cookpad ios_enKazuaki Matsuo
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first designKyrylo Reznykov
 
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...Yusuke Yamamoto
 
Building And Executing Test Cases with Appium and Various Test Frameworks.pdf
Building And Executing Test Cases with Appium and Various Test Frameworks.pdfBuilding And Executing Test Cases with Appium and Various Test Frameworks.pdf
Building And Executing Test Cases with Appium and Various Test Frameworks.pdfpCloudy
 
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdfDifferent Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdfpCloudy
 
Cypress Testing Demystified: A Practical Guide
Cypress Testing Demystified: A Practical GuideCypress Testing Demystified: A Practical Guide
Cypress Testing Demystified: A Practical GuideTestgrid.io
 
Making Security Agile
Making Security AgileMaking Security Agile
Making Security AgileOleg Gryb
 
How to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and AndroidHow to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and AndroidOptimizely
 
QTP 10.0_Kalyan Chakravarthy.ppt
QTP 10.0_Kalyan Chakravarthy.pptQTP 10.0_Kalyan Chakravarthy.ppt
QTP 10.0_Kalyan Chakravarthy.pptKalyan Chakravarthy
 
Use Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test AutomationUse Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test AutomationClever Moe
 
Serverless in production (O'Reilly Software Architecture)
Serverless in production (O'Reilly Software Architecture)Serverless in production (O'Reilly Software Architecture)
Serverless in production (O'Reilly Software Architecture)Yan Cui
 
Automated Acceptance Testing Example
Automated Acceptance Testing ExampleAutomated Acceptance Testing Example
Automated Acceptance Testing ExampleHani Massoud
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsJim Jeffers
 
ScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency InjectionScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency Injection7mind
 
Splunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shellsSplunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shellsAnthony D Hendricks
 

Similar to How to kill test flake in appium (20)

Java Test Automation for REST, Web and Mobile
Java Test Automation for REST, Web and MobileJava Test Automation for REST, Web and Mobile
Java Test Automation for REST, Web and Mobile
 
All levels of performance testing and monitoring in web-apps
All levels of performance testing and monitoring in web-appsAll levels of performance testing and monitoring in web-apps
All levels of performance testing and monitoring in web-apps
 
20160913 cookpad ios_en
20160913 cookpad ios_en20160913 cookpad ios_en
20160913 cookpad ios_en
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first design
 
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
 
Building And Executing Test Cases with Appium and Various Test Frameworks.pdf
Building And Executing Test Cases with Appium and Various Test Frameworks.pdfBuilding And Executing Test Cases with Appium and Various Test Frameworks.pdf
Building And Executing Test Cases with Appium and Various Test Frameworks.pdf
 
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdfDifferent Techniques Of Debugging Selenium Based Test Scripts.pdf
Different Techniques Of Debugging Selenium Based Test Scripts.pdf
 
Selenium With Spices
Selenium With SpicesSelenium With Spices
Selenium With Spices
 
Cypress Testing Demystified: A Practical Guide
Cypress Testing Demystified: A Practical GuideCypress Testing Demystified: A Practical Guide
Cypress Testing Demystified: A Practical Guide
 
Making Security Agile
Making Security AgileMaking Security Agile
Making Security Agile
 
How to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and AndroidHow to feature flag and run experiments in iOS and Android
How to feature flag and run experiments in iOS and Android
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
QTP 10.0_Kalyan Chakravarthy.ppt
QTP 10.0_Kalyan Chakravarthy.pptQTP 10.0_Kalyan Chakravarthy.ppt
QTP 10.0_Kalyan Chakravarthy.ppt
 
Use Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test AutomationUse Jenkins For Continuous Load Testing And Mobile Test Automation
Use Jenkins For Continuous Load Testing And Mobile Test Automation
 
Serverless in production (O'Reilly Software Architecture)
Serverless in production (O'Reilly Software Architecture)Serverless in production (O'Reilly Software Architecture)
Serverless in production (O'Reilly Software Architecture)
 
Automated Acceptance Testing Example
Automated Acceptance Testing ExampleAutomated Acceptance Testing Example
Automated Acceptance Testing Example
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
ScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency InjectionScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency Injection
 
Splunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shellsSplunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shells
 

Recently uploaded

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 

Recently uploaded (20)

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 

How to kill test flake in appium

  • 2. What is test Flakiness?
  • 3. Flakiness kills automation projects Tests passes locally and start failing sporadically when running in CI” Why should we care? ● We start ignoring test run results ● Engineers lose confidence with their UI tests ● Actual bugs get missed!!
  • 4. Agenda: 1. Choose effective wait strategies 𝤿 2. Use reliable locator strategies 𝤿 3. Make tests faster 𝤿 4. Make tests reliable 𝤿 5. Get better at debugging 𝤿 6. Follow best practices 𝤿
  • 5. App : API Demos Find the Test code at GitHub
  • 6. Hardcoded sleeps? 😦 @Test public void staticHardCodedWaits() throws InterruptedException { driver.findElementByXPath(accessibility).click(); Thread.sleep(3000); driver.findElementByXPath(customView).click(); Thread.sleep(3000); String text = driver.findElementById("content").findElement(By.xpath(talkBack) ).getText(); Assert.assertTrue(text.contains("TalkBack")); }
  • 7. Implicit waits @Test public void implicitWaits() { driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.findElementByXPath(accessibility).click(); driver.findElementByXPath(customView).click(); String text = driver.findElementById("content").findElement(By.xpath(talkBack )).getText(); Assert.assertTrue(text.contains("TalkBack")); }
  • 8. Use more of explicit waits @Test public void explicitWaits() { WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(accessibilit y))).click(); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(customView)) ).click(); String actualText = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("content"))) .findElement(By.xpath(talkBack)).getText(); Assert.assertTrue(actualText.contains("TalkBack")); }
  • 10. Wow! 1 down. 5 more to go! 1. Choose effective wait strategies ✅ 2. Use reliable locator strategies 𝤿 3. Make tests faster 𝤿 4. Make tests reliable 𝤿 5. Get better at debugging 𝤿 6. Follow best practices 𝤿
  • 11. Can’t we just use Xpath? Disadvantages of using XPath (especially in IOS): 1. Slow 2. Changes to app hierarchy can easily break tests 3. People can write crazy absolute XPaths like below: //*[1]/*[1]/*[3]/*[2]/*[1]/*[1]
  • 12. Accessibility id ● Cross platform, fast, unique. (In IOS: accessibility ID, Android: content-desc) driver.findElement(MobileBy.AccessibilityId("Graphics")).click ();
  • 13. Predicate Strings Predicate strings provides a query like syntax for finding IOS specific elements. Here are the Construction Rules @Test public void predicateStringTest() { driver.findElement(MobileBy.iOSNsPredicateString( "type == 'XCUIElementTypeButton' AND value BEGINSWITH[c] 'Alert' AND visible = 1")) .click(); }
  • 14. IOS Class chain ● Appium’s wrapper over Native XCTest lookup functions. ● Hybrid between XPath and predicate strings and much faster than XPath ● Here are some construction rules @Test public void iosClassChainTest() { String classChain = "XCUIElementTypeWindow[`name CONTAINS[cd] "blabla"`]"; driver.findElement(MobileBy.iOSClassChain(classChain)).click(); }
  • 15. UiSelector (Only Android) ● Appium provides a way to use Androids UiSelector API ● Valid Java code starting with new UiSelector() in string format @Test public void uiSelectorAndroid() { String uiSelector = "new UiSelector().descriptionContains("App")"; driver.findElement(MobileBy.AndroidUIAutomator(uiSelector)) .click(); }
  • 16. Takeaway: Prefer using accessibility id or native strategies over XPath
  • 17. Awesome! 2 down. 4 more to go! 1. Choose effective wait strategies ✅ 2. Use reliable locator strategies ✅ 3. Make tests faster 𝤿 4. Make tests reliable 𝤿 5. Get better at debugging 𝤿 6. Follow best practices 𝤿
  • 18. Who doesn’t like taking shortcuts? ● User journeys on the app generally takes time to do: ● Taps ● Key presses ● Making API calls over network to a Backend service ● Show animations (Shimmers etc) We can make our tests atomic by setting up the app in required state from where the actual test can be executed
  • 19. Android activities are your friend. ● Android activities represent different parts of an app. ● Directly launch the desired activity using either startActivity() or desired capabilities @Test public void usingAndroidActivities() throws InterruptedException { ((AndroidDriver) driver).startActivity(new Activity("io.appium.android.apis", "io.appium.android.apis.preference.DefaultValues")); } DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Automation"); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); capabilities.setCapability("appPackage", "io.appium.android.apis"); capabilities.setCapability("appActivity", "io.appium.android.apis.preference.DefaultValues");
  • 20. Use Kitchen sinks ● App devs can set up a single view which loads the app into desired screen with attached state already setup.
  • 21. Use deep links ● Essentially a URL which the app can parse and load certain state. ● With appium, we can directly use get() to hit the deeplink driver.get("app://test/home/with_username/with_password");
  • 22. Disable animations ● Animations on the app are of no use when running functional tests using Appium ● On IOS: Settings > General > Accessibility > Reduce Motion > On (As a one time setup) @Test public void usingAdbToTurnOffAnimations() throws IOException, InterruptedException { executeCmd("adb shell settings put global window_animation_scale 0"); executeCmd("adb shell settings put global transition_animation_scale 0"); executeCmd("adb shell settings put global animator_duration_scale 0"); driver.findElementByAccessibilityId("Animation").click(); driver.findElementByAccessibilityId("Custom Evaluator").click(); driver.findElementById("startButton").click(); driver.findElementById("startButton").click(); }
  • 23. Takeaway: Setup hooks to directly land at the screen under test
  • 24. You are on a roll. 3 down. 3 more to go! 1. Choose effective wait strategies ✅ 2. Use reliable locator strategies ✅ 3. Make tests faster ✅ 4. Make tests reliable 𝤿 5. Get better at debugging 𝤿 6. Follow best practices 𝤿
  • 25. Mock your API calls ● Backend services might change contracts or do deployments during test runs causing tests to fail. ● Mocked API calls can return predictable responses
  • 26. What could be an approach for this? ● Setup some mock server which returns canned responses for specific requests with expected responses ● Change App to point to this server and port or give app the ability to set this up via UI. ● Ability to start/stop the server before/after test suite ● Ability for mock server to return different success, failure responses for specific scenarios
  • 27. Takeaway: ● Mock your API’s ● Use API’s to setup data for tests
  • 28. Awesome! 4 down. 2 more to go! 1. Choose effective wait strategies ✅ 2. Use reliable locator strategies ✅ 3. Make tests faster ✅ 4. Make tests reliable ✅ 5. Get better at debugging 𝤿 6. Follow best practices 𝤿
  • 29. What should you do when tests fail? That’s simple! Just say its appiums fault and its buggy? 🤷 Right? ● Always read your test code exceptions in detail. It might give you a clue about where the problem is. org.openqa.selenium.WebDriverException: Connection refused (Connection refused) org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device. (WARNING: The server did not provide any stacktrace information)
  • 30. Appium logs are your friend! Try to follow below approach to see Appium logs: 1. Check session start loglines to see all the capabilities were sent in as expected. 2. The very end of the log, to see the last things Appium did (especially in the case of an Appium crash). 3. Any stacktraces Appium has written to the logs (since these will often have information directly related to an error). 4. Any log lines rated "warn" or "error".
  • 31. 2019-05-26 07:34:21:637 - [debug] [ADB] Killing adb server on port 5037 2019-05-26 07:34:21:846 - [debug] [ADB] Could not find devices, restarting adb server... 2019-05-26 07:34:21:846 - [debug] [ADB] Restarting adb 2019-05-26 07:34:21:846 - [debug] [ADB] Killing adb server on port 5037 2019-05-26 07:34:22:059 - [debug] [ADB] Could not find devices, restarting adb server... 2019-05-26 07:34:22:059 - [debug] [ADB] Restarting adb 2019-05-26 07:34:22:060 - [debug] [ADB] Killing adb server on port 5037 2019-05-26 07:34:22:271 - [debug] [AndroidDriver] Shutting down Android driver 2019-05-26 07:34:22:271 - [debug] [AndroidDriver] Called deleteSession but bootstrap wasn't active 2019-05-26 07:34:22:287 - [MJSONWP] Encountered internal error running command: Error: Could not find a connected Android device. at ADB.getDevices$ (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/tools/system-calls.js:191:13) at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40) at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22) at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21) at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37) at enqueueResult …… An example:
  • 32. Takeaway: When in doubt, Go through Appium Logs
  • 33. We have come so far! 5 down. Last one to go! 1. Choose effective wait strategies ✅ 2. Use reliable locator strategies ✅ 3. Make tests faster ✅ 4. Make tests reliable ✅ 5. Get better at debugging ✅ 6. Follow best practices 𝤿
  • 34. Best practices ● Store test run results in some db ● Visualize the data ● Get involved early in development process and ensure devs are building testability into the app from the start
  • 35. Takeaway: ● Build testability from start ● Visualize your results
  • 36. All done! No more flaky tests! 1. Choose effective wait strategies ✅ 2. Use reliable locator strategies ✅ 3. Make tests faster ✅ 4. Make tests reliable ✅ 5. Get better at debugging ✅ 6. Follow best practices ✅
  • 37. References ● Making your tests reliable, repeatable and fast - Jonathan lipps (HeadSpin Webinar) ● Setting up desired capabilities to speed up tests even more. Read about them here ● Know about mock server in a talk by Wim Selles