SlideShare a Scribd company logo
1 of 78
Selenium WebDriver
Test automation for web applications
Thomas Sundberg
Stockholm, Sweden
Think Code AB
thomas@thinkcode.se
@thomassundberg
Blog: https://thomassundberg.wordpress.com/
Code: https://github.com/tsundberg/selenium-test-
automation/tree/luxsoft-january-2015
© Think Code AB, http://www.thinkcode.se
TESTING OF WEB APPLICATIONS
© Think Code AB, http://www.thinkcode.se
Testing of web applications
• Introduction to testing
• Manual testing
• Automated testing
• Selenium
© Think Code AB, http://www.thinkcode.se
Introduction
• Why testing?
• What to test?
• When to test?
• How to test?
© Think Code AB, http://www.thinkcode.se
Why testing?
• Create confidence to release
© Think Code AB, http://www.thinkcode.se
Why release?
• Create value
• Reduce waste
• Get feedback from real users
– Was this what they wanted?
© Think Code AB, http://www.thinkcode.se
Create value
• Using the software is the only way our
users/customers can benefit from our work
• This is the only reason why they pay us to
create it
© Think Code AB, http://www.thinkcode.se
Reduce waste
• Waste until it is used
• Unused code is waste
• Unreleased code is unused code
• Waste until it is deployed
© Think Code AB, http://www.thinkcode.se
Feedback from real users
• Is this was what they wanted?
• Release early
• Release often
© Think Code AB, http://www.thinkcode.se
When to test?
• As soon as possible
© Think Code AB, http://www.thinkcode.se
Why?
• Small problems are easy to fix
• Young problems are small
• Catch them before they grow up and become
big problems
– Large, old problems can be catastrophic
© Think Code AB, http://www.thinkcode.se
How to test?
• Manual
• Automated
© Think Code AB, http://www.thinkcode.se
Manual
• Always through the user interface
• Slow
• Inconsistent
• Doesn't scale
• Will find new, interesting bugs
© Think Code AB, http://www.thinkcode.se
Automated
• Different levels
– User interface
– Code
• Faster
• Consistent
• Scales
• Will never find new, interesting bugs
© Think Code AB, http://www.thinkcode.se
Manual vs. Automated
• Manual test
– Understand the problem
– Know the application
• Automated test
– Understand the problem
– Know the application
– Programming
© Think Code AB, http://www.thinkcode.se
SELENIUM
© Think Code AB, http://www.thinkcode.se
Browser automation
• Can be used for tests
• Doesn’t have to be used for testing
© Think Code AB, http://www.thinkcode.se
Where does the name come from?
• Selenium is a chemical element, Se
• Treatment for Mercury poisoning
• Mercury is a closed source web testing tool
• Selenium is a cure for Mercury
© Think Code AB, http://www.thinkcode.se
Tests
• Many frameworks
• Test NG
• Spock
• JUnit
• Others
© Think Code AB, http://www.thinkcode.se
Testing pyramid
End to end
Integration
Unit
Slow
Faster
Fast
Many reasons to fail
Many reasons to fail
One reason to fail
Faster is better Fewer reasons to fail is better
© Think Code AB, http://www.thinkcode.se
End to end
• From the user interface
• Very slow
– It takes forever to start a browser and do
something
• Very fragile
– Lots of reasons why a test will fail
• The database is broken
• The user interface is missing a component
• Many more…
© Think Code AB, http://www.thinkcode.se
Doesn’t scale
• Impossible to test all paths
– 10 entrances from the ui
– 5 paths through the controller
– 7 paths through the model
– 10 * 5 * 7 = 350 paths
– 350 tests
© Think Code AB, http://www.thinkcode.se
Integration
• Verify that components works together
– Is the database properly configured?
– Is the queue started?
• Slow
• Fragile
– Many reasons to fail
© Think Code AB, http://www.thinkcode.se
Unit
• Small pieces of functionality at a low level
• Very fast
• Stable
– Only one reason to fail
– Failures are easy to understand
• Used for verifying all use cases for each
implementation
• Possible to verify all paths
© Think Code AB, http://www.thinkcode.se
Good tests
• Must be easy to
– Understand
– Maintain
– Change
– Extend
© Think Code AB, http://www.thinkcode.se
Testing pyramid
End to end
Integration
Unit
Slow
Faster
Fast
Many reasons to fail
Many reasons to fail
One reason to fail
Faster is better Fewer reasons to fail is better
© Think Code AB, http://www.thinkcode.se
Inverted Testing pyramid
End to end
Integration
Unit
Slow
Faster
Fast
Many reasons to fail
Many reasons to fail
One reason to fail
Faster is better Fewer reasons to fail is better
© Think Code AB, http://www.thinkcode.se
Selenium echo system
• Selenium IDE
• Selenium WebDriver
© Think Code AB, http://www.thinkcode.se
Selenium IDE
• Firefox plugin
• Record and replay
• If you want to
– create quick bug reproduction scripts
– create scripts to aid in automation-aided
exploratory testing
© Think Code AB, http://www.thinkcode.se
Selenium WebDriver
• A programming framework
• Local in any browser you have installed
– Open source
– Anyone can use it
• Many programming languages
– We will use Java
• If you want to
– create robust, browser-based regression automation
suites and tests
– scale and distribute scripts across many environments
© Think Code AB, http://www.thinkcode.se
Selenium WebDriver
• W3C standard
– Not done, but well on its way
• Every W3C browser must support WebDriver
© Think Code AB, http://www.thinkcode.se
Selenium Hub
• Automate a browser remote
• Enable us to do cross browser testing
– Browser
– Operating system
© Think Code AB, http://www.thinkcode.se
WebDriver remote
• Same API as regular WebDriver
– If it works local, you can execute it remote
– SauceLabs
© Think Code AB, http://www.thinkcode.se
SELENIUM IDE
© Think Code AB, http://www.thinkcode.se
Hello, world!
• http://selenium.thinkcode.se
• Find an element and verify the text
© Think Code AB, http://www.thinkcode.se
Fill out a form
• Change password
© Think Code AB, http://www.thinkcode.se
WHAT TO TEST?
© Think Code AB, http://www.thinkcode.se
What should you test?
• Testing theatre
• Test stuff that matters
© Think Code AB, http://www.thinkcode.se
Security theatre
• Not aiming for security
• Aim to make people feel safe
• Security check on airports
– Why do they take you water bottle?
– If it is dangerous, remove it far away so it can't be
dangerous for you
© Think Code AB, http://www.thinkcode.se
Don’t test everything
• Enough to feel safe
© Think Code AB, http://www.thinkcode.se
Testing pyramid
End to end
Integration
Unit
© Think Code AB, http://www.thinkcode.se
User interface
• Do not test everything through the user
interface
• Test at the right level
© Think Code AB, http://www.thinkcode.se
End to end
• Can you login?
• Can you fail to log in?
• Can you do a purchase?
– At least place something in the shopping bag
© Think Code AB, http://www.thinkcode.se
Integration
• Connect to the database
• Connect to a queue
© Think Code AB, http://www.thinkcode.se
Unit level
• Password algorithm
© Think Code AB, http://www.thinkcode.se
You must be in control
• Collaborators
• Mock or Stub
© Think Code AB, http://www.thinkcode.se
Database
• Know about the content
• Decide what the content should be
• This makes End to end complicated
© Think Code AB, http://www.thinkcode.se
What should you automate?
• Any test that should be repeated
• At the right level...
© Think Code AB, http://www.thinkcode.se
What should you not automate?
• Expensive tests
– Buying using a credit card
– Probably enough to do one manual test
– Setup a fake server that mimics the payment
service
– http://wiremock.org
© Think Code AB, http://www.thinkcode.se
One off
• If it truly exists
• Automate it the second time
© Think Code AB, http://www.thinkcode.se
SELENIUM WEBDRIVER
© Think Code AB, http://www.thinkcode.se
First WebDriver test
• Export the code from Selenium IDE
– The code is ok
– Not pretty
– Ok to start with
• Good for finding elements
© Think Code AB, http://www.thinkcode.se
Browser tools
• Firebug
• Firepath
• Other favorites?
© Think Code AB, http://www.thinkcode.se
First handmade WebDriver test
• Hello world
• Without page object
• With page object
© Think Code AB, http://www.thinkcode.se
Hand made is better
• You have better control
• You know what you did
• Slower?
– Maybe at first, but not in the long run
© Think Code AB, http://www.thinkcode.se
Page objects
• Separation of navigation logic and test
– Only need to change the page object when the
layout changes
– The tests remain unchanged if the logic is the
same
© Think Code AB, http://www.thinkcode.se
Lazy
• Hard to solve a hard problem
• Better to solve many small
© Think Code AB, http://www.thinkcode.se
One class per page
• Abstracts the page functionality
• Hide the page navigation
© Think Code AB, http://www.thinkcode.se
Simplifies the tests
• The test focus on WHAT the application should
do
• Not on HOW
• Behavior is interesting
© Think Code AB, http://www.thinkcode.se
Supply the browser
• Through the constructor
– Allow you to use the same page object with
different browsers
• Verify that the current page is the right page
– Check title or similar characteristics
• Throw an exception if you can’t verify the
page
© Think Code AB, http://www.thinkcode.se
assertThat
• Signals through exception
• assertThat(actaulTitle, is(expectedTitle));
© Think Code AB, http://www.thinkcode.se
Example - Check boxes
http://selenium.thinkcode.se/selectColor.html
© Think Code AB, http://www.thinkcode.se
Test organization
By technology By functional area
© Think Code AB, http://www.thinkcode.se
Test organization
• Separate on functional areas
• Do not separate on technology
– A new developer want to find the relevant test
and page objects fast
• All tests and page object for a certain area
should live in the same package
© Think Code AB, http://www.thinkcode.se
Selenium echo system
• Selenium IDE
– Firefox plugin
• WebDriver
– Programming api
• Selenium hub
– Remote
– Different browsers
– Different operating systems
© Think Code AB, http://www.thinkcode.se
Testing pyramid
End to end
Integration
Unit
© Think Code AB, http://www.thinkcode.se
Test things at the right level
• End to end
• Integration
• Unit
End to end
• Verify that the system is alive
• Most crucial flow
– Buy a product
– Book a trip
• Very slow
• Lots of reasons to fail
© Think Code AB, http://www.thinkcode.se
Integration
• Slow
• Many reasons to fail
• Doesn’t scale
© Think Code AB, http://www.thinkcode.se
Unit
• Fast
• Only one reason to fail
• Algorithms
• Password
© Think Code AB, http://www.thinkcode.se
Testing theater
• Verifying important parts in the system
• Not for satisfying a managers metric
© Think Code AB, http://www.thinkcode.se
WebDriver
• close()
• findElement(By by)
• findElements(By by)
• get(java.lang.String url)
• getCurrentUrl()
• getPageSource()
• getTitle()
• getWindowHandle()
• getWindowHandles()
• manage()
• navigate()
• quit()
• switchTo()
© Think Code AB, http://www.thinkcode.se
Locators
• By.id(java.lang.String id)
– The preferred locater if the IDs are unique
• By.name(java.lang.String name)
– Almost as good as ID, if the name is unique
• By.xpath(java.lang.String xpathExpression)
– Depends on the page structure
• By.cssSelector(java.lang.String selector)
– Finds elements via the driver's underlying W3 Selector engine.
• By.linkText(java.lang.String linkText)
– Complicated if your site supports many languages
• By.partialLinkText(java.lang.String linkText)
– Complicated if your site supports many languages
• By.tagName(java.lang.String name)
– Probably not a unique element, all h1
• By.className(java.lang.String className)
– Finds elements based on the value of the class attribute.
© Think Code AB, http://www.thinkcode.se
WebElement
• clear()
• click()
• findElement(By by)
• findElements(By by)
• getAttribute(java.lang.String name)
• getCssValue(java.lang.String propertyName)
• getLocation()
• getSize()
• getTagName()
• getText()
• isDisplayed()
• isEnabled()
• isSelected()
• sendKeys(java.lang.CharSequence... keysToSend)
• submit()
© Think Code AB, http://www.thinkcode.se
Page objects
• Separate navigation and logic
• Clearer and easier tests
• Supply the browser
• Verify the correct page
© Think Code AB, http://www.thinkcode.se
Interested in more?
Join me in Timisoara, Romania in April for
A two day, in depth, Selenium course.
http://mozaicworks.com/public-trainings-and-workshops/selenium-webdriver-test-automation-for-web-applications/
© Think Code AB, http://www.thinkcode.se
Thomas Sundberg
Stockholm, Sweden
Think Code AB
thomas@thinkcode.se
@thomassundberg
Blog: https://thomassundberg.wordpress.com/
Code: https://github.com/tsundberg/selenium-test-
automation/tree/luxsoft-january-2015
© Think Code AB, http://www.thinkcode.se

