SlideShare a Scribd company logo
1 of 25
Download to read offline
Web test automation
& Best practices
by
About me
Gediminas Guoba
Developer @ drivr.com
gg@drivr.com
gediminasgu@gmail.com
https://github.com/gediminasgu
About drivr.com
Selenium 2.0 (WebDriver)
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com/");// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));// Enter something to search for
query.SendKeys("Cheese");// Now submit the form. WebDriver will find the form for us from the
element
query.Submit();// Google's search is rendered dynamically with JavaScript.// Wait for the page to
load, timeout after 10 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });// Should see: "Cheese -
Google Search"
System.Console.WriteLine("Page title is: " + driver.Title);//Close the browser
driver.Quit();
Sample code
Challenges
Challenge 1: Layout, CSS, form
changes brakes tests
<form>
<input type=”text” id=”q” />
<input type=”submit” value=”Search” id=”submitBtn” />
</form>
Don’t use weak selectors like:
findElement by //form/input[type=submit]
Use id’s instead:
findElement by id ‘submitBtn’
Challenge 1: Layout, CSS, form
changes brakes tests
<form>
<input type=”text” id=”q” />
<input type=”submit” class=”btn” id=”submitBtn” />
</form>
Don’t use CSS class selectors like:
findElement by .btn
Use id’s instead:
findElement by id ‘submitBtn’
Challenge 1: Layout, CSS, form
changes brakes tests
Challenge 2: Testing CSS and layout
changes
Fighting layout bugs
https://code.google.com/p/fighting-layout-bugs/
Screenshot comparison (later)
Challenge 3: Data changes in
database
Don’t rely on data which can change
Have a “save” corner for your data
Or create a test data automatically
Or… have a separate test environment
Challenge 4: Simulation of different
situations
Special data config on DB
Data stubs in API
Data mocking on client side (later)
Challenge 5: Test stability
“Thread.Sleep()” is your enemy
Use WebDriverWait instead
// Google's search is rendered dynamically with JavaScript.// Wait for the page to load, timeout after 10
seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
Retry, retry, wait and retry again
Do it simple!
Challenge 6: Long running tests
Run tests in parallel
Split big test to a few smaller tests
Replace with JavaScript unit tests where
possible (later)
1000 unit tests takes 2-3 seconds
4-5 UI tests takes one minute
Challenge 7: Run tests in Production
Choose some tests to confirm your release to
production
We do not change any data
Challenge 0: Automation oriented
culture
Every team member must agree on automated
tests
Test is as much important as feature is
Don’t leave tests for “next sprint”
Do not release if even single test fails
Be prepared for long learning
Testing on different
browsers
Cross platform testing
Selenium supports many browsers + iOS and
Android
Run different OS for Selenium?
Sauce Labs
http://saucelabs.com
BrowserStack
http://www.browserstack.com/
Screenshot comparison
Selenium screenshot browser
Available at:
https://github.com/gediminasgu/selenium-screenshot-browser
Comparison done with: http://www.imagemagick.org/
Javascript tests
JavaScript unit tests
Jasmine testing framework
http://pivotal.github.io/jasmine/
AngularJS + HTTP mocking
http://docs.angularjs.org/api/ngMock.$httpBackend
Karma as tests runner
http://karma-runner.github.io/
E2E testing with
AngularJShttp://docs.angularjs.org/guide/dev_guide.e2e-testing
Thousands of tests in a seconds
Much stable than UI tests
Much easier to write!
Final word
Test automation is continuous process
Be prepared for long learning
Screenshot comparison rules!
AngularJS and Javascript unit testing is
awesome!
References
Selenium WebDriver
http://docs.seleniumhq.org/download/
Screenshot browser
https://github.com/gediminasgu/selenium-screenshot-browser
Jasmine - Javascript testing framework
http://pivotal.github.io/jasmine/
AngularJS - Javascript MVW framework
http://angularjs.org/
Karma - Javascript tests runner
http://karma-runner.github.io
Thank You!
Questions?

More Related Content

More from Agile Lietuva

Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...
Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...
Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...
Agile Lietuva
 

More from Agile Lietuva (20)

Agile pusryčiai 2023 - „Pirštas ant projekto pulso: CPO LT Agile patirtis ir ...
Agile pusryčiai 2023 - „Pirštas ant projekto pulso: CPO LT Agile patirtis ir ...Agile pusryčiai 2023 - „Pirštas ant projekto pulso: CPO LT Agile patirtis ir ...
Agile pusryčiai 2023 - „Pirštas ant projekto pulso: CPO LT Agile patirtis ir ...
 
Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...
Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...
Agile Pusryčiai 2023 - „Viešasis sektorius – neatskleistas inovacijų paklauso...
 
M. Kaminskas ir A. K. Remeikienė. LEAN projektas: sėkmės istorijos, iššūkiai ...
M. Kaminskas ir A. K. Remeikienė. LEAN projektas: sėkmės istorijos, iššūkiai ...M. Kaminskas ir A. K. Remeikienė. LEAN projektas: sėkmės istorijos, iššūkiai ...
M. Kaminskas ir A. K. Remeikienė. LEAN projektas: sėkmės istorijos, iššūkiai ...
 
