SlideShare a Scribd company logo
Improving Your Selenium
WebDriver Tests
Roy de Kleijn
Technical Test Consultant
Email: roy.dekleijn@the-future-group.com
Twitter: @TheWebTester
Website: http://www.rdekleijn.nl
Github: https://github.com/roydekleijn
Question #1
What makes your Selenium WebDriver tests suck?
Answer #1
Depending on third-party data
Synchronization issues
Cross-browser issues
Hard to locate elements
testdata
Slow feedback cycle
Flaky tests
High maintenance costs
Lack of confidence
Results in …
Contents
• Introduction
• Element locator tips & tricks
• Implementing the Page Object Model
• Utilize Data Objects
• Handle synchronization
• Speed-up and stabilize your tests (demo)
• What we have learned
We will start with an actual Page Object Model implementation today
Maintenance test
Maintenanceeffort
Time
Reality: code ends up into unmaintainable spaghetti
wish
Testing Pyramid
unit
UI
API
feedback-cycle
- Extremely fast
- Smallest units of the application / isolates failure
- Executed during build time
- No dependency on data
- Extremely slow
- Requires running application
- Will change frequently
- Dependency on data
- Fast
- Covering boundary conditions
- Start early in SD process
- Requires running application
- (some) dependency on data
Mock External Interfaces
application
Interface 1
Interface 2
Interface 3
application
Interface 1
Interface 2
Interface 3
mock
Contents
• Introduction
• Element locator tips & tricks
• Implementing the Page Object Model
• Utilize Data Objects
• Handle synchronization
• Speed-up and stabilize your tests (demo)
• What we have learned
We will start with an actual Page Object Model implementation today
Question #2
What is wrong with these locators?
#1
.//*[@id='wx-header-wrap']/div/div/div/div[2]/div[2]/div/section/div/form/input
#2
.//*[@id='gnav-header-inner']/div/ul/li[2]/a
Answer #2
They contain too much information about the location
Closer look #1
Closer look #1
.//*[@id='wx-header-wrap']/div/div/div/div[2]/div[2]/div/section/div/form/input
What if the location of this element will change over time?
It can be written like this:
input[class = ‘input--search’]
Or
input.input—search
Or
input[name = ‘search’]
Closer look #2
Closer look #2
.//*[@id='gnav-header-inner']/div/ul/li[2]/a
What if the order of the links will change over time ?
It can be written like this:
a[id=register]
Or
a#register
Attribute selectors
css xpath
Equals e[a=v] //e[@a=v]
Contains e[a*=v] //e[contains(@a, ‘v’)]
Starts-with e[a^=v] //e[starts-with(@a,
‘v’)]
Ends-with e[a$=v] //e[ends-with(@a, ‘v’)]
AngularJS - elements
• Different way of locating elements
• Binding
• Model
• Repeat
• ngWebDriver library (create by Paul Hammant)
• https://github.com/paul-hammant/ngWebDriver
• Logic from Protractor project
• Enable debug info
• Call angular.reloadWithDebugInfo(); in your browser debug console
• Execute the following snippet to reveal all the elements:
var bindings = document.getElementsByClassName('ng-binding');
for (var i = 0; i < bindings.length; ++i) {
var bindingName = angular.element(bindings[i]).data().$binding[0].exp
||angular.element(bindings[i]).data().$binding;
console.log(bindingName.toString());
console.log(bindings[i]);
}
Contents
• Introduction
• Element locator tips & tricks
• Implementing the Page Object Model
• Utilize Data Objects
• Handle synchronization
• Speed-up and stabilize your tests (demo)
• What we have learned
We will start with an actual Page Object Model implementation today
Problems that arise
• Unmaintainable
• Unreadable test scripts
• Creation of test scripts is time consuming
• Code duplication
From problem to solution
Solution
Each page contains only a part of the total functionality available on
the website
Put page specific functionality in a class with a corresponding name
Step-by-step plan
1. Identify necessary WebElements
2. Create a class
3. Define WebElements in corresponding classes
4. Model the functionality of a page into methods
5. Model the page flow by setting returntypes
Identify necessary WebElements
Create a class
A class with the name of the page extending from
LoadableComponent
public class HomePage extends LoadableComponent<HomePage> {
private WebDriver driver;
public HomePage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
Define WebElements
On class level (above the methods)
@FindBy(css = "a.login")
private WebElement loginLink;
Model the functionality
public LoginPage clickOnLoginLink() {
loginLink.click();
return new LoginPage(driver);
}
Model the page flow
• Prerequisite:
• Multiple pages are modelled
• Modify returntype
• The returntype is the name of the page (class) where you are navigating
towards
• Use the current class name, if you stay on the same page
Model the page flow
public LoginPage clickOnLoginLink() {
loginLink.click();
return new LoginPage(driver);
}
Returning page
Contents
• Introduction
• Element locator tips & tricks
• Implementing the Page Object Model
• Utilize Data Objects
• Handle synchronization
• Speed-up and stabilize your tests (demo)
• What we have learned
We will start with an actual Page Object Model implementation today
Data Objects
final CustomerAccount account = new
CustomerAccount.CustomerAccountBuilder("test@test.com","1qazxsw2").build();
Access data:
account.getEmail()
account.getPassword()
Data Objects - Complex
final Order order = new Order.OrderBuilder()//
.withInvoiceAddress(new Address.AddressBuilder("abc street", "1234ab").build())//
.withShippingAddress(new Address.AddressBuilder("shipstreet”,
"4321ab").withCountry("The Netherlands").build())//
.build();
// Retrieve data from the object
System.out.println(order.getInvoiceAddress().getStreet());
System.out.println(order.getShippingAddress().getCountry());
Contents
• Introduction
• Element locator tips & tricks
• Implementing the Page Object Model
• Utilize Data Objects
• Handle synchronization
• Speed-up and stabilize your tests (demo)
• What we have learned
We will start with an actual Page Object Model implementation today
Synchronization issues
• Browser has to start
• Page has to load
• AJAX request need to be finished
• Or, loader should be gone before we can continue
What NOT to do …
NEVER, use Thread.sleep();
• It will probably make your test unnecessary slow
• You never know if you wait exactly long enough
What to do…
• WebDriver build in wait mechanisms
• implicitlyWait: poll till element is present
• setScriptTimeout: time to wait for an asynchronous script to finish
• pageLoadTimeout: time to wait for a page load to complete
• ngWebDriver
• waitForAngularRequestsToFinish – wait for outstanding angular requests
• Custom (gist)
• checkPendingRequests – wait for all HTTP requests to be finished
Example 1
Wait for element to be clickable
@Test
public void waitForElementToBeClickable() {
new WebDriverWait(driver, 20,100) //
.until(ExpectedConditions.elementToBeClickable(
By.cssSelector("a.login")));
}
Example 2
Wait for loader to be invisible
@Test
public void waitForElementNotToBeVisable() {
new WebDriverWait(driver, 20, 100) //
.until(ExpectedConditions.invisibilityOfElementLocated(
By.cssSelector("loader")));
}
Contents
• Introduction
• Element locator tips & tricks
• Implementing the Page Object Model
• Utilize Data Objects
• Handle synchronization
• Speed-up and stabilize your tests (demo)
• What we have learned
We will start with an actual Page Object Model implementation today
Speed-up and stabilize your tests
Windows 7
IE
FF
Chrome
Windows vista
IE
FF
Ubuntu
FF
Opera
Mac OS
FF
Chrome
Opera
…
Nodes
Hub
Specification
HUB
Test Scripts
Docker Selenium
• Disposable Selenium Grid (in seconds)
• Autoscaling features
• https://hub.docker.com/r/selenium/
Docker-compose
seleniumhub:
image: selenium/hub
ports:
- 4444:4444
firefoxnode:
image: selenium/node-firefox
environment:
SCREEN_WIDTH: 2880
SCREEN_HEIGHT: 1800
ports:
- 5900
links:
- seleniumhub:hub
chromenode:
image: selenium/node-chrome
environment:
SCREEN_WIDTH: 2880
SCREEN_HEIGHT: 1800
ports:
- 5900
links:
- seleniumhub:hub
Docker commands
docker-compose up –d
-d: Run containers in the background
--force-recreate: Recreate containers entirely
Autoscaling:
docker-compose scale firefoxnode=5 chromenode=1
In practice
Implement or extend the Page Object Model
• Website
• url: http://demo.technisch-testen.nl
• Source
• Github: https://github.com/roydekleijn/webdriver-workshop
Contents
• Introduction
• Element locator tips & tricks
• Implementing the Page Object Model
• Utilize Data Objects
• Handle synchronization
• Speed-up and stabilize your tests (demo)
• What we have learned
We will start with an actual Page Object Model implementation today
What we have learned today
Depending on third-party data
Cross-browser issues
Hard to locate elements
testdata
Slow feedback cycle
Flaky tests
High maintenance costs
Synchronization issues
Avoid Thread.sleep()
or other hardcoded
waits
Utilize Page Object
Model
id > name > css >
xpath > angular
Mock interfaces
Run tests in parallel
Mock interfaces
Mock interfaces, setup
clean environments,
implement page object
model
Thank you…
Roy de Kleijn
Technical Test Consultant
Email: roy.dekleijn@the-future-group.com
Twitter: @TheWebTester
Website: http://www.rdekleijn.nl
Github: https://github.com/roydekleijn

More Related Content

What's hot

Alfresco/Activiti Modeler Application - Andras Popovics - 2019
Alfresco/Activiti Modeler Application - Andras Popovics - 2019Alfresco/Activiti Modeler Application - Andras Popovics - 2019
Alfresco/Activiti Modeler Application - Andras Popovics - 2019
András Popovics
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
Yakov Fain
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Final
guestcd4688
 
Debugging your Way through .NET with Visual Studio 2015
Debugging your Way through .NET with Visual Studio 2015Debugging your Way through .NET with Visual Studio 2015
Debugging your Way through .NET with Visual Studio 2015
Ido Flatow
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
Eamonn Boyle
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
Jennifer Estrada
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
Stacy Goh
 
Serverless with Azure Functions
Serverless with Azure FunctionsServerless with Azure Functions
Serverless with Azure Functions
Andreas Willich
 
Embracing HTTP in the era of API’s
Embracing HTTP in the era of API’sEmbracing HTTP in the era of API’s
Embracing HTTP in the era of API’s
Visug
 
Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...
Maarten Balliauw
 
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris O'Brien
 
JavaFX Versus HTML5 - JavaOne 2014
JavaFX Versus HTML5 - JavaOne 2014JavaFX Versus HTML5 - JavaOne 2014
JavaFX Versus HTML5 - JavaOne 2014
Ryan Cuprak
 
Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5
Stephen Chin
 
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
Sencha
 
Moving To The Client - JavaFX and HTML5
Moving To The Client - JavaFX and HTML5Moving To The Client - JavaFX and HTML5
Moving To The Client - JavaFX and HTML5
Stephen Chin
 
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
Dakiry
 
Building mobile applications with Vaadin TouchKit
Building mobile applications with Vaadin TouchKitBuilding mobile applications with Vaadin TouchKit
Building mobile applications with Vaadin TouchKit
Sami Ekblad
 
Moving to the Client - JavaFX and HTML5 (PowerPoint Version)
Moving to the Client - JavaFX and HTML5 (PowerPoint Version)Moving to the Client - JavaFX and HTML5 (PowerPoint Version)
Moving to the Client - JavaFX and HTML5 (PowerPoint Version)
Stephen Chin
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
NexThoughts Technologies
 
O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...
O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...
O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...
NCCOMMS
 

What's hot (20)

Alfresco/Activiti Modeler Application - Andras Popovics - 2019
Alfresco/Activiti Modeler Application - Andras Popovics - 2019Alfresco/Activiti Modeler Application - Andras Popovics - 2019
Alfresco/Activiti Modeler Application - Andras Popovics - 2019
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in Angular
 
Esri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc FinalEsri Dev Summit 2009 Rest and Mvc Final
Esri Dev Summit 2009 Rest and Mvc Final
 
Debugging your Way through .NET with Visual Studio 2015
Debugging your Way through .NET with Visual Studio 2015Debugging your Way through .NET with Visual Studio 2015
Debugging your Way through .NET with Visual Studio 2015
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 
Serverless with Azure Functions
Serverless with Azure FunctionsServerless with Azure Functions
Serverless with Azure Functions
 
Embracing HTTP in the era of API’s
Embracing HTTP in the era of API’sEmbracing HTTP in the era of API’s
Embracing HTTP in the era of API’s
 
Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...
 
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
Chris OBrien - Pitfalls when developing with the SharePoint Framework (SPFx)
 
JavaFX Versus HTML5 - JavaOne 2014
JavaFX Versus HTML5 - JavaOne 2014JavaFX Versus HTML5 - JavaOne 2014
JavaFX Versus HTML5 - JavaOne 2014
 
Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5Moving to the Client - JavaFX and HTML5
Moving to the Client - JavaFX and HTML5
 
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
 
Moving To The Client - JavaFX and HTML5
Moving To The Client - JavaFX and HTML5Moving To The Client - JavaFX and HTML5
Moving To The Client - JavaFX and HTML5
 
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
 
Building mobile applications with Vaadin TouchKit
Building mobile applications with Vaadin TouchKitBuilding mobile applications with Vaadin TouchKit
Building mobile applications with Vaadin TouchKit
 
Moving to the Client - JavaFX and HTML5 (PowerPoint Version)
Moving to the Client - JavaFX and HTML5 (PowerPoint Version)Moving to the Client - JavaFX and HTML5 (PowerPoint Version)
Moving to the Client - JavaFX and HTML5 (PowerPoint Version)
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...
O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...
O365Con18 - Connect SharePoint Framework Solutions to API's secured with Azur...
 

Viewers also liked

Load Testing: See a Bigger Picture
Load Testing: See a Bigger PictureLoad Testing: See a Bigger Picture
Load Testing: See a Bigger Picture
Alexander Podelko
 
Performance testing: respect the difference at swqd14
Performance testing: respect the difference at swqd14Performance testing: respect the difference at swqd14
Performance testing: respect the difference at swqd14
Alexander Podelko
 
Performance: See the Whole Picture
Performance: See the Whole PicturePerformance: See the Whole Picture
Performance: See the Whole Picture
Alexander Podelko
 
Performance Assurance for Packaged Applications
Performance Assurance for Packaged ApplicationsPerformance Assurance for Packaged Applications
Performance Assurance for Packaged Applications
Alexander Podelko
 
Performance Requirements: the Backbone of the Performance Engineering Process
Performance Requirements: the Backbone of the Performance Engineering ProcessPerformance Requirements: the Backbone of the Performance Engineering Process
Performance Requirements: the Backbone of the Performance Engineering Process
Alexander Podelko
 
A Short History of Performance Engineering
A Short History of Performance EngineeringA Short History of Performance Engineering
A Short History of Performance Engineering
Alexander Podelko
 
Load Testing: See a Bigger Picture, ALM Forum, 2014
Load Testing: See a Bigger Picture, ALM Forum, 2014Load Testing: See a Bigger Picture, ALM Forum, 2014
Load Testing: See a Bigger Picture, ALM Forum, 2014
Alexander Podelko
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for Testing
Mukta Aphale
 
A Short History of Performance Engineering
A Short History of Performance EngineeringA Short History of Performance Engineering
A Short History of Performance Engineering
Alexander Podelko
 
Tools of the Trade: Load Testing - Ignite session at WebPerfDays NY 14
Tools of the Trade: Load Testing -  Ignite session at WebPerfDays NY 14Tools of the Trade: Load Testing -  Ignite session at WebPerfDays NY 14
Tools of the Trade: Load Testing - Ignite session at WebPerfDays NY 14
Alexander Podelko
 
September_08 SQuAd Presentation
September_08 SQuAd PresentationSeptember_08 SQuAd Presentation
September_08 SQuAd Presentation
iradari
 

Viewers also liked (11)

Load Testing: See a Bigger Picture
Load Testing: See a Bigger PictureLoad Testing: See a Bigger Picture
Load Testing: See a Bigger Picture
 
Performance testing: respect the difference at swqd14
Performance testing: respect the difference at swqd14Performance testing: respect the difference at swqd14
Performance testing: respect the difference at swqd14
 
Performance: See the Whole Picture
Performance: See the Whole PicturePerformance: See the Whole Picture
Performance: See the Whole Picture
 
Performance Assurance for Packaged Applications
Performance Assurance for Packaged ApplicationsPerformance Assurance for Packaged Applications
Performance Assurance for Packaged Applications
 
Performance Requirements: the Backbone of the Performance Engineering Process
Performance Requirements: the Backbone of the Performance Engineering ProcessPerformance Requirements: the Backbone of the Performance Engineering Process
Performance Requirements: the Backbone of the Performance Engineering Process
 
A Short History of Performance Engineering
A Short History of Performance EngineeringA Short History of Performance Engineering
A Short History of Performance Engineering
 
Load Testing: See a Bigger Picture, ALM Forum, 2014
Load Testing: See a Bigger Picture, ALM Forum, 2014Load Testing: See a Bigger Picture, ALM Forum, 2014
Load Testing: See a Bigger Picture, ALM Forum, 2014
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for Testing
 
A Short History of Performance Engineering
A Short History of Performance EngineeringA Short History of Performance Engineering
A Short History of Performance Engineering
 
Tools of the Trade: Load Testing - Ignite session at WebPerfDays NY 14
Tools of the Trade: Load Testing -  Ignite session at WebPerfDays NY 14Tools of the Trade: Load Testing -  Ignite session at WebPerfDays NY 14
Tools of the Trade: Load Testing - Ignite session at WebPerfDays NY 14
 
September_08 SQuAd Presentation
September_08 SQuAd PresentationSeptember_08 SQuAd Presentation
September_08 SQuAd Presentation
 

Similar to Improving Your Selenium WebDriver Tests - Belgium testing days_2016

SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...Liam Cleary [MVP]
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testingdrewz lin
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
Agile Testing Alliance
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
Mike Wilcox
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
Ben Hall
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
Mark Rackley
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
TEST Huddle
 
The MEAN stack
The MEAN stack The MEAN stack
The MEAN stack
Nattaya Mairittha
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
Gill Cleeren
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
SPTechCon
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
Timothy Fisher
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
Mek Srunyu Stittri
 
Better End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using ProtractorBetter End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using Protractor
Kasun Kodagoda
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
Ortus Solutions, Corp
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnetVlad Maniak
 
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
SPTechCon
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
Wojciech Seliga
 

Similar to Improving Your Selenium WebDriver Tests - Belgium testing days_2016 (20)

SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
The MEAN stack
The MEAN stack The MEAN stack
The MEAN stack
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
 
Better End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using ProtractorBetter End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using Protractor
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Selenium withnet
Selenium withnetSelenium withnet
Selenium withnet
 
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 2: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
 

Recently uploaded

Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 

Recently uploaded (20)

Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 

Improving Your Selenium WebDriver Tests - Belgium testing days_2016