More Related Content

What's hot

Selenium webdriver course content rakesh hansalia
Selenium webdriver course content rakesh hansaliaSelenium webdriver course content rakesh hansalia
Selenium webdriver course content rakesh hansalia
Rakesh Hansalia
 
Selenium (1)
Selenium (1)Selenium (1)
Selenium (1)
onlinemindq
 

What's hot (20)

Selenium for Jobseekers
Selenium for JobseekersSelenium for Jobseekers
Selenium for Jobseekers
 
Selenium Webdriver
Selenium WebdriverSelenium Webdriver
Selenium Webdriver
 
Automation - web testing with selenium
Automation - web testing with seleniumAutomation - web testing with selenium
Automation - web testing with selenium
 
Practical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test AutomationPractical Tips & Tricks for Selenium Test Automation
Practical Tips & Tricks for Selenium Test Automation
 
Selenium webdriver course content rakesh hansalia
Selenium webdriver course content rakesh hansaliaSelenium webdriver course content rakesh hansalia
Selenium webdriver course content rakesh hansalia
 
Selenium (1)
Selenium (1)Selenium (1)
Selenium (1)
 
Selenium
SeleniumSelenium
Selenium
 
An Overview of Selenium
An Overview of SeleniumAn Overview of Selenium
An Overview of Selenium
 
