SlideShare a Scribd company logo
Toolbox for Selenium Tests in
Java: WebDriverManager and
Selenium-Jupiter
SeleniumConf Tokyo
19/04/2019
Boni García
boni.garcia@urjc.es http://bonigarcia.github.io/
@boni_gg https://github.com/bonigarcia
Boni García
• PhD in Information and Communications Technology from
Technical University of Madrid (UPM) in Spain. Dissertation
focused on software testing with Selenium
• Assistant Professor at King Juan Carlos University (URJC) in
Spain
• Open source software enthusiast. Creator and maintainer
of a number of projects: WebDriverManager, Selenium-
Jupiter, DualSub
• Author of more than 30 research papers in different
journals, magazines, international conferences, and the
book Mastering Software Testing with JUnit 5
Table of contents
WebDriverManager Selenium-Jupiter
Toolbox for Selenium in Java (but not only Java)
Ad
WebDriverManager - Motivation
• Selenium WebDriver allows to control different types of
browsers (such as Chrome, Firefox, Opera, Edge, and so on)
programmatically using different programming languages
(Java, JavaScript, Python, C#, …)
• Browser is driven using native mechanism, so we need a
binary file (driver) in between the test using the WebDriver
API and the actual browser
WebDriverManager - Motivation
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
System.setProperty("webdriver.opera.driver", "/path/to/operadriver");
System.setProperty("webdriver.ie.driver", "C:/path/to/IEDriverServer.exe");
System.setProperty("webdriver.edge.driver", "C:/path/to/MicrosoftWebDriver.exe");
System.setProperty("phantomjs.binary.path", "/path/to/phantomjs");
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
Ad
WebDriverManager - Motivation
• Driver management is painful:
• Driver (chromedriver, geckodriver, etc.) must be downloaded
manually for the proper platform running the test (i.e. Windows,
Linux, Mac)
• Proper driver version must match the browser version
• Browser are constantly updated (and drivers too)
• Tests are not portable (different operative systems, path to driver)
WebDriverManager - Motivation
Ad
WebDriverManager - Objective
• WebDriverManager is a Java library that allows to
automate the management of the binary drivers
(chromedriver, geckodriver, etc.) required by Selenium
WebDriver
WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.iedriver().setup();
WebDriverManager.phantomjs().setup();
https://github.com/bonigarcia/webdrivermanager
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.4.0</version>
<scope>test</scope>
</dependency>
dependencies {
testCompile("io.github.bonigarcia:webdrivermanager:3.4.0")
}
WebDriverManager - Objective
public class ChromeTest {
private WebDriver driver;
@BeforeClass
public static void setupClass() {
WebDriverManager.chromedriver().setup();
}
@Before
public void setupTest() {
driver = new ChromeDriver();
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void test() {
// Your test code here
}
}
public class ChromeTest {
private WebDriver driver;
@BeforeClass
public static void setupClass() {
WebDriverManager.firefoxdriver().setup();
}
@Before
public void setupTest() {
driver = new FirefoxDriver();
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void test() {
// Your test code here
}
}
Ad
WebDriverManager - Design
• WebDriverManager was first released on 21st March 2015
• In its earlier versions, WebDriverManager downloaded the
latest version of the driver by default
Check driver
latest version
Driver in
cache?
Download driver
Export driver path Driver
cache
no
Driver repository (online)
yes
setup()
WebDriverManager - Design
• Currently, WebDriverManager resolution algorithm is much richer
Check browser
version
Driver in
cache?
Download driver
Export driver path Driver
cache
no
Driver repository (online)
Internal
preferences
Recently
resolved?
Check driver
version
Versions
database
TTL
no
yes
yes
setup()
Versions database (online)
Ad
WebDriverManager - API
• WebDriverManager exposes a fluent API. For instance:
WebDriverManager.chromedriver().setup();
WebDriverManager.chromedriver().version("2.46").setup();
WebDriverManager.firefoxdriver().arch32().setup();
WebDriverManager.operadriver().forceDownload().setup();
WebDriverManager.phantomjs().avoidPreferences().setup();
WebDriverManager.edgedriver().proxy("server:port").setup();
Default usage for managing
chromedriver
Force a given version (2.46)
for chromedriver
Force 32-bit architecture for
geckodriver
Force the download of
operadriver
Avoid the use of preferences
for PhantomJS driver
Set proxy setup when
managing Edge driver
WebDriverManager - API
• More examples of the WebDriverManager API:
Method Description
version(String) Set a concrete version for the driver to be downloaded
targetPath(String) Change cache path (by default ~/.m2/repository/webdriver)
architecture(Architecture) Force a given architecture: 32-bits or 64-bits
operatingSystem(OperatingSystem) Force a given OS: WIN, LINUX, MAC
proxy(String) Use a HTTP proxy for the Internet connection
avoidPreferences() Avoid the use of Java preferences
driverRepositoryUrl(URL) Set a custom repository URL
timeout(int) Change connection timeout
browserPath() Set path for a given browser
ttl() Change time-to-live (by default 3600 seconds)
forceDownload() Force to download driver even if it exists in cache
https://github.com/bonigarcia/webdrivermanager
Ad
WebDriverManager - Configuration
• WebDriverManager is highly configurable with:
1. Environment variables. For example
2. Java properties. For example:
3. Configuration manager in Java. For example:
export WDM_TARGETPATH=~/.selenium
export WDM_CHROMEDRIVERVERSION=2.46
mvn test -Dwdm.targetPath=~/.selenium
gradle test -Dwdm.chromeDriverVersion=2.46
WebDriverManager.globalConfig().setTargetPath("~/.selenium");
WebDriverManager.chromedriver().version("2.46").setup();
WebDriverManager - Beyond Java
• WebDriverManager can be also used:
1. As CLI (command line interface) tool:
2. As server (using a REST-like API):
> java -jar webdrivermanager-3.4.0-fat.jar chrome
[INFO] Using WebDriverManager to resolve chrome
[INFO] Reading https://chromedriver.storage.googleapis.com/ to seek chromedriver
[INFO] Latest version of chromedriver is 2.37
[INFO] Downloading https://chromedriver.storage.googleapis.com/2.37/chromedriver_win32.zip
to folder D:projectswebdrivermanager
[INFO] Resulting binary D:projectswebdrivermanagertargetchromedriver.exe
> java -jar webdrivermanager-3.4.0-fat.jar server
[INFO] WebDriverManager server listening on port 4041
Examples of requests to WebDriverManager Server:
http://localhost:4041/firefoxdriver
http://localhost:4041/chromedriver?chromeDriverVersion=2.40
Ad
WebDriverManager - Conclusions
• WebDriverManager is a helper library for automating the
management of Selenium drivers (chromedriver, etc.)
WebDriverManager - Conclusions
• WebDriverManager is used in different projects in the Selenium
ecosystem. For instance:
• io.appium » java-client: https://github.com/appium/java-client
• com.codeborne » selenide: https://github.com/selenide/selenide
• WebDriverManager concept has been ported to other languages:
• webdriver-manager (Node.js): https://github.com/angular/webdriver-manager
• webdriver_manager (Python): https://github.com/jeffnyman/webdriver_manager
• WebDriverManager.Net (.Net): https://github.com/rosolko/WebDriverManager.Net
• Webdrivers Gem (Ruby): https://github.com/titusfortner/webdrivers
• WebDriverManager is in constant evolution. Its roadmap includes:
• Support Edge based on Chromium
• Using aspects (cross-cutting concerns) to resolve drivers automatically when
instantiating WebDriver objects
Ad
Table of contents
WebDriverManager Selenium-Jupiter
Toolbox for Selenium in Java (but not only Java)
Selenium-Jupiter - Motivation
• JUnit 5 (stable) was first released on September 2017
Revolutionary
Evolutionary
Necessary
Ad
Selenium-Jupiter - Motivation
• JUnit 5 provides a brand-new
programming an extension model
called Jupiter
• Basic test are similar than in JUnit 4
and provide a wide range of new
features, such as:
• Enhanced parameterized tests
• Parallel execution
• Test ordering
• Kotlin support
• …
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class BasicJUnit5Test {
@BeforeAll
static void setupAll() {
// setup all tests
}
@BeforeEach
void setup() {
// setup each test
}
@Test
void test() {
// exercise and verify SUT
}
@AfterEach
void teardown() {
// teardown each test
}
@AfterAll
static void teardownAll() {
// teardown all tests
}
}
https://junit.org/junit5/docs/current/user-guide/
Selenium-Jupiter - Motivation
• The extension model of JUnit 5 allows to add custom features
to the programming model through extension points:
Very convenient
for Selenium!
1. Custom logic in the test
lifecycle
2. Dependency injection in test
methods and constructors
3. Test templates
4. Test conditional execution
Ad
Selenium-Jupiter - Objective
• Selenium-Jupiter is a JUnit 5 extension aimed to ease the
use of Selenium from Java tests
• Thanks to the Jupiter extension model, the required
boilerplate to use Selenium from JUnit 5 is minimum
• Moreover, it allows to use browser and Android devices in
Docker containers in a effortless manner
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>selenium-jupiter</artifactId>
<version>3.2.0</version>
<scope>test</scope>
</dependency>
dependencies {
testCompile("io.github.bonigarcia:selenium-jupiter:3.2.0")
}
https://github.com/bonigarcia/selenium-jupiter
Selenium-Jupiter - Local browsers
• Selenium-Jupiter uses the dependency injection mechanism
to instantiate/release WebDriver objects before/after tests
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import io.github.bonigarcia.SeleniumExtension;
@ExtendWith(SeleniumExtension.class)
public class ChromeAndFirefoxJupiterTest {
@Test
public void testWithOneChrome(ChromeDriver chromeDriver) {
// Use Chrome in this test
}
@Test
public void testWithFirefox(FirefoxDriver firefoxDriver) {
// Use Firefox in this test
}
@Test
public void testWithChromeAndFirefox(ChromeDriver chromeDriver,
FirefoxDriver firefoxDriver) {
// Use Chrome and Firefox in this test
}
}
We simply need to specify the type of browser to
be used, as test or constructor parameters:
• ChromeDriver
• FirefoxDriver
• OperaDriver
• SafariDriver
• EdgeDriver
• InternetExplorerDriver
• HtmlUnitDriver
• PhantomJSDriver
• AppiumDriver
Internally, Selenium-Jupiter uses
WebDriverManager to resolve properly the
required binary drivers to control local browsers
Ad
Selenium-Jupiter - Remote browsers
• Selenium-Jupiter provides
the annotation @DriverUrl
to locate the Selenium or
Appium server and
@DriverCapabilities to
specify the desired
capabilities
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.github.bonigarcia.DriverCapabilities;
import io.github.bonigarcia.DriverUrl;
import io.github.bonigarcia.SeleniumExtension;
@ExtendWith(SeleniumExtension.class)
public class SauceLabsJupiterTest {
@DriverUrl
String url = "https://ondemand.eu-central-1.saucelabs.com/wd/hub";
@DriverCapabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
{
capabilities.setCapability("username", "<my-saucelabs-user>");
capabilities.setCapability("accessKey", "<my-saucelabs-key>");
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("platform", "Windows 10");
capabilities.setCapability("version", "59.0");
capabilities.setCapability("name", "selenium-jupiter-and-saucelabs");
}
@Test
void testWithSaucelabs(RemoteWebDriver driver) {
// test
}
}
Selenium-Jupiter - Remote browsers
• Selenium-Jupiter provides
the annotation @DriverUrl
to locate the Selenium or
Appium server and
@DriverCapabilities to
specify the desired
capabilities
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.github.bonigarcia.seljup.DriverCapabilities;
import io.github.bonigarcia.seljup.DriverUrl;
import io.github.bonigarcia.seljup.SeleniumExtension;
@ExtendWith(SeleniumExtension.class)
public class AppiumWithGlobalOptionsChromeJupiterTest {
@DriverUrl
String url = "http://localhost:4723/wd/hub";
@DriverCapabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
{
capabilities.setCapability("browserName", "chrome");
capabilities.setCapability("deviceName", "Samsung Galaxy S6");
}
@Test
void testWithAndroid(AppiumDriver<WebElement> driver) {
// test
}
}
Ad
Selenium-Jupiter - Dockerized browsers
• Selenium-Jupiter provides seamless integration with Docker
• The annotation @DockerBrowser is used to declare a dockerized
browsers. The supported browser are
• Chrome, Firefox, and Opera:
• Docker images for stable versions are maintained by Aerokube
• Beta and unstable (Chrome and Firefox) are maintained by ElasTest
• Edge and Internet Explorer:
• Due to license, these Docker images are not hosted in Docker Hub
• It can be built following a tutorial provided by Aerokube
• Android devices:
• Docker images for Android devices are maintained in the docker-android project (by Budi
Utomo)
Selenium-Jupiter - Dockerized browsers
• Browser in Docker containers example:
import static io.github.bonigarcia.BrowserType.CHROME;
import static io.github.bonigarcia.BrowserType.FIREFOX;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.github.bonigarcia.DockerBrowser;
import io.github.bonigarcia.SeleniumExtension;
@ExtendWith(SeleniumExtension.class)
public class DockerChromeJupiterTest {
@Test
public void testChrome(@DockerBrowser(type = CHROME) RemoteWebDriver driver) {
// test
}
@Test
public void testChromeWithVersion(@DockerBrowser(type = FIREFOX, version = "66.0")
RemoteWebDriver driver) {
// test
}
}
Supported browser types are: CHROME,
FIREFOX, OPERA, y EDGE , IEXPLORER
and ANDROID
The parameter version admits the
following special values: latest,
latest-*, beta, y unstable
If version is not specified, the latest
stable will be used. For that, Selenium-
Jupiter internally connects to Docker
Hub to find out the latest version (ever
green Docker browser)
Ad
Selenium-Jupiter - Dockerized browsers
• Browsers in Docker containers can be used to create performance tests:
import static io.github.bonigarcia.BrowserType.CHROME;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.util.List;
import io.github.bonigarcia.DockerBrowser;
import io.github.bonigarcia.SeleniumExtension;
@ExtendWith(SeleniumExtension.class)
public class DockerChromeJupiterTest {
static final int NUM_BROWSERS = 10;
@Test
public void testPerformance(
@DockerBrowser(type = CHROME, size = NUM_BROWSERS) List<RemoteWebDriver> driverList) {
// test
}
} In this test, we will have 10
Chrome browsers ready to be
used by the test logic
Selenium-Jupiter - Dockerized browsers
• Android in Docker container example:
import static io.github.bonigarcia.BrowserType.ANDROID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.github.bonigarcia.DockerBrowser;
import io.github.bonigarcia.SeleniumExtension;
@ExtendWith(SeleniumExtension.class)
public class DockerAndroidCustomJupiterTest {
@Test
public void testAndroid(@DockerBrowser(type = ANDROID, version = "8.1",
deviceName = "Nexus S") RemoteWebDriver driver) {
// test
}
} When using Android in Docker
containers, the type of device can
be specified
Android version API level Browser name
5.0.1 21 browser
5.1.1 22 browser
6.0 23 chrome
7.0 24 chrome
7.1.1 25 chrome
8.0 26 chrome
8.1 27 chrome
9.0 28 chrome
Type Device name
Phone Samsung Galaxy S6
Phone Nexus 4
Phone Nexus 5
Phone Nexus One
Phone Nexus S
Tablet Nexus 7
Ad
Selenium-Jupiter - Dockerized browsers
• When using Docker containers, it is possible to interact with the remote
session using VNC (and also recording these sessions)
Selenium-Jupiter - Test templates
• Selenium-Jupiter use the JUnit 5’s support for test templates
• A template defines the number and types of browser used by a test:
1. By means of a JSON file:
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.WebDriver;
import io.github.bonigarcia.SeleniumExtension;
@ExtendWith(SeleniumExtension.class)
public class TemplateTest {
@TestTemplate
void templateTest(WebDriver driver) {
// test
}
}
{
"browsers": [
[
{
"type": "chrome-in-docker",
"version": "latest"
}
],
[
{
"type": "chrome-in-docker",
"version": "latest-1"
}
],
[
{
"type": "chrome-in-docker",
"version": "beta"
}
],
[
{
"type": "chrome-in-docker",
"version": "unstable"
}
]
]
}
Ad
Selenium-Jupiter - Test templates
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openqa.selenium.WebDriver;
import io.github.bonigarcia.BrowserBuilder;
import io.github.bonigarcia.BrowsersTemplate.Browser;
import io.github.bonigarcia.SeleniumExtension;
public class TemplateRegisterTest {
@RegisterExtension
static SeleniumExtension seleniumExtension = new SeleniumExtension();
@BeforeAll
static void setup() {
Browser chrome = BrowserBuilder.chrome().build();
Browser firefox = BrowserBuilder.firefox().build();
seleniumExtension.addBrowsers(chrome, firefox);
}
@TestTemplate
void templateTest(WebDriver driver) {
// ...
}
}
• Selenium-Jupiter use the JUnit 5’s support for test templates
• A template defines the number and types of browser used by a test:
2. Programmatically:
Selenium-Jupiter - Configuration
• Selenium-Jupiter is also highly configurable with:
1. Environment variables. For example
2. Java properties. For example:
3. Configuration manager in Java. For example:
export SEL_JUP_VNC=true
export SEL_JUP_RECORDING=true
mvn test –Dsel.jup.vnc=true
gradle test –Dsel.jup.vnc=true
@RegisterExtension
static SeleniumExtension seleniumExtension = new SeleniumExtension();
@BeforeAll
static void setup() {
seleniumExtension.getConfig().setVnc(true);
seleniumExtension.getConfig().setRecording(true);
}
Ad
Selenium-Jupiter - Beyond Java
• Selenium-Jupiter can be also used:
1. As CLI (command line interface) tool:
2. As server (using a REST-like API):
> java -jar selenium-jupiter-3.2.0-fat.jar chrome
[INFO] Using SeleniumJupiter to execute chrome (latest) in Docker
[INFO] Using CHROME version 73.0 (latest)
[INFO] Starting Docker container aerokube/selenoid:1.8.4
[DEBUG] Creating WebDriver for CHROME at http://172.17.0.1:32784/wd/hub
Jan 07, 2019 6:55:17 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[INFO] Starting Docker container psharkey/novnc:3.3-t6
[INFO] Session id 8edd28c130bb2bc62f8e4467c20f4dc0
[INFO] VNC URL (copy and paste in a browser navigation bar to interact with remote session)
[INFO]
http://172.17.0.1:32785/vnc.html?host=172.17.0.1&port=32784&path=vnc/8edd28c130bb2bc62f8e44
67c20f4dc0&resize=scale&autoconnect=true&password=selenoid
[INFO] Press ENTER to exit
[INFO] Stopping Docker container aerokube/selenoid:1.8.4
[INFO] Stopping Docker container psharkey/novnc:3.3-t6
java -jar webdrivermanager-3.2.0-fat.jar server
[INFO] Selenium-Jupiter server listening on http://localhost:4042/wd/hub
Selenium-Jupiter becomes
a Selenium Server
Selenium-Jupiter allows to
control Docker browsers
through VNC
Selenium-Jupiter - Conclusions
• Selenium-Jupiter is a JUnit 5 extension for Selenium (WebDriver, Grid)
and Appium
Ad
Selenium-Jupiter - Conclusions
• Selenium-Jupiter has much more features such as:
• Using WebDriver @Options in tests (e.g. ChromeOptions,
FirefoxOptions, etc.)
• Screenshots at the end of test (as PNG image or Base64)
• Integration with Jenkins (publishing test results in the Jenkins GUI)
• Integration with Genymotion (cloud provider for Android devices)
• Generic driver (configurable type of browser)
• Single session (reuse browser in different tests)
• Selenium-Jupiter is evolving in the near future. Its roadmap includes:
• Improve test template support (e.g. specifying options within the template)
• Improve scalability for performance tests (candidate technology: Kubernetes)
https://bonigarcia.github.io/selenium-jupiter/
Toolbox for Selenium Tests in
Java: WebDriverManager and
Selenium-Jupiter
Thank you very much!
Q&A
Boni García
boni.garcia@urjc.es http://bonigarcia.github.io/
@boni_gg https://github.com/bonigarcia
Ad

More Related Content

What's hot (20)

PPTX
Xray for Jira - How to automate your QA process
PPT
Selenium ppt
PPTX
Introduction to selenium
PPTX
Selenium locators: ID, Name, xpath, CSS Selector advance methods
PDF
Automation Testing using Selenium
PPTX
Automated testing using Selenium & NUnit
PPTX
An overview of selenium webdriver
PDF
Basic overview of Angular
PPTX
Appium ppt
PPT
Selenium ppt
PPTX
Selenium IDE
PPTX
Automation test framework with cucumber – BDD
PPTX
Manual testing
PDF
Chapter 3 - Common Test Types and Test Process for Mobile Applications
PPTX
PPTX
Quality Assurance and Software Testing
PPTX
05 intent
PDF
Selenium with Cucumber
PDF
Behavior Driven Development and Automation Testing Using Cucumber
PPT
Manual testing concepts course 1
Xray for Jira - How to automate your QA process
Selenium ppt
Introduction to selenium
Selenium locators: ID, Name, xpath, CSS Selector advance methods
Automation Testing using Selenium
Automated testing using Selenium & NUnit
An overview of selenium webdriver
Basic overview of Angular
Appium ppt
Selenium ppt
Selenium IDE
Automation test framework with cucumber – BDD
Manual testing
Chapter 3 - Common Test Types and Test Process for Mobile Applications
Quality Assurance and Software Testing
05 intent
Selenium with Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
Manual testing concepts course 1

Similar to Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter (20)

PDF
WebDriverManager: the Swiss Army Knife for Selenium WebDriver
PDF
Selenium Manager: Automated Driver & Browser Management for Selenium WebDriver
PDF
TAFs on WebDriver API - By - Pallavi Sharma.pdf
PDF
Selenium Automation Testing What, Why and How
PDF
Selenium for Tester.pdf
PPTX
Selenium topic 3 -Web Driver Basics
PDF
Selenium Full Material( apprendre Selenium).pdf
PDF
Web driver selenium simplified
PPTX
Module 01 - WebDriver Basics
PDF
anoverviewofseleniumwebdriver-160407055026 (pdf.io).pdf
PPTX
Selenium web driver
PPTX
Selenium with java
PPTX
Step by step - Selenium 3 web-driver - From Scratch
PDF
Introduction to Selenium and WebDriver
PPTX
Automated Testing on Web Applications
PDF
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
PDF
Session on Selenium Powertools by Unmesh Gundecha
PPTX
Selenium Basics and Overview topics.pptx
PPTX
Selenium Basics and Overview1233444.pptx
PPTX
APIs for Browser Automation (MoT Meetup 2024)
WebDriverManager: the Swiss Army Knife for Selenium WebDriver
Selenium Manager: Automated Driver & Browser Management for Selenium WebDriver
TAFs on WebDriver API - By - Pallavi Sharma.pdf
Selenium Automation Testing What, Why and How
Selenium for Tester.pdf
Selenium topic 3 -Web Driver Basics
Selenium Full Material( apprendre Selenium).pdf
Web driver selenium simplified
Module 01 - WebDriver Basics
anoverviewofseleniumwebdriver-160407055026 (pdf.io).pdf
Selenium web driver
Selenium with java
Step by step - Selenium 3 web-driver - From Scratch
Introduction to Selenium and WebDriver
Automated Testing on Web Applications
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Session on Selenium Powertools by Unmesh Gundecha
Selenium Basics and Overview topics.pptx
Selenium Basics and Overview1233444.pptx
APIs for Browser Automation (MoT Meetup 2024)
Ad

More from Boni García (16)

PDF
Developing Selenium tests with JUnit 5
PPTX
Extending WebDriver: A cloud approach
PPTX
A Proposal to Orchestrate Test Cases
PPTX
Introducción y novedades de JUnit 5 (04/07/2018)
PPTX
User Impersonation as a Service in End-to-End Testing
PPTX
Introducción y novedades de JUnit 5 (16/01/2018)
PPTX
WebRTC Testing: State of the Art
PPTX
ElasTest: an elastic platform for testing complex distributed large software ...
PPTX
Analysis of video quality and end-to-end latency in WebRTC
PPT
NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
PPT
NUBOMEDIA Webinar
PPT
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
PPTX
Cloud Instances of Kurento v6 on FIWARE Lab
PPTX
Kurento v6 Development Guide
PPTX
Kurento v6 Installation Guide
PPTX
Introduction to the Stream Oriented GE (Kurento v6)
Developing Selenium tests with JUnit 5
Extending WebDriver: A cloud approach
A Proposal to Orchestrate Test Cases
Introducción y novedades de JUnit 5 (04/07/2018)
User Impersonation as a Service in End-to-End Testing
Introducción y novedades de JUnit 5 (16/01/2018)
WebRTC Testing: State of the Art
ElasTest: an elastic platform for testing complex distributed large software ...
Analysis of video quality and end-to-end latency in WebRTC
NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
NUBOMEDIA Webinar
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
Cloud Instances of Kurento v6 on FIWARE Lab
Kurento v6 Development Guide
Kurento v6 Installation Guide
Introduction to the Stream Oriented GE (Kurento v6)
Ad

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Transform Your Business with a Software ERP System
PPTX
Introduction to Artificial Intelligence
PPTX
L1 - Introduction to python Backend.pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Cost to Outsource Software Development in 2025
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
System and Network Administration Chapter 2
PDF
Softaken Excel to vCard Converter Software.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Reimagine Home Health with the Power of Agentic AI​
Transform Your Business with a Software ERP System
Introduction to Artificial Intelligence
L1 - Introduction to python Backend.pptx
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms I-SECS-1021-03
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Cost to Outsource Software Development in 2025
Wondershare Filmora 15 Crack With Activation Key [2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Navsoft: AI-Powered Business Solutions & Custom Software Development
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Digital Systems & Binary Numbers (comprehensive )
System and Network Administration Chapter 2
Softaken Excel to vCard Converter Software.pdf

Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter

  • 1. Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter SeleniumConf Tokyo 19/04/2019 Boni García boni.garcia@urjc.es http://bonigarcia.github.io/ @boni_gg https://github.com/bonigarcia
  • 2. Boni García • PhD in Information and Communications Technology from Technical University of Madrid (UPM) in Spain. Dissertation focused on software testing with Selenium • Assistant Professor at King Juan Carlos University (URJC) in Spain • Open source software enthusiast. Creator and maintainer of a number of projects: WebDriverManager, Selenium- Jupiter, DualSub • Author of more than 30 research papers in different journals, magazines, international conferences, and the book Mastering Software Testing with JUnit 5
  • 3. Table of contents WebDriverManager Selenium-Jupiter Toolbox for Selenium in Java (but not only Java)
  • 4. WebDriverManager - Motivation • Selenium WebDriver allows to control different types of browsers (such as Chrome, Firefox, Opera, Edge, and so on) programmatically using different programming languages (Java, JavaScript, Python, C#, …) • Browser is driven using native mechanism, so we need a binary file (driver) in between the test using the WebDriver API and the actual browser
  • 5. WebDriverManager - Motivation System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); System.setProperty("webdriver.opera.driver", "/path/to/operadriver"); System.setProperty("webdriver.ie.driver", "C:/path/to/IEDriverServer.exe"); System.setProperty("webdriver.edge.driver", "C:/path/to/MicrosoftWebDriver.exe"); System.setProperty("phantomjs.binary.path", "/path/to/phantomjs"); System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
  • 6. WebDriverManager - Motivation • Driver management is painful: • Driver (chromedriver, geckodriver, etc.) must be downloaded manually for the proper platform running the test (i.e. Windows, Linux, Mac) • Proper driver version must match the browser version • Browser are constantly updated (and drivers too) • Tests are not portable (different operative systems, path to driver)
  • 8. WebDriverManager - Objective • WebDriverManager is a Java library that allows to automate the management of the binary drivers (chromedriver, geckodriver, etc.) required by Selenium WebDriver WebDriverManager.chromedriver().setup(); WebDriverManager.firefoxdriver().setup(); WebDriverManager.operadriver().setup(); WebDriverManager.edgedriver().setup(); WebDriverManager.iedriver().setup(); WebDriverManager.phantomjs().setup(); https://github.com/bonigarcia/webdrivermanager <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>3.4.0</version> <scope>test</scope> </dependency> dependencies { testCompile("io.github.bonigarcia:webdrivermanager:3.4.0") }
  • 9. WebDriverManager - Objective public class ChromeTest { private WebDriver driver; @BeforeClass public static void setupClass() { WebDriverManager.chromedriver().setup(); } @Before public void setupTest() { driver = new ChromeDriver(); } @After public void teardown() { if (driver != null) { driver.quit(); } } @Test public void test() { // Your test code here } } public class ChromeTest { private WebDriver driver; @BeforeClass public static void setupClass() { WebDriverManager.firefoxdriver().setup(); } @Before public void setupTest() { driver = new FirefoxDriver(); } @After public void teardown() { if (driver != null) { driver.quit(); } } @Test public void test() { // Your test code here } }
  • 10. WebDriverManager - Design • WebDriverManager was first released on 21st March 2015 • In its earlier versions, WebDriverManager downloaded the latest version of the driver by default Check driver latest version Driver in cache? Download driver Export driver path Driver cache no Driver repository (online) yes setup()
  • 11. WebDriverManager - Design • Currently, WebDriverManager resolution algorithm is much richer Check browser version Driver in cache? Download driver Export driver path Driver cache no Driver repository (online) Internal preferences Recently resolved? Check driver version Versions database TTL no yes yes setup() Versions database (online)
  • 12. WebDriverManager - API • WebDriverManager exposes a fluent API. For instance: WebDriverManager.chromedriver().setup(); WebDriverManager.chromedriver().version("2.46").setup(); WebDriverManager.firefoxdriver().arch32().setup(); WebDriverManager.operadriver().forceDownload().setup(); WebDriverManager.phantomjs().avoidPreferences().setup(); WebDriverManager.edgedriver().proxy("server:port").setup(); Default usage for managing chromedriver Force a given version (2.46) for chromedriver Force 32-bit architecture for geckodriver Force the download of operadriver Avoid the use of preferences for PhantomJS driver Set proxy setup when managing Edge driver
  • 13. WebDriverManager - API • More examples of the WebDriverManager API: Method Description version(String) Set a concrete version for the driver to be downloaded targetPath(String) Change cache path (by default ~/.m2/repository/webdriver) architecture(Architecture) Force a given architecture: 32-bits or 64-bits operatingSystem(OperatingSystem) Force a given OS: WIN, LINUX, MAC proxy(String) Use a HTTP proxy for the Internet connection avoidPreferences() Avoid the use of Java preferences driverRepositoryUrl(URL) Set a custom repository URL timeout(int) Change connection timeout browserPath() Set path for a given browser ttl() Change time-to-live (by default 3600 seconds) forceDownload() Force to download driver even if it exists in cache https://github.com/bonigarcia/webdrivermanager
  • 14. WebDriverManager - Configuration • WebDriverManager is highly configurable with: 1. Environment variables. For example 2. Java properties. For example: 3. Configuration manager in Java. For example: export WDM_TARGETPATH=~/.selenium export WDM_CHROMEDRIVERVERSION=2.46 mvn test -Dwdm.targetPath=~/.selenium gradle test -Dwdm.chromeDriverVersion=2.46 WebDriverManager.globalConfig().setTargetPath("~/.selenium"); WebDriverManager.chromedriver().version("2.46").setup();
  • 15. WebDriverManager - Beyond Java • WebDriverManager can be also used: 1. As CLI (command line interface) tool: 2. As server (using a REST-like API): > java -jar webdrivermanager-3.4.0-fat.jar chrome [INFO] Using WebDriverManager to resolve chrome [INFO] Reading https://chromedriver.storage.googleapis.com/ to seek chromedriver [INFO] Latest version of chromedriver is 2.37 [INFO] Downloading https://chromedriver.storage.googleapis.com/2.37/chromedriver_win32.zip to folder D:projectswebdrivermanager [INFO] Resulting binary D:projectswebdrivermanagertargetchromedriver.exe > java -jar webdrivermanager-3.4.0-fat.jar server [INFO] WebDriverManager server listening on port 4041 Examples of requests to WebDriverManager Server: http://localhost:4041/firefoxdriver http://localhost:4041/chromedriver?chromeDriverVersion=2.40
  • 16. WebDriverManager - Conclusions • WebDriverManager is a helper library for automating the management of Selenium drivers (chromedriver, etc.)
  • 17. WebDriverManager - Conclusions • WebDriverManager is used in different projects in the Selenium ecosystem. For instance: • io.appium » java-client: https://github.com/appium/java-client • com.codeborne » selenide: https://github.com/selenide/selenide • WebDriverManager concept has been ported to other languages: • webdriver-manager (Node.js): https://github.com/angular/webdriver-manager • webdriver_manager (Python): https://github.com/jeffnyman/webdriver_manager • WebDriverManager.Net (.Net): https://github.com/rosolko/WebDriverManager.Net • Webdrivers Gem (Ruby): https://github.com/titusfortner/webdrivers • WebDriverManager is in constant evolution. Its roadmap includes: • Support Edge based on Chromium • Using aspects (cross-cutting concerns) to resolve drivers automatically when instantiating WebDriver objects
  • 18. Table of contents WebDriverManager Selenium-Jupiter Toolbox for Selenium in Java (but not only Java)
  • 19. Selenium-Jupiter - Motivation • JUnit 5 (stable) was first released on September 2017 Revolutionary Evolutionary Necessary
  • 20. Selenium-Jupiter - Motivation • JUnit 5 provides a brand-new programming an extension model called Jupiter • Basic test are similar than in JUnit 4 and provide a wide range of new features, such as: • Enhanced parameterized tests • Parallel execution • Test ordering • Kotlin support • … import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class BasicJUnit5Test { @BeforeAll static void setupAll() { // setup all tests } @BeforeEach void setup() { // setup each test } @Test void test() { // exercise and verify SUT } @AfterEach void teardown() { // teardown each test } @AfterAll static void teardownAll() { // teardown all tests } } https://junit.org/junit5/docs/current/user-guide/
  • 21. Selenium-Jupiter - Motivation • The extension model of JUnit 5 allows to add custom features to the programming model through extension points: Very convenient for Selenium! 1. Custom logic in the test lifecycle 2. Dependency injection in test methods and constructors 3. Test templates 4. Test conditional execution
  • 22. Selenium-Jupiter - Objective • Selenium-Jupiter is a JUnit 5 extension aimed to ease the use of Selenium from Java tests • Thanks to the Jupiter extension model, the required boilerplate to use Selenium from JUnit 5 is minimum • Moreover, it allows to use browser and Android devices in Docker containers in a effortless manner <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>selenium-jupiter</artifactId> <version>3.2.0</version> <scope>test</scope> </dependency> dependencies { testCompile("io.github.bonigarcia:selenium-jupiter:3.2.0") } https://github.com/bonigarcia/selenium-jupiter
  • 23. Selenium-Jupiter - Local browsers • Selenium-Jupiter uses the dependency injection mechanism to instantiate/release WebDriver objects before/after tests import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import io.github.bonigarcia.SeleniumExtension; @ExtendWith(SeleniumExtension.class) public class ChromeAndFirefoxJupiterTest { @Test public void testWithOneChrome(ChromeDriver chromeDriver) { // Use Chrome in this test } @Test public void testWithFirefox(FirefoxDriver firefoxDriver) { // Use Firefox in this test } @Test public void testWithChromeAndFirefox(ChromeDriver chromeDriver, FirefoxDriver firefoxDriver) { // Use Chrome and Firefox in this test } } We simply need to specify the type of browser to be used, as test or constructor parameters: • ChromeDriver • FirefoxDriver • OperaDriver • SafariDriver • EdgeDriver • InternetExplorerDriver • HtmlUnitDriver • PhantomJSDriver • AppiumDriver Internally, Selenium-Jupiter uses WebDriverManager to resolve properly the required binary drivers to control local browsers
  • 24. Selenium-Jupiter - Remote browsers • Selenium-Jupiter provides the annotation @DriverUrl to locate the Selenium or Appium server and @DriverCapabilities to specify the desired capabilities import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.Capabilities; import org.openqa.selenium.remote.RemoteWebDriver; import io.github.bonigarcia.DriverCapabilities; import io.github.bonigarcia.DriverUrl; import io.github.bonigarcia.SeleniumExtension; @ExtendWith(SeleniumExtension.class) public class SauceLabsJupiterTest { @DriverUrl String url = "https://ondemand.eu-central-1.saucelabs.com/wd/hub"; @DriverCapabilities DesiredCapabilities capabilities = new DesiredCapabilities(); { capabilities.setCapability("username", "<my-saucelabs-user>"); capabilities.setCapability("accessKey", "<my-saucelabs-key>"); capabilities.setCapability("browserName", "Chrome"); capabilities.setCapability("platform", "Windows 10"); capabilities.setCapability("version", "59.0"); capabilities.setCapability("name", "selenium-jupiter-and-saucelabs"); } @Test void testWithSaucelabs(RemoteWebDriver driver) { // test } }
  • 25. Selenium-Jupiter - Remote browsers • Selenium-Jupiter provides the annotation @DriverUrl to locate the Selenium or Appium server and @DriverCapabilities to specify the desired capabilities import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.remote.DesiredCapabilities; import io.appium.java_client.AppiumDriver; import io.github.bonigarcia.seljup.DriverCapabilities; import io.github.bonigarcia.seljup.DriverUrl; import io.github.bonigarcia.seljup.SeleniumExtension; @ExtendWith(SeleniumExtension.class) public class AppiumWithGlobalOptionsChromeJupiterTest { @DriverUrl String url = "http://localhost:4723/wd/hub"; @DriverCapabilities DesiredCapabilities capabilities = new DesiredCapabilities(); { capabilities.setCapability("browserName", "chrome"); capabilities.setCapability("deviceName", "Samsung Galaxy S6"); } @Test void testWithAndroid(AppiumDriver<WebElement> driver) { // test } }
  • 26. Selenium-Jupiter - Dockerized browsers • Selenium-Jupiter provides seamless integration with Docker • The annotation @DockerBrowser is used to declare a dockerized browsers. The supported browser are • Chrome, Firefox, and Opera: • Docker images for stable versions are maintained by Aerokube • Beta and unstable (Chrome and Firefox) are maintained by ElasTest • Edge and Internet Explorer: • Due to license, these Docker images are not hosted in Docker Hub • It can be built following a tutorial provided by Aerokube • Android devices: • Docker images for Android devices are maintained in the docker-android project (by Budi Utomo)
  • 27. Selenium-Jupiter - Dockerized browsers • Browser in Docker containers example: import static io.github.bonigarcia.BrowserType.CHROME; import static io.github.bonigarcia.BrowserType.FIREFOX; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.remote.RemoteWebDriver; import io.github.bonigarcia.DockerBrowser; import io.github.bonigarcia.SeleniumExtension; @ExtendWith(SeleniumExtension.class) public class DockerChromeJupiterTest { @Test public void testChrome(@DockerBrowser(type = CHROME) RemoteWebDriver driver) { // test } @Test public void testChromeWithVersion(@DockerBrowser(type = FIREFOX, version = "66.0") RemoteWebDriver driver) { // test } } Supported browser types are: CHROME, FIREFOX, OPERA, y EDGE , IEXPLORER and ANDROID The parameter version admits the following special values: latest, latest-*, beta, y unstable If version is not specified, the latest stable will be used. For that, Selenium- Jupiter internally connects to Docker Hub to find out the latest version (ever green Docker browser)
  • 28. Selenium-Jupiter - Dockerized browsers • Browsers in Docker containers can be used to create performance tests: import static io.github.bonigarcia.BrowserType.CHROME; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.remote.RemoteWebDriver; import java.util.List; import io.github.bonigarcia.DockerBrowser; import io.github.bonigarcia.SeleniumExtension; @ExtendWith(SeleniumExtension.class) public class DockerChromeJupiterTest { static final int NUM_BROWSERS = 10; @Test public void testPerformance( @DockerBrowser(type = CHROME, size = NUM_BROWSERS) List<RemoteWebDriver> driverList) { // test } } In this test, we will have 10 Chrome browsers ready to be used by the test logic
  • 29. Selenium-Jupiter - Dockerized browsers • Android in Docker container example: import static io.github.bonigarcia.BrowserType.ANDROID; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.remote.RemoteWebDriver; import io.github.bonigarcia.DockerBrowser; import io.github.bonigarcia.SeleniumExtension; @ExtendWith(SeleniumExtension.class) public class DockerAndroidCustomJupiterTest { @Test public void testAndroid(@DockerBrowser(type = ANDROID, version = "8.1", deviceName = "Nexus S") RemoteWebDriver driver) { // test } } When using Android in Docker containers, the type of device can be specified Android version API level Browser name 5.0.1 21 browser 5.1.1 22 browser 6.0 23 chrome 7.0 24 chrome 7.1.1 25 chrome 8.0 26 chrome 8.1 27 chrome 9.0 28 chrome Type Device name Phone Samsung Galaxy S6 Phone Nexus 4 Phone Nexus 5 Phone Nexus One Phone Nexus S Tablet Nexus 7
  • 30. Selenium-Jupiter - Dockerized browsers • When using Docker containers, it is possible to interact with the remote session using VNC (and also recording these sessions)
  • 31. Selenium-Jupiter - Test templates • Selenium-Jupiter use the JUnit 5’s support for test templates • A template defines the number and types of browser used by a test: 1. By means of a JSON file: import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.ExtendWith; import org.openqa.selenium.WebDriver; import io.github.bonigarcia.SeleniumExtension; @ExtendWith(SeleniumExtension.class) public class TemplateTest { @TestTemplate void templateTest(WebDriver driver) { // test } } { "browsers": [ [ { "type": "chrome-in-docker", "version": "latest" } ], [ { "type": "chrome-in-docker", "version": "latest-1" } ], [ { "type": "chrome-in-docker", "version": "beta" } ], [ { "type": "chrome-in-docker", "version": "unstable" } ] ] }
  • 32. Selenium-Jupiter - Test templates import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.RegisterExtension; import org.openqa.selenium.WebDriver; import io.github.bonigarcia.BrowserBuilder; import io.github.bonigarcia.BrowsersTemplate.Browser; import io.github.bonigarcia.SeleniumExtension; public class TemplateRegisterTest { @RegisterExtension static SeleniumExtension seleniumExtension = new SeleniumExtension(); @BeforeAll static void setup() { Browser chrome = BrowserBuilder.chrome().build(); Browser firefox = BrowserBuilder.firefox().build(); seleniumExtension.addBrowsers(chrome, firefox); } @TestTemplate void templateTest(WebDriver driver) { // ... } } • Selenium-Jupiter use the JUnit 5’s support for test templates • A template defines the number and types of browser used by a test: 2. Programmatically:
  • 33. Selenium-Jupiter - Configuration • Selenium-Jupiter is also highly configurable with: 1. Environment variables. For example 2. Java properties. For example: 3. Configuration manager in Java. For example: export SEL_JUP_VNC=true export SEL_JUP_RECORDING=true mvn test –Dsel.jup.vnc=true gradle test –Dsel.jup.vnc=true @RegisterExtension static SeleniumExtension seleniumExtension = new SeleniumExtension(); @BeforeAll static void setup() { seleniumExtension.getConfig().setVnc(true); seleniumExtension.getConfig().setRecording(true); }
  • 34. Selenium-Jupiter - Beyond Java • Selenium-Jupiter can be also used: 1. As CLI (command line interface) tool: 2. As server (using a REST-like API): > java -jar selenium-jupiter-3.2.0-fat.jar chrome [INFO] Using SeleniumJupiter to execute chrome (latest) in Docker [INFO] Using CHROME version 73.0 (latest) [INFO] Starting Docker container aerokube/selenoid:1.8.4 [DEBUG] Creating WebDriver for CHROME at http://172.17.0.1:32784/wd/hub Jan 07, 2019 6:55:17 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: OSS [INFO] Starting Docker container psharkey/novnc:3.3-t6 [INFO] Session id 8edd28c130bb2bc62f8e4467c20f4dc0 [INFO] VNC URL (copy and paste in a browser navigation bar to interact with remote session) [INFO] http://172.17.0.1:32785/vnc.html?host=172.17.0.1&port=32784&path=vnc/8edd28c130bb2bc62f8e44 67c20f4dc0&resize=scale&autoconnect=true&password=selenoid [INFO] Press ENTER to exit [INFO] Stopping Docker container aerokube/selenoid:1.8.4 [INFO] Stopping Docker container psharkey/novnc:3.3-t6 java -jar webdrivermanager-3.2.0-fat.jar server [INFO] Selenium-Jupiter server listening on http://localhost:4042/wd/hub Selenium-Jupiter becomes a Selenium Server Selenium-Jupiter allows to control Docker browsers through VNC
  • 35. Selenium-Jupiter - Conclusions • Selenium-Jupiter is a JUnit 5 extension for Selenium (WebDriver, Grid) and Appium
  • 36. Selenium-Jupiter - Conclusions • Selenium-Jupiter has much more features such as: • Using WebDriver @Options in tests (e.g. ChromeOptions, FirefoxOptions, etc.) • Screenshots at the end of test (as PNG image or Base64) • Integration with Jenkins (publishing test results in the Jenkins GUI) • Integration with Genymotion (cloud provider for Android devices) • Generic driver (configurable type of browser) • Single session (reuse browser in different tests) • Selenium-Jupiter is evolving in the near future. Its roadmap includes: • Improve test template support (e.g. specifying options within the template) • Improve scalability for performance tests (candidate technology: Kubernetes) https://bonigarcia.github.io/selenium-jupiter/
  • 37. Toolbox for Selenium Tests in Java: WebDriverManager and Selenium-Jupiter Thank you very much! Q&A Boni García boni.garcia@urjc.es http://bonigarcia.github.io/ @boni_gg https://github.com/bonigarcia