  • 1. Improving Your Selenium WebDriver Tests Roy de Kleijn Technical Test Consultant Email: roy.dekleijn@the-future-group.com Twitter: @TheWebTester Website: http://www.rdekleijn.nl Github: https://github.com/roydekleijn
  • 2. Question #1 What makes your Selenium WebDriver tests suck?
  • 3. Answer #1 Depending on third-party data Synchronization issues Cross-browser issues Hard to locate elements testdata Slow feedback cycle Flaky tests High maintenance costs
  • 5. Contents • Introduction • Element locator tips & tricks • Implementing the Page Object Model • Utilize Data Objects • Handle synchronization • Speed-up and stabilize your tests (demo) • What we have learned We will start with an actual Page Object Model implementation today
  • 6. Maintenance test Maintenanceeffort Time Reality: code ends up into unmaintainable spaghetti wish
  • 7. Testing Pyramid unit UI API feedback-cycle - Extremely fast - Smallest units of the application / isolates failure - Executed during build time - No dependency on data - Extremely slow - Requires running application - Will change frequently - Dependency on data - Fast - Covering boundary conditions - Start early in SD process - Requires running application - (some) dependency on data
  • 8. Mock External Interfaces application Interface 1 Interface 2 Interface 3 application Interface 1 Interface 2 Interface 3 mock
  • 9. Contents • Introduction • Element locator tips & tricks • Implementing the Page Object Model • Utilize Data Objects • Handle synchronization • Speed-up and stabilize your tests (demo) • What we have learned We will start with an actual Page Object Model implementation today
  • 10. Question #2 What is wrong with these locators? #1 .//*[@id='wx-header-wrap']/div/div/div/div[2]/div[2]/div/section/div/form/input #2 .//*[@id='gnav-header-inner']/div/ul/li[2]/a
  • 11. Answer #2 They contain too much information about the location
  • 13. Closer look #1 .//*[@id='wx-header-wrap']/div/div/div/div[2]/div[2]/div/section/div/form/input What if the location of this element will change over time? It can be written like this: input[class = ‘input--search’] Or input.input—search Or input[name = ‘search’]
  • 15. Closer look #2 .//*[@id='gnav-header-inner']/div/ul/li[2]/a What if the order of the links will change over time ? It can be written like this: a[id=register] Or a#register
  • 16. Attribute selectors css xpath Equals e[a=v] //e[@a=v] Contains e[a*=v] //e[contains(@a, ‘v’)] Starts-with e[a^=v] //e[starts-with(@a, ‘v’)] Ends-with e[a$=v] //e[ends-with(@a, ‘v’)]
  • 17. AngularJS - elements • Different way of locating elements • Binding • Model • Repeat • ngWebDriver library (create by Paul Hammant) • https://github.com/paul-hammant/ngWebDriver • Logic from Protractor project
  • 18. • Enable debug info • Call angular.reloadWithDebugInfo(); in your browser debug console • Execute the following snippet to reveal all the elements: var bindings = document.getElementsByClassName('ng-binding'); for (var i = 0; i < bindings.length; ++i) { var bindingName = angular.element(bindings[i]).data().$binding[0].exp ||angular.element(bindings[i]).data().$binding; console.log(bindingName.toString()); console.log(bindings[i]); }
  • 19. Contents • Introduction • Element locator tips & tricks • Implementing the Page Object Model • Utilize Data Objects • Handle synchronization • Speed-up and stabilize your tests (demo) • What we have learned We will start with an actual Page Object Model implementation today
  • 20. Problems that arise • Unmaintainable • Unreadable test scripts • Creation of test scripts is time consuming • Code duplication
  • 21. From problem to solution
  • 22. Solution Each page contains only a part of the total functionality available on the website Put page specific functionality in a class with a corresponding name
  • 23. Step-by-step plan 1. Identify necessary WebElements 2. Create a class 3. Define WebElements in corresponding classes 4. Model the functionality of a page into methods 5. Model the page flow by setting returntypes
  • 25. Create a class A class with the name of the page extending from LoadableComponent public class HomePage extends LoadableComponent<HomePage> { private WebDriver driver; public HomePage(WebDriver driver) { this.driver = driver; PageFactory.initElements(driver, this); }
  • 26. Define WebElements On class level (above the methods) @FindBy(css = "a.login") private WebElement loginLink;
  • 27. Model the functionality public LoginPage clickOnLoginLink() { loginLink.click(); return new LoginPage(driver); }
  • 28. Model the page flow • Prerequisite: • Multiple pages are modelled • Modify returntype • The returntype is the name of the page (class) where you are navigating towards • Use the current class name, if you stay on the same page
  • 29. Model the page flow public LoginPage clickOnLoginLink() { loginLink.click(); return new LoginPage(driver); } Returning page
  • 30. Contents • Introduction • Element locator tips & tricks • Implementing the Page Object Model • Utilize Data Objects • Handle synchronization • Speed-up and stabilize your tests (demo) • What we have learned We will start with an actual Page Object Model implementation today
  • 31. Data Objects final CustomerAccount account = new CustomerAccount.CustomerAccountBuilder("test@test.com","1qazxsw2").build(); Access data: account.getEmail() account.getPassword()
  • 32. Data Objects - Complex final Order order = new Order.OrderBuilder()// .withInvoiceAddress(new Address.AddressBuilder("abc street", "1234ab").build())// .withShippingAddress(new Address.AddressBuilder("shipstreet”, "4321ab").withCountry("The Netherlands").build())// .build(); // Retrieve data from the object System.out.println(order.getInvoiceAddress().getStreet()); System.out.println(order.getShippingAddress().getCountry());
  • 33. Contents • Introduction • Element locator tips & tricks • Implementing the Page Object Model • Utilize Data Objects • Handle synchronization • Speed-up and stabilize your tests (demo) • What we have learned We will start with an actual Page Object Model implementation today
  • 34. Synchronization issues • Browser has to start • Page has to load • AJAX request need to be finished • Or, loader should be gone before we can continue
  • 35. What NOT to do … NEVER, use Thread.sleep(); • It will probably make your test unnecessary slow • You never know if you wait exactly long enough
  • 36. What to do… • WebDriver build in wait mechanisms • implicitlyWait: poll till element is present • setScriptTimeout: time to wait for an asynchronous script to finish • pageLoadTimeout: time to wait for a page load to complete • ngWebDriver • waitForAngularRequestsToFinish – wait for outstanding angular requests • Custom (gist) • checkPendingRequests – wait for all HTTP requests to be finished
  • 37. Example 1 Wait for element to be clickable @Test public void waitForElementToBeClickable() { new WebDriverWait(driver, 20,100) // .until(ExpectedConditions.elementToBeClickable( By.cssSelector("a.login"))); }
  • 38. Example 2 Wait for loader to be invisible @Test public void waitForElementNotToBeVisable() { new WebDriverWait(driver, 20, 100) // .until(ExpectedConditions.invisibilityOfElementLocated( By.cssSelector("loader"))); }
  • 39. Contents • Introduction • Element locator tips & tricks • Implementing the Page Object Model • Utilize Data Objects • Handle synchronization • Speed-up and stabilize your tests (demo) • What we have learned We will start with an actual Page Object Model implementation today
  • 40. Speed-up and stabilize your tests Windows 7 IE FF Chrome Windows vista IE FF Ubuntu FF Opera Mac OS FF Chrome Opera … Nodes Hub Specification HUB Test Scripts
  • 41. Docker Selenium • Disposable Selenium Grid (in seconds) • Autoscaling features • https://hub.docker.com/r/selenium/
  • 42. Docker-compose seleniumhub: image: selenium/hub ports: - 4444:4444 firefoxnode: image: selenium/node-firefox environment: SCREEN_WIDTH: 2880 SCREEN_HEIGHT: 1800 ports: - 5900 links: - seleniumhub:hub chromenode: image: selenium/node-chrome environment: SCREEN_WIDTH: 2880 SCREEN_HEIGHT: 1800 ports: - 5900 links: - seleniumhub:hub
  • 43. Docker commands docker-compose up –d -d: Run containers in the background --force-recreate: Recreate containers entirely Autoscaling: docker-compose scale firefoxnode=5 chromenode=1
  • 44. In practice Implement or extend the Page Object Model • Website • url: http://demo.technisch-testen.nl • Source • Github: https://github.com/roydekleijn/webdriver-workshop
  • 45. Contents • Introduction • Element locator tips & tricks • Implementing the Page Object Model • Utilize Data Objects • Handle synchronization • Speed-up and stabilize your tests (demo) • What we have learned We will start with an actual Page Object Model implementation today
  • 46. What we have learned today Depending on third-party data Cross-browser issues Hard to locate elements testdata Slow feedback cycle Flaky tests High maintenance costs Synchronization issues Avoid Thread.sleep() or other hardcoded waits Utilize Page Object Model id > name > css > xpath > angular Mock interfaces Run tests in parallel Mock interfaces Mock interfaces, setup clean environments, implement page object model
  • 47. Thank you… Roy de Kleijn Technical Test Consultant Email: roy.dekleijn@the-future-group.com Twitter: @TheWebTester Website: http://www.rdekleijn.nl Github: https://github.com/roydekleijn

Editor's Notes

  1. Selenium WebDriver is a popular tool for driving the browsers for test automation. Many companies with browser-based applications have taken steps towards including Selenium WebDriver in their repertoire. There’s also a lot of reports on challenges: brittleness of tests with tests passing and failing randomly, trouble with maintenance as the test suites get bigger and difficulties working with Angular or Ajax enriched applications. If you can’t trust your tests, maintaining them takes a lot of time or your application feels to disagree with being easy to test, your tests might not be adding value. In this workshop, we focus on Selenium WebDriver tests as code, and look into practices to overcome these common problems. We start with existing tests on an open source application, and we change them through refactoring to improve them. Join this session to improve your ability to create more maintainable and valuable tests with Selenium WebDriver.
  2. Let me start with a question..
  3. In this workshop we are going to cover some of these topics - Some of these answers are highly related to each other and can be resolved in one go..
  4. Some time ago I have drawn a graph of how a project evolves over time.
  5. Tests bevatten veel driver specieke syntax, waardoor je onleesbare scripts krijgt. Het maken van scripts duurt vrij lang en wordt als lastig ervaren
  6. Hoe kom je nu tot deze oplossing. Ik heb een 4 stappenplan bedacht om tot een werkbare abstractie te komen. In sommige gevallen kan het wenselijk zijn om voor een hoger abstractie niveau te kiezen. (als bijvoorbeeld veel functionaliteit op de website hetzelfde is en de pagina’s erg op elkaar lijken). Je kan dan “parent classes” maken en deze laten erfen. OF Maken van veel voorkomende componenten en deze gebruiken op de specifieke pagina’s.
  7. Voorbeeld van een loginscript van Wehkamp.nl
  8. Zoals we eerder hebben gezien kunnen we webelementen benaderen aan de hand van een locator. Het is aan te raden om deze 1x boven in de class te definieren. De logische naam (tweede regel) kun je dan gebruiken in alle onderliggende methodes. Dit bevorderd de onderhoudbaarheid, omdat je de naam van de locator maar op 1 plek hoeft aan te passen bij een wijziging.
  9. Het idee is om methoded te maken die de functionaliteit van de pagine representeren. Er kan voor gekozen worden om meerdere acties te groeperen in 1 functie. Dit hangt samen met het soort test cases dat gemaakt gaat worden.
  10. Zie vorige sheet.
  11. Why we do this ?? To speed up testing, to be able to run more tests in parallel We need to do this carefully, because data can change the state of the application and will influence other tests
  12. Selenium WebDriver is a popular tool for driving the browsers for test automation. Many companies with browser-based applications have taken steps towards including Selenium WebDriver in their repertoire. There’s also a lot of reports on challenges: brittleness of tests with tests passing and failing randomly, trouble with maintenance as the test suites get bigger and difficulties working with Angular or Ajax enriched applications. If you can’t trust your tests, maintaining them takes a lot of time or your application feels to disagree with being easy to test, your tests might not be adding value. In this workshop, we focus on Selenium WebDriver tests as code, and look into practices to overcome these common problems. We start with existing tests on an open source application, and we change them through refactoring to improve them. Join this session to improve your ability to create more maintainable and valuable tests with Selenium WebDriver.