Tech talks (Automation on Selenium Web Driver. How to begin & implement)
Tech talks (Automation on Selenium Web Driver. How to begin & implement)Tech talks (Automation on Selenium Web Driver. How to begin & implement)
Tech talks (Automation on Selenium Web Driver. How to begin & implement)
 
Automated Web Testing Using Selenium
Automated Web Testing Using SeleniumAutomated Web Testing Using Selenium
Automated Web Testing Using Selenium
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
 
Efficient Automated Test Creation With Selenium IDE Plugins
Efficient Automated Test Creation With Selenium IDE PluginsEfficient Automated Test Creation With Selenium IDE Plugins
Efficient Automated Test Creation With Selenium IDE Plugins
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011Selenium 2 - PyCon 2011
Selenium 2 - PyCon 2011
 
Selenium Primer
Selenium PrimerSelenium Primer
Selenium Primer
 
Selenium - Introduction
Selenium - IntroductionSelenium - Introduction
Selenium - Introduction
 

Viewers also liked

Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Prasad Sawant
 
Fire Sprinkler System Solution
Fire Sprinkler System SolutionFire Sprinkler System Solution
Fire Sprinkler System Solution
Kroos Nan
 
Data centar cooling using multiple chiller system with r134a
Data centar cooling using multiple chiller system with r134aData centar cooling using multiple chiller system with r134a
Data centar cooling using multiple chiller system with r134a
UNEP OzonAction
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Framework
guestd8c458
 
