selenium webdriver - ldstech what is selenium webdriver? ... use on: test classes and test methods...
TRANSCRIPT
![Page 1: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/1.jpg)
Selenium WebDriver: Enhanced Integration with the
Java Stack
![Page 2: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/2.jpg)
Notes
This is a training, NOT a presentation
Please be prepared to:
• Learn
• Ask questions
• Participate in the labs
http://tech.lds.org/wiki/Java_Stack_Training
![Page 3: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/3.jpg)
Prerequisites
Required:
• "Unit Testing with TestNG"
• "Integration Testing and Test Data Builders"
Recommended:
• "Test Doubles, Mocks, and Matchers"
• "Functional Testing with the Java Stack Test Runner"
![Page 4: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/4.jpg)
Agenda
• What is Selenium WebDriver?
• Using Stack Selenium
• Customizing Stack Selenium drivers and execution
• Using multiple drivers per test
• Selenium Grid
• Gotchas
![Page 5: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/5.jpg)
SELENIUM WEBDRIVER?
What is
![Page 6: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/6.jpg)
SELENIUM WEBDRIVER
http://www.flickr.com/photos/foto-kouba/6783399423/
![Page 7: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/7.jpg)
SELENIUM WEBDRIVER
Browser Client
We
bD
rive
r
![Page 8: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/8.jpg)
How To: WebDriver
• Add the Selenium WebDriver Maven dependencies
• Install the browser that you want to drive
• Write the code that:
• starts the driver
• executes the automation
• closes the driver
![Page 9: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/9.jpg)
Maven Setup
Tests go in the QA module
• Tests should end in "FT"
Tests will be executed by the ALM module
project/ qa/ src/ test/ java/ pom.xml alm/ pom.xml pom.xml
Tests go here
![Page 10: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/10.jpg)
Maven Setup
Tests go in the QA module
• Tests should end in "FT"
Tests will be executed by the ALM module
> mvn clean install > mvn alm-promote
![Page 11: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/11.jpg)
Maven Setup
Tests go in the QA module
• Tests should end in "FT"
Tests will be executed by the ALM module
> mvn clean install > mvn alm-promote
![Page 12: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/12.jpg)
How To: WebDriver public class BasicExampleFT {
@BeforeClass(alwaysRun = true) protected void setUp() { webDriver = new FirefoxDriver(); shortWait = new WebDriverWait(webDriver, 5); } @AfterClass(alwaysRun = true) protected void teardown() { webDriver.quit(); } @Test public void inSearchOfCheese() { webDriver.get("http://www.google.com"); WebElement element = webDriver.findElement(By.name("q")); element.sendKeys("cheese!"); element.submit(); shortWait.until(ExpectedConditions.titleIs("cheese!...")); }
}
org.lds.stack.training.webdriver.example.BasicExampleFT
![Page 13: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/13.jpg)
Limitations
Setup and management of WebDriver
• When should I start the driver?
• When should I stop the driver?
• How do I configure the driver consistently?
Setup and management of browsers
• On workstation
• On server
![Page 14: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/14.jpg)
STACK SELENIUM
Introducing
![Page 15: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/15.jpg)
Goals
• Minimize effort to start, configure and manage tests
• Consistency in test structure and lifecycle
• Encourage good practices and habits
![Page 16: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/16.jpg)
Stack Selenium
Leverages:
• TestNG
• Spring TestContext framework
![Page 17: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/17.jpg)
STACK SELENIUM
Browser
Client
WebD
rive
r
WebD
river
Web
Driver
Browser
![Page 18: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/18.jpg)
Getting Started
• Add the Selenium WebDriver Maven dependencies
• Install the browser that you want to drive
• Write the code that:
• starts the driver
• executes the automation
• closes the driver
![Page 19: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/19.jpg)
Getting Started
• Add the Selenium WebDriver Maven dependencies
• Install the browser that you want to drive
• Write the code that:
• starts the driver
• executes the automation
• closes the driver
Add the stack-
selenium Maven
dependency
![Page 20: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/20.jpg)
Maven Dependencies
<dependency> <groupId>org.lds.stack.qa</groupId> <artifactId>stack-selenium</artifactId>
</dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-firefox-driver</artifactId>
</dependency>
Latest version of
stack-selenium is
4.2.2.
![Page 21: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/21.jpg)
Getting Started
public class ImprovedExampleFT extends AbstractDefaultSeleniumFT {
@Test public void inSearchOfCheese() {
webDriver.get("http://www.google.com"); WebElement element = webDriver.findElement(By.name("q")); element.sendKeys("cheese!"); element.submit(); shortWait.until(ExpectedConditions.titleIs("cheese…"));
} }
org.lds.stack.training.webdriver.example.ImprovedExampleFT
![Page 22: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/22.jpg)
What's Provided?
WebDriver reference (webDriver)
WebDriverWait objects ("waiters")
• shortWait (5 seconds)
• mediumWait (10 seconds)
• longWait (30 seconds)
![Page 23: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/23.jpg)
LAB 1
http://openclipart.org/detail/22736/lab-icon-2-by-papapishu
![Page 24: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/24.jpg)
DRIVER SELECTION AND MANAGEMENT
Customizing
![Page 25: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/25.jpg)
Framework Configuration
Uses Spring configuration classes
• Configuration class
• On test class
@Configuration // other annotations, as needed public class MyConfiguration { // one or more bean definitions here }
@ContextConfiguration(classes = MyConfiguration.class) public class MyFunctionalTestFT extends AbstractSeleniumFT { // tests go here }
![Page 26: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/26.jpg)
Framework Configuration
Uses Spring configuration classes
• Configuration class
• On test class
@Configuration // other annotations, as needed public class MyConfiguration { // one or more bean definitions here }
@ContextConfiguration(classes = MyConfiguration.class) public class MyFunctionalTestFT extends AbstractSeleniumFT { // tests go here }
![Page 27: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/27.jpg)
Which Class Should I
Use? AbstractDefaultSeleniumFT
• "The defaults drivers and waits work for me"
AbstractSeleniumFT
• "I want more control over my drivers and waits"
AbstractMultiDriverSeleniumFT
• "I want to run the same tests over multiple drivers"
(and I like really long class names)
![Page 28: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/28.jpg)
Framework Configuration
• Add our own configuration annotations to configuration class
@ContextConfiguration( classes = AbstractDefaultSeleniumFT.DefaultConfiguration.class) public class AbstractDefaultSeleniumFT extends AbstractSeleniumFT { // various injected elements @Configuration @EnableSeleniumSupport(includeDefaultDrivers = true) @DefaultWebDriverWaits static class DefaultConfiguration { } }
org.lds.stack.qa.selenium.AbstractDefaultSeleniumFT
![Page 29: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/29.jpg)
@EnableSeleniumSupport
USE ON: Spring configuration classes
Makes the switchable/configurable web driver available
• Registers any web driver configurations
Attributes:
• includeDefaultDrivers (default false): include default drivers in the
configuration
@Configuration @EnableSeleniumSupport class MyConfiguration { }
![Page 30: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/30.jpg)
includeDefaultDrivers=true
Adds the following drivers to the test container:
• DEFAULT-htmlUnit.HTML_UNIT
• DEFAULT-firefox.FIREFOX
• DEFAULT-chrome.CHROME
@Configuration @EnableSeleniumSupport(includeDefaultDrivers = true) class MyConfiguration { }
![Page 31: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/31.jpg)
includeDefaultDrivers=true
Adds the following drivers to the test container:
• DEFAULT-htmlUnit.HTML_UNIT
• DEFAULT-firefox.FIREFOX
• DEFAULT-chrome.CHROME
Only the drivers found
in dependencies
@Configuration @EnableSeleniumSupport(includeDefaultDrivers = true) class MyConfiguration { }
![Page 32: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/32.jpg)
DRIVER IDENTIFIERS
A brief detour
![Page 33: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/33.jpg)
Driver Identifiers
DEFAULT-htmlUnit.HTML_UNIT
Driver key or name Driver Type
![Page 34: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/34.jpg)
Driver Identifiers
DEFAULT-htmlUnit.HTML_UNIT
Driver key or name Driver Type
You decide on
a name! Must be a valid
value
![Page 35: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/35.jpg)
Which Driver to Use
• REMOTE
• HTML_UNIT
• FIREFOX
• CHROME
Then by driver
name/key in
alphabetical order
org.lds.stack.qa.selenium.core.DriverType
![Page 36: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/36.jpg)
Quiz #1
• DEFAULT-chrome.CHROME
• DEFAULT-firefox.FIREFOX
• DEFAULT-htmlUnit.HTML_UNIT
![Page 37: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/37.jpg)
Quiz #1
• DEFAULT-chrome.CHROME
• DEFAULT-firefox.FIREFOX
• DEFAULT-htmlUnit.HTML_UNIT X
![Page 38: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/38.jpg)
Quiz #2
• driver1.CHROME
• driver1.REMOTE
• driver2.CHROME
![Page 39: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/39.jpg)
Quiz #2
• driver1.CHROME
• driver1.REMOTE X
• driver2.CHROME
![Page 40: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/40.jpg)
BACK TO OUR PROGRAM
And now…
![Page 41: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/41.jpg)
@UseSeleniumDriver
USE ON: test classes and test methods
Specifies which driver to use for a class or method
Attributes:
• key (optional): the driver name or key or use
• driverType (optional): the driver type to use
@UseSeleniumDriver( key = "myDriver", driverType = DriverType.HTML_UNIT) @ContextConfiguration(classes = MyConfiguration.class) public class MyTestFT extends AbstractSeleniumFT { // code happens }
org.lds.stack.training.webdriver.example.UseSeleniumDriverFT
![Page 42: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/42.jpg)
@UseSeleniumDriver
USE ON: test classes and test methods
Specifies which driver to use for a class or method
Attributes:
• key (optional): the driver name or key or use
• driverType (optional): the driver type to use
@UseSeleniumDriver( key = "myDriver", driverType = DriverType.HTML_UNIT) @Test public void testSomethingOnlyWithThisDriver() { // test something }
org.lds.stack.training.webdriver.example.UseSeleniumDriverFT
![Page 43: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/43.jpg)
@DriverClose
USE ON: test classes and test methods
Manages when a WebDriver should be closed
Attributes:
• closeAround (defaults to CLASS): when should driver be closed
@DriverClose @ContextConfiguration(classes = MyConfiguration.class) public class MyTestFT extends AbstractSeleniumFT { // code happens }
org.lds.stack.training.webdriver.example.DriverCloseFT
![Page 44: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/44.jpg)
@DriverClose
USE ON: test classes and test methods
Manages when a WebDriver should be closed
Attributes:
• closeAround (defaults to CLASS): when should driver be closed
@DriverClose(closeAround = DriverClose.CloseAround.METHODS) @ContextConfiguration(classes = MyConfiguration.class) public class MyTestFT extends AbstractSeleniumFT { // code happens }
org.lds.stack.training.webdriver.example.DriverCloseFT
![Page 45: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/45.jpg)
@DriverClose
USE ON: test classes and test methods
Manages when a WebDriver should be closed
Attributes:
• closeAround (defaults to CLASS): when should driver be closed
@DriverClose @Test public void testSomethingOnlyWithThisDriver() { // test something }
org.lds.stack.training.webdriver.example.DriverCloseFT
![Page 46: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/46.jpg)
@DefaultWebDriverWaits
USE ON: Spring configuration classes
Adds the following WebDriverWait objects:
• shortWait (5 seconds)
• mediumWait (10 seconds)
• longWait (30 seconds)
@Configuration @DefaultWebDriverWaits class MyConfiguration { }
org.lds.stack.training.webdriver.example.DefaultWebDriverWaitsFT
![Page 47: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/47.jpg)
@WebDriverWait
USE ON: Spring configuration classes
Adds a WebDriverWait with the specified name
Attributes
• name: name of the waiter
• timeout: time (in seconds) that waiter should wait
• interval (defaults to 250): frequency waiter should poll (in ms)
@Configuration @WebDriverWait(name = "myWait" timeout = 7) class MyConfiguration { }
org.lds.stack.training.webdriver.example.WebDriverWaitFT
![Page 48: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/48.jpg)
@WebDriverWaits
USE ON: Spring configuration classes
Specifies a collection of @WebDriverWait elements
Attributes
• value: zero or more @WebDriverWait elements
@Configuration @WebDriverWaits({ @WebDriverWait(name = "shortWait", timeout = 5), @WebDriverWait(name = "mediumWait", timeout = 10), @WebDriverWait(name = "longWait", timeout = 30) }) class MyConfiguration { }
org.lds.stack.training.webdriver.example.WebDriverWaitsFT
![Page 49: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/49.jpg)
Annotation Summary
Spring Configuration
• @EnableSeleniumSupport
• @DefaultWebDriverWaits
• @WebDriverWait
• @WebDriverWaits
Test Configuration
• @UseSeleniumDriver
• @DriverClose
• @UseSeleniumDrivers
…to be
continued
![Page 50: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/50.jpg)
WebDriverConfigurer
USE IN: Spring configuration classes
Defines a new WebDriver for use in tests
@Configuration class MyConfiguration { @Bean(name = "myHtmlUnit-driver") public WebDriverConfigurer<HtmlUnitDriver> htmlUnitDriver() { return new WebDriverConfigurer<HtmlUnitDriver>() { public HtmlUnitDriver configure() { return new HtmlUnitDriver(); } }; }
org.lds.stack.training.webdriver.example.WebDriverConfigurerFT
![Page 51: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/51.jpg)
WebDriverConfigurer
USE IN: Spring configuration classes
Defines a new WebDriver for use in tests
@Configuration class MyConfiguration { @Bean(name = "myHtmlUnit-driver") public WebDriverConfigurer<HtmlUnitDriver> htmlUnitDriver() { return new WebDriverConfigurer<HtmlUnitDriver>() { public HtmlUnitDriver configure() { return new HtmlUnitDriver(); } }; }
If omitted, uses the
method name for the
driver name
org.lds.stack.training.webdriver.example.WebDriverConfigurerFT
![Page 52: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/52.jpg)
LAB 2
http://openclipart.org/detail/22736/lab-icon-2-by-papapishu
![Page 53: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/53.jpg)
MULTIPLE DRIVERS ON TESTS
Using
![Page 54: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/54.jpg)
Using Multiple Drivers
Options include:
• Duplicate test methods or classes
• Create TestNG suite configurations
![Page 55: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/55.jpg)
Using Multiple Drivers
Options include:
• Duplicate test methods or classes
• Create TestNG suite configurations
• Use AbstractMultiDriverSeleniumFT!
![Page 56: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/56.jpg)
Multiple Drivers - Steps
• Extend AbstractMultiDriverSeleniumFT
• Create a Spring configuration class
• Attach configuration class to test
• Add @UseSeleniumDrivers annotation to class
• Add constructor to accept driver selectors
![Page 57: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/57.jpg)
Using Multiple Drivers
@UseSeleniumDrivers(drivers = { @UseSeleniumDriver(driverType = DriverType.HTML_UNIT), @UseSeleniumDriver(driverType = DriverType.FIREFOX) })
@ContextConfiguration(classes = MultiDriverConfiguration.class) public class MultiDriverSeleniumFT
extends AbstractMultiDriverSeleniumFT { @Autowired private Wait<WebDriver> shortWait; @Factory(dataProvider = "driverDataProvider") public MultiDriverSeleniumFT(String predicateAsString) {
super(predicateAsString); } // some tests
}
org.lds.stack.training.webdriver.example.MultiDriverSeleniumFT
![Page 58: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/58.jpg)
SELENIUM GRID
Using
![Page 59: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/59.jpg)
SELENIUM GRID
Browser Client
We
bD
rive
r
![Page 60: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/60.jpg)
Selenium Grid – Getting
Started • Create a RemoteWebDriver configuration for each browser
• Select the driver using @UseSeleniumDriver
@Bean public WebDriverConfigurer<RemoteWebDriver> chromeGrid() {
return new WebDriverConfigurer<RemoteWebDriver>() { public RemoteWebDriver configure() {
return new RemoteWebDriver( new URL(GRID_ROOT_URL + "/wd/hub"), DesiredCapabilities.chrome());
} };
}
org.lds.stack.training.webdriver.example.GridExampleFT
![Page 61: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/61.jpg)
HEADLESS DRIVER?
http://www.flickr.com/photos/friedwater/2750747024/
![Page 62: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/62.jpg)
GOTCHAS
http://www.flickr.com/photos/kwl/5199093132/
![Page 63: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/63.jpg)
Updating Versions
• Stack-selenium version
• Selenium version
<properties> ... <stackSeleniumVersion>4.2.2</stackSeleniumVersion> ...
</properties>
<properties> ... <seleniumVersion>2.30.0</seleniumVersion> ...
</properties>
![Page 64: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/64.jpg)
Configuring Browsers
Read the docs!
• Selenium WebDriver site –
https://code.google.com/p/selenium/
• ChromeDriver –
https://code.google.com/p/selenium/wiki/ChromeDriver
• FirefoxDriver –
https://code.google.com/p/selenium/wiki/FirefoxDriver
![Page 65: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/65.jpg)
SUMMARY
![Page 66: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/66.jpg)
Upcoming Features
Support for augmenters
• TakesScreenshot
• JavaScriptExecutor
Increased driver support
• GhostDriver
• SafariDriver
More WebDriver expectations
![Page 67: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/67.jpg)
Stack Selenium, Part Two
• WebDriver testing techniques
• Page Objects
• Environment configuration
![Page 68: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/68.jpg)
Java Testing Toolkit
• Testing framework: TestNG
• Test assertions: Hamcrest Matchers and Stack Unit Test utilities
• Test doubles and mocks: Mockito
• Integration testing framework: Spring TestContext
• Test data builders: Make-it-Easy
• Test runner: Stack TestRunner
• Functional testing: Stack Selenium
![Page 69: Selenium WebDriver - LDSTech What is Selenium WebDriver? ... USE ON: test classes and test methods Specifies which driver to use for a class or method Attributes: • key (optional):](https://reader031.vdocuments.mx/reader031/viewer/2022021818/5aaf61a07f8b9a190d8d3b9c/html5/thumbnails/69.jpg)
THANKS