SlideShare une entreprise Scribd logo
1  sur  47
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

Contenu connexe

Tendances

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 - 2019András Popovics
 
Web sockets in Angular
Web sockets in AngularWeb sockets in Angular
Web sockets in AngularYakov 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 Finalguestcd4688
 
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 2015Ido Flatow
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesEamonn 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 SPAsJennifer Estrada
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshopStacy Goh
 
Serverless with Azure Functions
Serverless with Azure FunctionsServerless with Azure Functions
Serverless with Azure FunctionsAndreas 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’sVisug
 
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 2014Ryan 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 HTML5Stephen 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 HTML5Stephen 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 TouchKitSami 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
 
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
 

Tendances (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...
 

En vedette

Load Testing: See a Bigger Picture
Load Testing: See a Bigger PictureLoad Testing: See a Bigger Picture
Load Testing: See a Bigger PictureAlexander 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 swqd14Alexander Podelko
 
Performance: See the Whole Picture
Performance: See the Whole PicturePerformance: See the Whole Picture
Performance: See the Whole PictureAlexander Podelko
 
Performance Assurance for Packaged Applications
Performance Assurance for Packaged ApplicationsPerformance Assurance for Packaged Applications
Performance Assurance for Packaged ApplicationsAlexander 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 ProcessAlexander Podelko
 
A Short History of Performance Engineering
A Short History of Performance EngineeringA Short History of Performance Engineering
A Short History of Performance EngineeringAlexander 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, 2014Alexander Podelko
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for TestingMukta Aphale
 
A Short History of Performance Engineering
A Short History of Performance EngineeringA Short History of Performance Engineering
A Short History of Performance EngineeringAlexander 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 14Alexander Podelko
 
September_08 SQuAd Presentation
September_08 SQuAd PresentationSeptember_08 SQuAd Presentation
September_08 SQuAd Presentationiradari
 

En vedette (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
 

Similaire à 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 GundechaAgile Testing Alliance
 
Web Components v1
Web Components v1Web Components v1
Web Components v1Mike Wilcox
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETBen Hall
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery EssentialsMark Rackley
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfullyTEST Huddle
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill 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 2011Timothy 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 sideMek 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 ProtractorKasun 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 developersChris 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 2014Wojciech Seliga
 

Similaire à 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
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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 Processorsdebabhi2
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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 Scriptwesley chun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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.pdfsudhanshuwaghmare1
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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 RobisonAnna Loughnan Colquhoun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Dernier (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.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

Notes de l'éditeur

  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.