HVAC Design Project
HVAC Design ProjectHVAC Design Project
HVAC Design Project
Luis Molina
 

Viewers also liked (20)

Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Selenium Webdriver - jOpenSpace 2015
Selenium Webdriver - jOpenSpace 2015Selenium Webdriver - jOpenSpace 2015
Selenium Webdriver - jOpenSpace 2015
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium intro
Selenium introSelenium intro
Selenium intro
 
Introduction to Selenium Webdriver - SpringPeople
Introduction to Selenium Webdriver - SpringPeopleIntroduction to Selenium Webdriver - SpringPeople
Introduction to Selenium Webdriver - SpringPeople
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
Understanding Selenium/RC, Webdriver Architecture and developing the page obj...
 
Fire Sprinkler System Solution
Fire Sprinkler System SolutionFire Sprinkler System Solution
Fire Sprinkler System Solution
 
Projects
ProjectsProjects
Projects
 
Electrical engineering in construction field
Electrical engineering in construction fieldElectrical engineering in construction field
Electrical engineering in construction field
 
Data centar cooling using multiple chiller system with r134a
Data centar cooling using multiple chiller system with r134aData centar cooling using multiple chiller system with r134a
Data centar cooling using multiple chiller system with r134a
 
Fire sprinkler system
Fire sprinkler systemFire sprinkler system
Fire sprinkler system
 
Building Construction 1 - Experiencing Construction
Building Construction 1 - Experiencing ConstructionBuilding Construction 1 - Experiencing Construction
Building Construction 1 - Experiencing Construction
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Framework
 
Mechanical, electrical, and plumbing engineering enhancements in revit 2016 nk
Mechanical, electrical, and plumbing engineering enhancements in revit 2016 nkMechanical, electrical, and plumbing engineering enhancements in revit 2016 nk
Mechanical, electrical, and plumbing engineering enhancements in revit 2016 nk
 
Section 1 - Building and Construction
Section 1 - Building and ConstructionSection 1 - Building and Construction
Section 1 - Building and Construction
 
Airchanges hvac
Airchanges hvacAirchanges hvac
Airchanges hvac
 
HVAC Design Project
HVAC Design ProjectHVAC Design Project
HVAC Design Project
 

Similar to Selenium WebDriver - Test automation for web applications

Acing application lifecycle management in SharePoint
Acing application lifecycle management in SharePointAcing application lifecycle management in SharePoint
Acing application lifecycle management in SharePoint
Jeremy Thake
 

Similar to Selenium WebDriver - Test automation for web applications (20)

New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDE
 
Joomla as a mobile App backend - ideas, examples and experiences
Joomla as a mobile App backend - ideas, examples and experiencesJoomla as a mobile App backend - ideas, examples and experiences
Joomla as a mobile App backend - ideas, examples and experiences
 
Test Automation with Twist and Sahi
Test Automation with Twist and SahiTest Automation with Twist and Sahi
Test Automation with Twist and Sahi
 
Pearls and Must-Have Tools for the Modern Web / .NET Developer
Pearls and Must-Have Tools for the Modern Web / .NET DeveloperPearls and Must-Have Tools for the Modern Web / .NET Developer
Pearls and Must-Have Tools for the Modern Web / .NET Developer
 
[Pinto] Is my SharePoint Development team properly enlighted?
[Pinto] Is my SharePoint Development team properly enlighted?[Pinto] Is my SharePoint Development team properly enlighted?
[Pinto] Is my SharePoint Development team properly enlighted?
 
Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully Mastering Test Automation: How to Use Selenium Successfully
Mastering Test Automation: How to Use Selenium Successfully
 
Acing application lifecycle management in SharePoint
Acing application lifecycle management in SharePointAcing application lifecycle management in SharePoint
Acing application lifecycle management in SharePoint
 
CodeIgniter for Startups, cicon2010
CodeIgniter for Startups, cicon2010CodeIgniter for Startups, cicon2010
CodeIgniter for Startups, cicon2010
 
Automated Acceptance Testing from Scratch
Automated Acceptance Testing from ScratchAutomated Acceptance Testing from Scratch
Automated Acceptance Testing from Scratch
 