B. den Haak. How to make OKRs Lean Again
B. den Haak. How to make OKRs Lean AgainB. den Haak. How to make OKRs Lean Again
B. den Haak. How to make OKRs Lean Again
 
D. Aitcheson. How to make forecasts that are actually accurate.
D. Aitcheson. How to make forecasts that are actually accurate.D. Aitcheson. How to make forecasts that are actually accurate.
D. Aitcheson. How to make forecasts that are actually accurate.
 
Aleksandra Černiauskienė. Misija Bloomberg: Agile pagal amerikiečius
Aleksandra Černiauskienė. Misija Bloomberg: Agile pagal amerikiečiusAleksandra Černiauskienė. Misija Bloomberg: Agile pagal amerikiečius
Aleksandra Černiauskienė. Misija Bloomberg: Agile pagal amerikiečius
 
Maija Aniskovič. Agile įtaka komandos motyvacijai.
Maija Aniskovič. Agile  įtaka komandos motyvacijai.Maija Aniskovič. Agile  įtaka komandos motyvacijai.
Maija Aniskovič. Agile įtaka komandos motyvacijai.
 
dr. E. Janiūnienė. Asociacijos Agile Lietuva atlikto Agile tyrimo pristatymas
dr. E. Janiūnienė. Asociacijos Agile Lietuva atlikto Agile tyrimo pristatymasdr. E. Janiūnienė. Asociacijos Agile Lietuva atlikto Agile tyrimo pristatymas
dr. E. Janiūnienė. Asociacijos Agile Lietuva atlikto Agile tyrimo pristatymas
 
M. Aniskovič. Laužome stereotipus: Agile gali drąsiai taikyti visi
M. Aniskovič. Laužome stereotipus: Agile gali drąsiai taikyti visiM. Aniskovič. Laužome stereotipus: Agile gali drąsiai taikyti visi
M. Aniskovič. Laužome stereotipus: Agile gali drąsiai taikyti visi
 
R. Krukonis. Reikalingas greitas rezultatas – pakeiskime projekto darbų organ...
R. Krukonis. Reikalingas greitas rezultatas – pakeiskime projekto darbų organ...R. Krukonis. Reikalingas greitas rezultatas – pakeiskime projekto darbų organ...
R. Krukonis. Reikalingas greitas rezultatas – pakeiskime projekto darbų organ...
 
M. Jovaišas. Viešojo sektoriaus lankstumas įgyvendinant transformacijas
M. Jovaišas. Viešojo sektoriaus lankstumas įgyvendinant transformacijasM. Jovaišas. Viešojo sektoriaus lankstumas įgyvendinant transformacijas
M. Jovaišas. Viešojo sektoriaus lankstumas įgyvendinant transformacijas
 
A. Kovaliov. Kas nėra Agile jaunystėje, tas neturi širdies. Kas nėra Watefall...
A. Kovaliov. Kas nėra Agile jaunystėje, tas neturi širdies. Kas nėra Watefall...A. Kovaliov. Kas nėra Agile jaunystėje, tas neturi širdies. Kas nėra Watefall...
A. Kovaliov. Kas nėra Agile jaunystėje, tas neturi širdies. Kas nėra Watefall...
 
V. Vasiliauskas. Nestandartinis atvejis: nuo Kanban prie Scrum
V. Vasiliauskas. Nestandartinis atvejis: nuo Kanban prie ScrumV. Vasiliauskas. Nestandartinis atvejis: nuo Kanban prie Scrum
V. Vasiliauskas. Nestandartinis atvejis: nuo Kanban prie Scrum
 
Leonard Vorobej. Agile projektų valdymas pradedantiesiems
Leonard Vorobej. Agile projektų valdymas pradedantiesiemsLeonard Vorobej. Agile projektų valdymas pradedantiesiems
Leonard Vorobej. Agile projektų valdymas pradedantiesiems
 
Giedrė Žemulaitytė. Agile personalo skyriaus valdyme
Giedrė Žemulaitytė. Agile personalo skyriaus valdyme Giedrė Žemulaitytė. Agile personalo skyriaus valdyme
Giedrė Žemulaitytė. Agile personalo skyriaus valdyme
 
Gabija Fatėnaitė. Agile ir Scrum turinio kūrimo ir marketingo komandose
Gabija Fatėnaitė. Agile ir Scrum turinio kūrimo ir marketingo komandoseGabija Fatėnaitė. Agile ir Scrum turinio kūrimo ir marketingo komandose
Gabija Fatėnaitė. Agile ir Scrum turinio kūrimo ir marketingo komandose
 
Gediminas Milieška. Agile kelionės: nuo transformacijos iki planavimo dideliu...
Gediminas Milieška. Agile kelionės: nuo transformacijos iki planavimo dideliu...Gediminas Milieška. Agile kelionės: nuo transformacijos iki planavimo dideliu...
Gediminas Milieška. Agile kelionės: nuo transformacijos iki planavimo dideliu...
 
