@BagmarAnand 1
Changing Tyres In A Moving Car
Making Functional Test Automation Effective
Anand Bagmar
Software Quality Evangelist
@BagmarAnand 2
BagmarAnand
https://www.linkedin.com/in/anandbagmar/
About Me
@BagmarAnand 3
• Automated tests run fast.
• The automated test execution needs no manual
intervention to run/complete successfully – across
environments, in parallel, for all team members & CI
execution.
Raise your hand if you disagree
@BagmarAnand 4
• Automated tests are triggered automatically on any
product change.
• Automated tests can run, on-demand, on different
(supported) browsers/devices with no changes in code or
configuration.
Raise your hand if you disagree
@BagmarAnand 5
• The automated test code is clean and easy to maintain,
reuse and scale.
• Your automated tests can run in any order, and in parallel.
Raise your hand if you disagree
@BagmarAnand 6
• Consolidated reports and trends from test runs are
available in a central reporting server for the team.
• You have all the relevant information to do RCA of failed
tests readily available.
Raise your hand if you disagree
@BagmarAnand 7
• Your automated functional tests give deterministic
feedback - i.e. no flaky/intermittent test failures.
• As a result of your functional automation, manual testing
efforts are reduced.
Raise your hand if you disagree
@BagmarAnand 8
Why do you disagree?
Why is your automation not
effective?
@BagmarAnand 9
https://media.istockphoto.com/photos/hands-over-face-woman-hides-from-excess-of-business-buzzwords-picture-id155003877
Too many things to do
@BagmarAnand 10
https://thumbs.dreamstime.com/z/time-pressure-concept-businessman-buckled-under-clock-face-management-51187287.jpg
Running against
time
@BagmarAnand 11
Changing Tyres In A Moving Car
12
@BagmarAnand
Anti-Patterns
Prevent desired outcome from your automated tests
@BagmarAnand 13
What is an anti-pattern?
@BagmarAnand 14
Ideas that seem good, but are not!
https://likesmag.com/wp-content/uploads/2017/10/funny-design-fails.jpg
@BagmarAnand 15
Why do we do this?
https://martech.org/wp-content/uploads/2015/08/shortcut-strategy-maze-path-direction-ss-1920.jpg
@BagmarAnand 16
Caught in the headlights!
https://worlddeer.org/wp-content/uploads/elementor/thumbs/deer-in-headlights-meaning-pge44ctbg1qqspz7fp4erd9gy0dwohfbykadnxpp54.jpg
@BagmarAnand 17
Narrow focus
https://media.istockphoto.com/photos/potrait-of-a-man-holding-magnifying-glass-and-looking-through-it-up-picture-id1188760421
@BagmarAnand 18
Limited information
https://cdn.mos.cms.futurecdn.net/3cc58cc565491e129b29a5937ef46a1b-1200-80.jpg
@BagmarAnand 19
Common anti-patterns &
ways to address them
20
@BagmarAnand
Code Quality
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
@BagmarAnand 21
@BagmarAnand 22
Deeply nested code
Assertions all over the place
Impossible to understand
@BagmarAnand 24
Cognitive
complexity
@BagmarAnand 25
Cyclomatic
Complexity
26
@BagmarAnand
Code Quality
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
@BagmarAnand 27
Code Analysis
@BagmarAnand 28
Code Analysis
29
@BagmarAnand
https://media.istockphoto.com/vectors/stitch-in-time-saves-nine-vector-id1341596037
30
@BagmarAnand
Waits
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
@BagmarAnand 31
Thread.sleep()
@BagmarAnand 32
https://octopus.com/blog/selenium/8-mixing-waits/mixing-waits
Mixing Implicit & Explicit Waits
33
@BagmarAnand
Waits
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
34
@BagmarAnand
https://thumbs.dreamstime.com/b/no-sleeping-icon-white-background-not-allowed-here-sign-pillow-symbol-flat-style-249490992.jpg
STOP SLEEPING
35
@BagmarAnand
https://cdn.pecs-unitedkingdom.com/wp-content/uploads/2020/07/29093602/help-3.png
Understand Waits
@BagmarAnand 36
https://www.selenium.dev/documentation/webdriver/waits/
@BagmarAnand 37
https://octopus.com/blog/selenium/8-mixing-waits/mixing-waits
Do NOT mix Implicit & Explicit Waits
38
@BagmarAnand
Exception
Handling
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
@BagmarAnand 39
Swallowed / ignored exceptions
@BagmarAnand 40
Assertions all over the place!
41
@BagmarAnand
Exception Handling
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
42
@BagmarAnand
https://quotefancy.com/media/wallpaper/3840x2160/715835-Tom-Peters-Quote-Test-fast-fail-fast-adjust-fast.jpg
43
@BagmarAnand
https://www.selenium.dev/documentation/test_practices/encouraged/page_object_models/#support-in-webdriver
No assertions in PageObjects
44
@BagmarAnand
https://www.baeldung.com/java-new-custom-exception
Custom exceptions help in RCA
45
@BagmarAnand
Test Data
&
Data Provider
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
46
@BagmarAnand
@BagmarAnand 47
https://i.pinimg.com/originals/a6/04/2c/a6042c1e63cc3dc35cdfb202aff42b8a.jpg
The journey is not explicit
RCA becomes challenging
48
@BagmarAnand
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
Test Data
&
Data Provider
@BagmarAnand 49
Identify & automate unique journeys
@BagmarAnand 50
https://i.pinimg.com/originals/a6/04/2c/a6042c1e63cc3dc35cdfb202aff42b8a.jpg
Make each journey explicit
@BagmarAnand 51
• Data is complex
• Needs to mimic “real” data
• Needs to be unique
• Data can be nested
• Though specified as static, may need to be Dynamic
• Data can be shared and reused
Criteria for Test Data
@BagmarAnand 52
• In Test implementation
• In Test specification / intent
• In code … separate data structures / classes / etc.
• External files
Different ways to specify Test Data
@BagmarAnand 53
• Automated tests should have dedicated test data
• This data should not be mixed with data required for manual / exploratory testing
• Test data approach:
• Identify test data requirements to enable manual testing and automated testing
• Parallel execution, and CI-based execution to be kept in mind!
• Seed from Production / higher environments
• Create using REST APIs
Test Data for Automation
54
@BagmarAnand
Test Execution
Priority
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
55
@BagmarAnand
https://media.istockphoto.com/photos/waiting-in-line-picture-id177129252
Executing Tests in Sequence
@BagmarAnand 56
https://miro.medium.com/max/1400/1*LnNYJCRPmmvybAbqBbrIfg.png
Dependencies in Tests
@BagmarAnand 57
https://en.wikipedia.org/wiki/High-occupancy_vehicle_lane#/media/File:Interstate_5_northbound_near_Shoreline,_WA_-_HOV_and_VMS.jpg
Inefficient resource utilisation
58
@BagmarAnand
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
Test Execution
Priority
@BagmarAnand 59
https://www.youtube.com/watch?v=thL7wfJ4vGo
Independent Tests
@BagmarAnand 60
Test
Test
Test
Test Framework
Test Execution Scheduler
Optimised Test Execution
61
@BagmarAnand
Test execution
configuration -
testng.xml
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
@BagmarAnand 62
testng.xml
@BagmarAnand 63
testng.xml
@BagmarAnand 64
testng.xml
Suites / Classes / Tests
Parameters (test data)
65
@BagmarAnand
Test execution
configuration -
testng.xml
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
66
@BagmarAnand
Example:
Smoke / Sanity / Regression
Module / Component
https://media.istockphoto.com/vectors/blank-tag-labels-vector-id585063630
Tag your tests
67
@BagmarAnand
Separate build/test configuration
from test implementation
example: gradle/groovy over maven
https://www.cashanalytics.com/wp-content/uploads/2019/01/Understanding-Robotic-Process-Automation.png
68
@BagmarAnand
• Run specific subset of tests on demand, based on tag name
• Configurable from command line
• No code change required
Configurable Test Execution
69
@BagmarAnand
Magic – Rerun
failed tests,
automatically
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
70
@BagmarAnand
Flaky Tests
71
@BagmarAnand
DO NOT USE Retry Listener
72
@BagmarAnand
DO NOT Force actions
@BagmarAnand 73
https://quotefancy.com/media/wallpaper/3840x2160/228806-Nick-Vujicic-Quote-If-I-fail-I-try-again-and-again-and-again.jpg
@BagmarAnand 74
75
@BagmarAnand
76
@BagmarAnand
Magic – Rerun failed
tests, automatically
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
77
@BagmarAnand
@BagmarAnand 78
https://cdn.quotesgram.com/img/92/5/98723605-try-again-fail-better-samuel-beckett-quotes-sayings-pictures.jpg
@BagmarAnand 79
Do ‘proper’ RCA for failing & flaky tests
80
@BagmarAnand
Page Objects
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
@BagmarAnand 81
BaseTest
SearchTest
extends
Test Class Design
@BagmarAnand 82
BasePage
SearchPage
extends
Page Object Design
@BagmarAnand 83
WebPage
CommonUtils
SettingsPage
GlobalSearchPage
HeadersPage
CustomerHeadersPage
RootCustomerPage
CompanyPage
CustomerOverviewPage
Very Complex Page Object Design
@BagmarAnand 84
“Dad” is a “Human”
”Mom” is a “Human”
Inheritance
@BagmarAnand 85
Is “SearchPage” a “BasePage?”
Poor use of Inheritance
86
@BagmarAnand
Page Objects
Code Quality
Waits
Exception Handling
Test Data & Data Provider
Test Execution Priority
Test Execution configuration – testng.xml
Magic – Rerun of failed tests, automatically
Page Objects
@BagmarAnand 87
https://www.selenium.dev/documentation/test_practices/encouraged/page_object_models/#support-in-webdriver
Identifying Page Objects
@BagmarAnand 88
89
@BagmarAnand
Do not use PageFactory
https://titusfortner.com/2021/02/03/page-factory-optimization.html
@BagmarAnand 90
@BagmarAnand 91
What’s next?
@BagmarAnand 92
https://northstreet.dental/wp-content/uploads/2019/04/prevention-is-better-than-cure.jpg
@BagmarAnand 93
How can we avoid this trap?
https://www.gallereo.com/clients/c4ca4238a0b923820dcc509a6f75849b/image/istock%20avoid.jpg
@BagmarAnand 94
https://images.squarespace-cdn.com/content/v1/55f9cddce4b02abb448cfc46/1497726424894-1UATOB2UCTLXHHEMCGY2/context-matters.jpg
@BagmarAnand 95
https://i.ytimg.com/vi/Hdk-8BC86A8/hq720.jpg
@BagmarAnand 96
Take a step back
Think about the big picture
https://study.com/cimages/course-image/big-picture-thinking-in-business_183979_large.jpg
@BagmarAnand 97
https://res.cloudinary.com/hy4kyit2a/f_auto,fl_lossy,q_70/learn/modules/project-risk-management-for-partners/identify-assess-address-risk/images/33bde18fc5e1b848aa868fb6889b8585_risk-
mgmt-u-2-identify-assess-address-task-wheel.png
@BagmarAnand 98
https://www.selenium.dev/documentation/test_practices/encouraged/
Understand and choose the right practices
@BagmarAnand 99
https://i0.wp.com/dariusforoux.com/wp-content/uploads/2018/10/one-step-at-a-time.png
Evolve
@BagmarAnand 100
Tech Debt
Understand, Track, Address
https://strapi-appunite.s3.eu-central-1.amazonaws.com/r_1951381_w_F85_X_3f65c9a221.jpg
@BagmarAnand 101
https://cdn.gloveworx.com/images/9_26_mistakes.2e16d0ba.fill-1600x900.jpg
@BagmarAnand 102
https://smallbusinessify.com/wp-content/uploads/2021/11/Learn-From-Your-Mistakes.jpg
@BagmarAnand 103
https://mindfulbydesign.com/wp-content/uploads/2018/03/16-x-9.png
@BagmarAnand 104
https://www.calmsage.com/wp-content/uploads/2021/02/lessons-you-can-learn-from-your-mistakes.jpg
@BagmarAnand 105
BagmarAnand
https://www.linkedin.com/in/anandbagmar/
Thank You

Change Tyres In A Moving Car - Make Functional Test Automation Effective Keynote