DevOps and AWS - Code PaLOUsa 2017
DevOps and AWS  - Code PaLOUsa 2017DevOps and AWS  - Code PaLOUsa 2017
DevOps and AWS - Code PaLOUsa 2017
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
SharePoint Saturday Ottawa - From SharePoint to Office 365 Development
SharePoint Saturday Ottawa - From SharePoint to Office 365 DevelopmentSharePoint Saturday Ottawa - From SharePoint to Office 365 Development
SharePoint Saturday Ottawa - From SharePoint to Office 365 Development
 
Optimizing Test Coverage throughout the DevOps Pipeline
Optimizing Test Coverage throughout the DevOps PipelineOptimizing Test Coverage throughout the DevOps Pipeline
Optimizing Test Coverage throughout the DevOps Pipeline
 
Branding office 365 with front end tooling
Branding office 365 with front end toolingBranding office 365 with front end tooling
Branding office 365 with front end tooling
 
PyCon Ukraine 2014
PyCon Ukraine 2014PyCon Ukraine 2014
PyCon Ukraine 2014
 
Developer Night - Opticon18
Developer Night - Opticon18Developer Night - Opticon18
Developer Night - Opticon18
 
COMP 4026 Lecture3 Prototyping and Evaluation
COMP 4026 Lecture3 Prototyping and EvaluationCOMP 4026 Lecture3 Prototyping and Evaluation
COMP 4026 Lecture3 Prototyping and Evaluation
 
What Visual Studio Code can do for Java Development
What Visual Studio Code can do for Java DevelopmentWhat Visual Studio Code can do for Java Development
What Visual Studio Code can do for Java Development
 
Agile Methodologies
Agile MethodologiesAgile Methodologies
Agile Methodologies
 
SharePoint Fest Chicago - From SharePoint to Office 365 Development
SharePoint Fest Chicago - From SharePoint to Office 365 DevelopmentSharePoint Fest Chicago - From SharePoint to Office 365 Development
SharePoint Fest Chicago - From SharePoint to Office 365 Development
 

More from TSundberg

Selenium and-the-four-rules-of-simple-design
Selenium and-the-four-rules-of-simple-designSelenium and-the-four-rules-of-simple-design
Selenium and-the-four-rules-of-simple-design
TSundberg
 
Selenium and the Four Rules of Simple Design
Selenium and the Four Rules of Simple DesignSelenium and the Four Rules of Simple Design
Selenium and the Four Rules of Simple Design
TSundberg
 
Selenium and the Four Rules of-simple-design
Selenium and the Four Rules of-simple-designSelenium and the Four Rules of-simple-design
Selenium and the Four Rules of-simple-design
TSundberg
 

More from TSundberg (20)

How deep are your tests? Agile Cymru 2016
How deep are your tests? Agile Cymru 2016How deep are your tests? Agile Cymru 2016
How deep are your tests? Agile Cymru 2016
 
BDD with Cucumber-JVM - Nordic Testing Days 2016
BDD with Cucumber-JVM - Nordic Testing Days 2016BDD with Cucumber-JVM - Nordic Testing Days 2016
BDD with Cucumber-JVM - Nordic Testing Days 2016
 
Definition of done: Working software in production
Definition of done: Working software in productionDefinition of done: Working software in production
Definition of done: Working software in production
 
How deep are your test AT I T.A.K.E. Unconference 2016
How deep are your test AT I T.A.K.E. Unconference 2016How deep are your test AT I T.A.K.E. Unconference 2016
How deep are your test AT I T.A.K.E. Unconference 2016
 
How deep are your tests?
How deep are your tests?How deep are your tests?
How deep are your tests?
 
The Responsible Developer, Java Day, Kiev 2015
The Responsible Developer, Java Day, Kiev 2015The Responsible Developer, Java Day, Kiev 2015
The Responsible Developer, Java Day, Kiev 2015
 
Bdd with Cucumber-jvm. Java Day, Kiev 2015
Bdd with Cucumber-jvm. Java Day, Kiev 2015Bdd with Cucumber-jvm. Java Day, Kiev 2015
Bdd with Cucumber-jvm. Java Day, Kiev 2015
 
How to fail a project
How to fail a projectHow to fail a project
How to fail a project
 
Walking Skeleton I T.A.K.E. 2015
Walking Skeleton I T.A.K.E. 2015Walking Skeleton I T.A.K.E. 2015
Walking Skeleton I T.A.K.E. 2015
 
The Responsible Developer I T.A.K.E.2015
The Responsible Developer I T.A.K.E.2015The Responsible Developer I T.A.K.E.2015
The Responsible Developer I T.A.K.E.2015
 
Walking Skeleton as presented at ACCU 2015 in Bristol, England
Walking Skeleton as presented at ACCU 2015 in Bristol, EnglandWalking Skeleton as presented at ACCU 2015 in Bristol, England
Walking Skeleton as presented at ACCU 2015 in Bristol, England
 
Selenium and the Four Rules of Simple Design
Selenium and the Four Rules of Simple DesignSelenium and the Four Rules of Simple Design
Selenium and the Four Rules of Simple Design
 