Denis Vanpoucke. Agile kelionės:nuo transformacijos iki planavimo dideliu mastu
Denis Vanpoucke. Agile kelionės:nuo transformacijos iki planavimo dideliu mastuDenis Vanpoucke. Agile kelionės:nuo transformacijos iki planavimo dideliu mastu
Denis Vanpoucke. Agile kelionės:nuo transformacijos iki planavimo dideliu mastu
 
Irmantas Znatinas. Kodėl reikalingas Agile, kai "pas mus ir taip viskas puiki...
Irmantas Znatinas. Kodėl reikalingas Agile, kai "pas mus ir taip viskas puiki...Irmantas Znatinas. Kodėl reikalingas Agile, kai "pas mus ir taip viskas puiki...
Irmantas Znatinas. Kodėl reikalingas Agile, kai "pas mus ir taip viskas puiki...
 
A. Kovaliov ir A. Kublickij. Diegimo etapas prasideda nuo pirmos iteracijos ....
A. Kovaliov ir A. Kublickij. Diegimo etapas prasideda nuo pirmos iteracijos ....A. Kovaliov ir A. Kublickij. Diegimo etapas prasideda nuo pirmos iteracijos ....
A. Kovaliov ir A. Kublickij. Diegimo etapas prasideda nuo pirmos iteracijos ....
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Gediminas Guoba - Test automation & best practices

  • 1. Web test automation & Best practices by
  • 2. About me Gediminas Guoba Developer @ drivr.com gg@drivr.com gediminasgu@gmail.com https://github.com/gediminasgu
  • 5. IWebDriver driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.google.com/");// Find the text input element by its name IWebElement query = driver.FindElement(By.Name("q"));// Enter something to search for query.SendKeys("Cheese");// Now submit the form. WebDriver will find the form for us from the element query.Submit();// Google's search is rendered dynamically with JavaScript.// Wait for the page to load, timeout after 10 seconds WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });// Should see: "Cheese - Google Search" System.Console.WriteLine("Page title is: " + driver.Title);//Close the browser driver.Quit(); Sample code
  • 7. Challenge 1: Layout, CSS, form changes brakes tests <form> <input type=”text” id=”q” /> <input type=”submit” value=”Search” id=”submitBtn” /> </form> Don’t use weak selectors like: findElement by //form/input[type=submit] Use id’s instead: findElement by id ‘submitBtn’
  • 8. Challenge 1: Layout, CSS, form changes brakes tests <form> <input type=”text” id=”q” /> <input type=”submit” class=”btn” id=”submitBtn” /> </form> Don’t use CSS class selectors like: findElement by .btn Use id’s instead: findElement by id ‘submitBtn’
  • 9. Challenge 1: Layout, CSS, form changes brakes tests
  • 10. Challenge 2: Testing CSS and layout changes Fighting layout bugs https://code.google.com/p/fighting-layout-bugs/ Screenshot comparison (later)
  • 11. Challenge 3: Data changes in database Don’t rely on data which can change Have a “save” corner for your data Or create a test data automatically Or… have a separate test environment
  • 12. Challenge 4: Simulation of different situations Special data config on DB Data stubs in API Data mocking on client side (later)
  • 13. Challenge 5: Test stability “Thread.Sleep()” is your enemy Use WebDriverWait instead // Google's search is rendered dynamically with JavaScript.// Wait for the page to load, timeout after 10 seconds WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); }); Retry, retry, wait and retry again Do it simple!
  • 14. Challenge 6: Long running tests Run tests in parallel Split big test to a few smaller tests Replace with JavaScript unit tests where possible (later) 1000 unit tests takes 2-3 seconds 4-5 UI tests takes one minute
  • 15. Challenge 7: Run tests in Production Choose some tests to confirm your release to production We do not change any data
  • 16. Challenge 0: Automation oriented culture Every team member must agree on automated tests Test is as much important as feature is Don’t leave tests for “next sprint” Do not release if even single test fails Be prepared for long learning
  • 18. Cross platform testing Selenium supports many browsers + iOS and Android Run different OS for Selenium? Sauce Labs http://saucelabs.com BrowserStack http://www.browserstack.com/
  • 20. Selenium screenshot browser Available at: https://github.com/gediminasgu/selenium-screenshot-browser Comparison done with: http://www.imagemagick.org/
  • 22. JavaScript unit tests Jasmine testing framework http://pivotal.github.io/jasmine/ AngularJS + HTTP mocking http://docs.angularjs.org/api/ngMock.$httpBackend Karma as tests runner http://karma-runner.github.io/ E2E testing with AngularJShttp://docs.angularjs.org/guide/dev_guide.e2e-testing Thousands of tests in a seconds Much stable than UI tests Much easier to write!
  • 23. Final word Test automation is continuous process Be prepared for long learning Screenshot comparison rules! AngularJS and Javascript unit testing is awesome!
  • 24. References Selenium WebDriver http://docs.seleniumhq.org/download/ Screenshot browser https://github.com/gediminasgu/selenium-screenshot-browser Jasmine - Javascript testing framework http://pivotal.github.io/jasmine/ AngularJS - Javascript MVW framework http://angularjs.org/ Karma - Javascript tests runner http://karma-runner.github.io