Selenium and-the-four-rules-of-simple-design
Selenium and-the-four-rules-of-simple-designSelenium and-the-four-rules-of-simple-design
Selenium and-the-four-rules-of-simple-design
 
Selenium and the Four Rules of Simple Design
Selenium and the Four Rules of Simple DesignSelenium and the Four Rules of Simple Design
Selenium and the Four Rules of Simple Design
 
Selenium and the Four Rules of-simple-design
Selenium and the Four Rules of-simple-designSelenium and the Four Rules of-simple-design
Selenium and the Four Rules of-simple-design
 
Selenium and the Four Rules of Simple Design
Selenium and the Four Rules of Simple DesignSelenium and the Four Rules of Simple Design
Selenium and the Four Rules of Simple Design
 
Bdd with Cucumber-JVM
Bdd with Cucumber-JVMBdd with Cucumber-JVM
Bdd with Cucumber-JVM
 
The Responsible Developer - XP days Ukraine 2014
The Responsible Developer - XP days Ukraine 2014The Responsible Developer - XP days Ukraine 2014
The Responsible Developer - XP days Ukraine 2014
 
BDD with Cucumber-JVM as presented at JDD 2014 Krakow, Poland, 2014
BDD with Cucumber-JVM as presented at JDD 2014 Krakow, Poland, 2014BDD with Cucumber-JVM as presented at JDD 2014 Krakow, Poland, 2014
BDD with Cucumber-JVM as presented at JDD 2014 Krakow, Poland, 2014
 
The responsible-developer-thomas-sundberg-jdd-2014
The responsible-developer-thomas-sundberg-jdd-2014The responsible-developer-thomas-sundberg-jdd-2014
The responsible-developer-thomas-sundberg-jdd-2014
 

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
 

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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Selenium WebDriver - Test automation for web applications

  • 1. Selenium WebDriver Test automation for web applications
  • 2. Thomas Sundberg Stockholm, Sweden Think Code AB thomas@thinkcode.se @thomassundberg Blog: https://thomassundberg.wordpress.com/ Code: https://github.com/tsundberg/selenium-test- automation/tree/luxsoft-january-2015 © Think Code AB, http://www.thinkcode.se
  • 3. TESTING OF WEB APPLICATIONS © Think Code AB, http://www.thinkcode.se
  • 4. Testing of web applications • Introduction to testing • Manual testing • Automated testing • Selenium © Think Code AB, http://www.thinkcode.se
  • 5. Introduction • Why testing? • What to test? • When to test? • How to test? © Think Code AB, http://www.thinkcode.se
  • 6. Why testing? • Create confidence to release © Think Code AB, http://www.thinkcode.se
  • 7. Why release? • Create value • Reduce waste • Get feedback from real users – Was this what they wanted? © Think Code AB, http://www.thinkcode.se
  • 8. Create value • Using the software is the only way our users/customers can benefit from our work • This is the only reason why they pay us to create it © Think Code AB, http://www.thinkcode.se
  • 9. Reduce waste • Waste until it is used • Unused code is waste • Unreleased code is unused code • Waste until it is deployed © Think Code AB, http://www.thinkcode.se
  • 10. Feedback from real users • Is this was what they wanted? • Release early • Release often © Think Code AB, http://www.thinkcode.se
  • 11. When to test? • As soon as possible © Think Code AB, http://www.thinkcode.se
  • 12. Why? • Small problems are easy to fix • Young problems are small • Catch them before they grow up and become big problems – Large, old problems can be catastrophic © Think Code AB, http://www.thinkcode.se
  • 13. How to test? • Manual • Automated © Think Code AB, http://www.thinkcode.se
  • 14. Manual • Always through the user interface • Slow • Inconsistent • Doesn't scale • Will find new, interesting bugs © Think Code AB, http://www.thinkcode.se
  • 15. Automated • Different levels – User interface – Code • Faster • Consistent • Scales • Will never find new, interesting bugs © Think Code AB, http://www.thinkcode.se
  • 16. Manual vs. Automated • Manual test – Understand the problem – Know the application • Automated test – Understand the problem – Know the application – Programming © Think Code AB, http://www.thinkcode.se
  • 17. SELENIUM © Think Code AB, http://www.thinkcode.se
  • 18. Browser automation • Can be used for tests • Doesn’t have to be used for testing © Think Code AB, http://www.thinkcode.se
  • 19. Where does the name come from? • Selenium is a chemical element, Se • Treatment for Mercury poisoning • Mercury is a closed source web testing tool • Selenium is a cure for Mercury © Think Code AB, http://www.thinkcode.se
  • 20. Tests • Many frameworks • Test NG • Spock • JUnit • Others © Think Code AB, http://www.thinkcode.se
  • 21. Testing pyramid End to end Integration Unit Slow Faster Fast Many reasons to fail Many reasons to fail One reason to fail Faster is better Fewer reasons to fail is better © Think Code AB, http://www.thinkcode.se
  • 22. End to end • From the user interface • Very slow – It takes forever to start a browser and do something • Very fragile – Lots of reasons why a test will fail • The database is broken • The user interface is missing a component • Many more… © Think Code AB, http://www.thinkcode.se
  • 23. Doesn’t scale • Impossible to test all paths – 10 entrances from the ui – 5 paths through the controller – 7 paths through the model – 10 * 5 * 7 = 350 paths – 350 tests © Think Code AB, http://www.thinkcode.se
  • 24. Integration • Verify that components works together – Is the database properly configured? – Is the queue started? • Slow • Fragile – Many reasons to fail © Think Code AB, http://www.thinkcode.se
  • 25. Unit • Small pieces of functionality at a low level • Very fast • Stable – Only one reason to fail – Failures are easy to understand • Used for verifying all use cases for each implementation • Possible to verify all paths © Think Code AB, http://www.thinkcode.se
  • 26. Good tests • Must be easy to – Understand – Maintain – Change – Extend © Think Code AB, http://www.thinkcode.se
  • 27. Testing pyramid End to end Integration Unit Slow Faster Fast Many reasons to fail Many reasons to fail One reason to fail Faster is better Fewer reasons to fail is better © Think Code AB, http://www.thinkcode.se
  • 28. Inverted Testing pyramid End to end Integration Unit Slow Faster Fast Many reasons to fail Many reasons to fail One reason to fail Faster is better Fewer reasons to fail is better © Think Code AB, http://www.thinkcode.se
  • 29. Selenium echo system • Selenium IDE • Selenium WebDriver © Think Code AB, http://www.thinkcode.se
  • 30. Selenium IDE • Firefox plugin • Record and replay • If you want to – create quick bug reproduction scripts – create scripts to aid in automation-aided exploratory testing © Think Code AB, http://www.thinkcode.se
  • 31. Selenium WebDriver • A programming framework • Local in any browser you have installed – Open source – Anyone can use it • Many programming languages – We will use Java • If you want to – create robust, browser-based regression automation suites and tests – scale and distribute scripts across many environments © Think Code AB, http://www.thinkcode.se
  • 32. Selenium WebDriver • W3C standard – Not done, but well on its way • Every W3C browser must support WebDriver © Think Code AB, http://www.thinkcode.se
  • 33. Selenium Hub • Automate a browser remote • Enable us to do cross browser testing – Browser – Operating system © Think Code AB, http://www.thinkcode.se
  • 34. WebDriver remote • Same API as regular WebDriver – If it works local, you can execute it remote – SauceLabs © Think Code AB, http://www.thinkcode.se
  • 35. SELENIUM IDE © Think Code AB, http://www.thinkcode.se
  • 36. Hello, world! • http://selenium.thinkcode.se • Find an element and verify the text © Think Code AB, http://www.thinkcode.se
  • 37. Fill out a form • Change password © Think Code AB, http://www.thinkcode.se
  • 38. WHAT TO TEST? © Think Code AB, http://www.thinkcode.se
  • 39. What should you test? • Testing theatre • Test stuff that matters © Think Code AB, http://www.thinkcode.se
  • 40. Security theatre • Not aiming for security • Aim to make people feel safe • Security check on airports – Why do they take you water bottle? – If it is dangerous, remove it far away so it can't be dangerous for you © Think Code AB, http://www.thinkcode.se
  • 41. Don’t test everything • Enough to feel safe © Think Code AB, http://www.thinkcode.se
  • 42. Testing pyramid End to end Integration Unit © Think Code AB, http://www.thinkcode.se
  • 43. User interface • Do not test everything through the user interface • Test at the right level © Think Code AB, http://www.thinkcode.se
  • 44. End to end • Can you login? • Can you fail to log in? • Can you do a purchase? – At least place something in the shopping bag © Think Code AB, http://www.thinkcode.se
  • 45. Integration • Connect to the database • Connect to a queue © Think Code AB, http://www.thinkcode.se
  • 46. Unit level • Password algorithm © Think Code AB, http://www.thinkcode.se
  • 47. You must be in control • Collaborators • Mock or Stub © Think Code AB, http://www.thinkcode.se
  • 48. Database • Know about the content • Decide what the content should be • This makes End to end complicated © Think Code AB, http://www.thinkcode.se
  • 49. What should you automate? • Any test that should be repeated • At the right level... © Think Code AB, http://www.thinkcode.se
  • 50. What should you not automate? • Expensive tests – Buying using a credit card – Probably enough to do one manual test – Setup a fake server that mimics the payment service – http://wiremock.org © Think Code AB, http://www.thinkcode.se
  • 51. One off • If it truly exists • Automate it the second time © Think Code AB, http://www.thinkcode.se
  • 52. SELENIUM WEBDRIVER © Think Code AB, http://www.thinkcode.se
  • 53. First WebDriver test • Export the code from Selenium IDE – The code is ok – Not pretty – Ok to start with • Good for finding elements © Think Code AB, http://www.thinkcode.se
  • 54. Browser tools • Firebug • Firepath • Other favorites? © Think Code AB, http://www.thinkcode.se
  • 55. First handmade WebDriver test • Hello world • Without page object • With page object © Think Code AB, http://www.thinkcode.se
  • 56. Hand made is better • You have better control • You know what you did • Slower? – Maybe at first, but not in the long run © Think Code AB, http://www.thinkcode.se
  • 57. Page objects • Separation of navigation logic and test – Only need to change the page object when the layout changes – The tests remain unchanged if the logic is the same © Think Code AB, http://www.thinkcode.se
  • 58. Lazy • Hard to solve a hard problem • Better to solve many small © Think Code AB, http://www.thinkcode.se
  • 59. One class per page • Abstracts the page functionality • Hide the page navigation © Think Code AB, http://www.thinkcode.se
  • 60. Simplifies the tests • The test focus on WHAT the application should do • Not on HOW • Behavior is interesting © Think Code AB, http://www.thinkcode.se
  • 61. Supply the browser • Through the constructor – Allow you to use the same page object with different browsers • Verify that the current page is the right page – Check title or similar characteristics • Throw an exception if you can’t verify the page © Think Code AB, http://www.thinkcode.se
  • 62. assertThat • Signals through exception • assertThat(actaulTitle, is(expectedTitle)); © Think Code AB, http://www.thinkcode.se
  • 63. Example - Check boxes http://selenium.thinkcode.se/selectColor.html © Think Code AB, http://www.thinkcode.se
  • 64. Test organization By technology By functional area © Think Code AB, http://www.thinkcode.se
  • 65. Test organization • Separate on functional areas • Do not separate on technology – A new developer want to find the relevant test and page objects fast • All tests and page object for a certain area should live in the same package © Think Code AB, http://www.thinkcode.se
  • 66. Selenium echo system • Selenium IDE – Firefox plugin • WebDriver – Programming api • Selenium hub – Remote – Different browsers – Different operating systems © Think Code AB, http://www.thinkcode.se
  • 67. Testing pyramid End to end Integration Unit © Think Code AB, http://www.thinkcode.se
  • 68. Test things at the right level • End to end • Integration • Unit
  • 69. End to end • Verify that the system is alive • Most crucial flow – Buy a product – Book a trip • Very slow • Lots of reasons to fail © Think Code AB, http://www.thinkcode.se
  • 70. Integration • Slow • Many reasons to fail • Doesn’t scale © Think Code AB, http://www.thinkcode.se
  • 71. Unit • Fast • Only one reason to fail • Algorithms • Password © Think Code AB, http://www.thinkcode.se
  • 72. Testing theater • Verifying important parts in the system • Not for satisfying a managers metric © Think Code AB, http://www.thinkcode.se
  • 73. WebDriver • close() • findElement(By by) • findElements(By by) • get(java.lang.String url) • getCurrentUrl() • getPageSource() • getTitle() • getWindowHandle() • getWindowHandles() • manage() • navigate() • quit() • switchTo() © Think Code AB, http://www.thinkcode.se
  • 74. Locators • By.id(java.lang.String id) – The preferred locater if the IDs are unique • By.name(java.lang.String name) – Almost as good as ID, if the name is unique • By.xpath(java.lang.String xpathExpression) – Depends on the page structure • By.cssSelector(java.lang.String selector) – Finds elements via the driver's underlying W3 Selector engine. • By.linkText(java.lang.String linkText) – Complicated if your site supports many languages • By.partialLinkText(java.lang.String linkText) – Complicated if your site supports many languages • By.tagName(java.lang.String name) – Probably not a unique element, all h1 • By.className(java.lang.String className) – Finds elements based on the value of the class attribute. © Think Code AB, http://www.thinkcode.se
  • 75. WebElement • clear() • click() • findElement(By by) • findElements(By by) • getAttribute(java.lang.String name) • getCssValue(java.lang.String propertyName) • getLocation() • getSize() • getTagName() • getText() • isDisplayed() • isEnabled() • isSelected() • sendKeys(java.lang.CharSequence... keysToSend) • submit() © Think Code AB, http://www.thinkcode.se
  • 76. Page objects • Separate navigation and logic • Clearer and easier tests • Supply the browser • Verify the correct page © Think Code AB, http://www.thinkcode.se
  • 77. Interested in more? Join me in Timisoara, Romania in April for A two day, in depth, Selenium course. http://mozaicworks.com/public-trainings-and-workshops/selenium-webdriver-test-automation-for-web-applications/ © Think Code AB, http://www.thinkcode.se
  • 78. Thomas Sundberg Stockholm, Sweden Think Code AB thomas@thinkcode.se @thomassundberg Blog: https://thomassundberg.wordpress.com/ Code: https://github.com/tsundberg/selenium-test- automation/tree/luxsoft-january-2015 © Think Code AB, http://www.thinkcode.se

Editor's Notes

  1. Show a record and re-play session. Have the participants to do the same thing
  2. Record and replay a change password scenario
  3. Implement an example and have the participants to do it as well