SlideShare a Scribd company logo
Developing Selenium tests
with JUnit 5
Boni García
boni.garcia@uc3m.es http://bonigarcia.github.io/
@boni_gg https://github.com/bonigarcia
1. Introduction
https://bonigarcia.github.io/selenium-jupiter/
1. Introduction
• Source code: https://github.com/bonigarcia/selenium-jupiter
• Documentation: https://bonigarcia.github.io/selenium-jupiter
• Examples: https://github.com/bonigarcia/selenium-jupiter-
examples
Requirements to run these examples:
• Java
• An IDE or Maven/Gradle
• Docker Engine
• Linux (only required when running Android in Docker)
Table of Contents
1. Introduction
2. JUnit 5
• Introduction
• Architecture
• Support
• Setup
• Basic tests
• Assertions
• Parameterized tests
• Features
• Extension model
3. Selenium-Jupiter
4. Final remarks and future work
2. JUnit 5 - Introduction
• JUnit is the most popular testing framework
for Java and can be used to implement
different types of tests (unit, integration,
end-to-end, …)
• JUnit 5 (first GA released on September
2017) provides a brand-new programming an
extension model called Jupiter
https://junit.org/junit5/docs/current/user-guide/
2. JUnit 5 - Architecture
Revolutionary
Evolutionary
Necessary
2. JUnit 5 - Support
• JUnit 5 test can be executed in different ways:
1. Using a build tools:
2. Using an IDE:
3. Using the console launcher (standalone JAR provided by the
JUnit 5 team):
java -jar junit-platform-console-standalone-version.jar <Options>
2. JUnit 5 - Setup
• To execute JUnit 5 with Maven we need to configure pom.xml:
<properties>
<junit5.version>5.6.2</junit5.version>
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
To be precise, we need the API in
compile time for tests and the
engine in execution time
2. JUnit 5 - Setup
• To execute JUnit 5 with Gradle (4.8+) we need to configure build.gradle:
repositories {
mavenCentral()
}
ext {
junit5 = '5.6.2'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
options.compilerArgs += '-parameters'
}
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-engine:${junit5}")
}
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api:${junit5}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junit5}")
}
To be precise, we need the API in
compile time for tests and the
engine in execution time
2. JUnit 5 - Basic tests
• Basic tests in JUnit 5 are similar
to JUnit 4:
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
}
}
Methods are no
required to be
public anymore
The names of the
annotations for
test lifecycle have
changed in JUnit 5
2. JUnit 5 - Basic tests
• We can represent the basic test lifecycle as follows:
2. JUnit 5 - Assertions
• An assertion is a predicate (boolean function) that should be
evaluated to true to continue with the execution of the
program or test
2. JUnit 5 - Assertions
• JUnit 5 provides a rich variety of assertions (static methods of
the class Assertions):
• assertTrue, assertFalse, assertEquals, assertSame, …
• In addition, there is a number of Java libraries providing fluent
APIs for assertions, such as:
• Hamcrest: http://hamcrest.org/
• AssertJ: https://assertj.github.io/doc/
• Truth: https://truth.dev/
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>${truth.version}</version>
<scope>test</scope>
</dependency>
In the examples
repository, Truth is
used
2. JUnit 5 - Other features
• JUnit 5 has many features, such as:
• Parameterized tests
• Parallel execution
• Ordered tests
• Display names
• Assumptions
• Conditional test execution
• Tagging and filtering
• Nested tests
• Repeated tests
• Dynamic tests
• Timeouts
• …
https://junit.org/junit5/docs/current/user-guide/
2. JUnit 5 - Extension model
•The extension model of
Jupiter allows to add custom
features to the programming
model:
• Dependency injection in test
methods and constructors
• Custom logic in the test
lifecycle
• Test templates
Very convenient for Selenium!
Table of Contents
1. Introduction
2. JUnit 5
3. Selenium-Jupiter
• Motivation
• Setup
• Local browsers
• Remote browsers
• Docker browsers
• Test templates
• Integration with Jenkins
• Beyond Java
4. Final remarks and future work
3. Selenium-Jupiter - Motivation
• Selenium-Jupiter is a JUnit 5 extension aimed to ease the use
of Selenium from Java tests
https://bonigarcia.github.io/selenium-jupiter/
Clean test code (reduced boilerplate)
Effortless Docker integration (web
browsers and Android devices)
Advanced features for tests
3. Selenium-Jupiter - Setup
• Selenium-Jupiter can be included in a Java project as follows:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>selenium-jupiter</artifactId>
<version>3.3.5</version>
<scope>test</scope>
</dependency>
dependencies {
testCompile("io.github.bonigarcia:selenium-jupiter:3.3.5")
}
Using the latest version is
always recommended!
3. Selenium-Jupiter - Local browsers
• JUnit 4 and Selenium JUnit 5 and Selenium-Jupiter:
3. Selenium-Jupiter - Local browsers
• Selenium-Jupiter uses JUnit 5’s dependency injection:
@ExtendWith(SeleniumJupiter.class)
class SeleniumJupiterTest {
@Test
void test(ChromeDriver chromeDriver) {
// Use Chrome in this test
}
}
Valid types: ChromeDriver,
FirefoxDriver, OperaDriver,
SafariDriver, EdgeDriver,
InternetExplorerDriver,
HtmlUnitDriver, PhantomJSDriver,
AppiumDriver, SelenideDriver
Internally, Selenium-Jupiter uses WebDriverManager
to resolve properly the required browser drivers
(chromedriver in this example)
3. Selenium-Jupiter - Remote browsers
• Selenium-Jupiter provides the annotations @DriverUrl and
@DriverCapabilities to control remote browsers and
mobiles, e.g.:
https://saucelabs.com/
http://appium.io/
3. Selenium-Jupiter - Docker browsers
• Docker is a software technology which
allows to pack and run any application
as a lightweight and portable container
• The Docker platform has two main
components: the Docker Engine, to
create and execute containers; and the
Docker Hub (https://hub.docker.com/),
a cloud service for distributing
containers
https://www.docker.com/
3. Selenium-Jupiter - Docker browsers
• Selenium-Jupiter provides seamless integration with
Docker using the annotation @DockerBrowser:
• 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 (docker-android project) by Budi Utomo
3. Selenium-Jupiter - Docker browsers
@ExtendWith(SeleniumJupiter.class)
class DockerBasicTest {
@Test
void testFirefoxBeta(
@DockerBrowser(type = FIREFOX, version = "beta") RemoteWebDriver driver) {
driver.get("https://bonigarcia.github.io/selenium-jupiter/");
assertThat(driver.getTitle(),
containsString("JUnit 5 extension for Selenium"));
}
}
Supported browser types are: CHROME,
FIREFOX, OPERA, EDGE , IEXPLORER and
ANDROID
If version is not specified, the latest container version in Docker Hub
is pulled. This parameter allows fixed versions and also the special
values: latest, latest-*, beta, and unstable
3. Selenium-Jupiter - Docker browsers
• The use of Docker enables a rich number of features:
• Remote session access with VNC
• Session recordings
• Performance tests
3. Selenium-Jupiter - Docker browsers
• The possible Android setup options are the following:
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
3. Selenium-Jupiter - Test templates
• Selenium-Jupiter use the JUnit 5’s support for test templates:
@ExtendWith(SeleniumJupiter.class)
public class TemplateTest {
@TestTemplate
void templateTest(WebDriver driver) {
// test
}
}
3. Selenium-Jupiter - Integration with Jenkins
• Seamless integration with Jenkins
through the Jenkins attachment plugin
• It allows to attach output files in tests
(e.g. PNG screenshots and MP4
recordings) in the Jenkins GUI
• For example:
$ mvn clean test -Dtest=DockerRecordingTest 
-Dsel.jup.recording=true 
-Dsel.jup.screenshot.at.the.end.of.tests=true 
-Dsel.jup.screenshot.format=png 
-Dsel.jup.output.folder=surefire-reports
3. Selenium-Jupiter - Beyond Java
• Selenium-Jupiter can be also used:
1. As CLI (Command Line Interface) tool:
2. As a server (using a REST-like API):
$ java -jar selenium-jupiter-3.3.5-fat.jar chrome unstable
[INFO] Using Selenium-Jupiter to execute chrome unstable in Docker
...
Selenium-Jupiter allows to control
Docker browsers through VNC
(manual testing)
$ java -jar selenium-jupiter-3.3.5-fat.jar server
[INFO] Selenium-Jupiter server listening on http://localhost:4042/wd/hub
Selenium-Jupiter becomes into a
Selenium Server (Hub)
Table of Contents
1. Introduction
2. JUnit 5
3. Selenium-Jupiter
4. Final remarks and future work
4. Final remarks and future work
• Selenium-Jupiter has another features such as:
• Generic driver (configurable type of browser)
• Mapping volumes in Docker containers
• Access to Docker client to manage custom containers
• Selenium-Jupiter is in constant development. Its roadmap
includes:
• Improve test template support (e.g. specifying options)
• Improve scalability for performance tests using Kubernetes
• Enhance diagnostic capabilities (gathering mechanism for the
browser console)
Developing Selenium tests
with JUnit 5
Thank you very much!
Boni García
boni.garcia@uc3m.es http://bonigarcia.github.io/
@boni_gg https://github.com/bonigarcia

More Related Content

What's hot

An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
Joao Pereira
 
Test ng
Test ngTest ng
Test ng
fbenault
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
boyw165
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
chrisb206 chrisb206
 
How to setup unit testing in Android Studio
How to setup unit testing in Android StudioHow to setup unit testing in Android Studio
How to setup unit testing in Android Studio
tobiaspreuss
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
Tomer Gabel
 
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos SanchezMaven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
mfrancis
 
Eclipse IDE, 2019.09, Java Development
Eclipse IDE, 2019.09, Java Development Eclipse IDE, 2019.09, Java Development
Eclipse IDE, 2019.09, Java Development
Pei-Hsuan Hsieh
 
Maven
MavenMaven
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
Luciano Resende
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-in
Tonny Madsen
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
Manos Georgopoulos
 
Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
Colombo Selenium Meetup
 
TestNg_Overview_Config
TestNg_Overview_ConfigTestNg_Overview_Config
TestNg_Overview_Config
Abhishek Chakraborty
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
FastConnect
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
Denis Bazhin
 
Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)
Marakana Inc.
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
Mike Desjardins
 
Testing with Spring 4.x
Testing with Spring 4.xTesting with Spring 4.x
Testing with Spring 4.x
Sam Brannen
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla
 

What's hot (20)

An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Test ng
Test ngTest ng
Test ng
 
Note - Apache Maven Intro
Note - Apache Maven IntroNote - Apache Maven Intro
Note - Apache Maven Intro
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
How to setup unit testing in Android Studio
How to setup unit testing in Android StudioHow to setup unit testing in Android Studio
How to setup unit testing in Android Studio
 
Maven for Dummies
Maven for DummiesMaven for Dummies
Maven for Dummies
 
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos SanchezMaven, Eclipse and OSGi Working Together - Carlos Sanchez
Maven, Eclipse and OSGi Working Together - Carlos Sanchez
 
Eclipse IDE, 2019.09, Java Development
Eclipse IDE, 2019.09, Java Development Eclipse IDE, 2019.09, Java Development
Eclipse IDE, 2019.09, Java Development
 
Maven
MavenMaven
Maven
 
Tuscany : Applying OSGi After The Fact
Tuscany : Applying  OSGi After The FactTuscany : Applying  OSGi After The Fact
Tuscany : Applying OSGi After The Fact
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-in
 
Introduction to maven
Introduction to mavenIntroduction to maven
Introduction to maven
 
Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
 
TestNg_Overview_Config
TestNg_Overview_ConfigTestNg_Overview_Config
TestNg_Overview_Config
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)Learn How to Unit Test Your Android Application (with Robolectric)
Learn How to Unit Test Your Android Application (with Robolectric)
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Testing with Spring 4.x
Testing with Spring 4.xTesting with Spring 4.x
Testing with Spring 4.x
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 

Similar to Developing Selenium tests with JUnit 5

Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
Sergii Fesenko
 
Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.
Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.
Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.
Richard Langlois P. Eng.
 
Automated Testing on Web Applications
Automated Testing on Web ApplicationsAutomated Testing on Web Applications
Automated Testing on Web Applications
Samuel Borg
 
Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
Mihai-Cristian Fratila
 
Selenium Introduction
Selenium IntroductionSelenium Introduction
Selenium Introduction
Mayur Khairnar
 
Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With Selenium
Jodie Miners
 
Selenium (1)
Selenium (1)Selenium (1)
Selenium (1)
onlinemindq
 
TestNGvsJUnit
TestNGvsJUnitTestNGvsJUnit
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
NaviAningi
 
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.pptKKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
Kiran Kumar SD
 
Test it! Unit, mocking and in-container Meet Arquillian!
Test it! Unit, mocking and in-container Meet Arquillian!Test it! Unit, mocking and in-container Meet Arquillian!
Test it! Unit, mocking and in-container Meet Arquillian!
Ivan Ivanov
 
The Test way
The Test wayThe Test way
The Test way
Mikhail Grinfeld
 
First steps with selenium rc
First steps with selenium rcFirst steps with selenium rc
First steps with selenium rc
Dang Nguyen
 
How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?
Dmitry Buzdin
 
Sel
SelSel
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
Vijay Rangaiah
 
Sakai10 Selenium Workshop
Sakai10 Selenium WorkshopSakai10 Selenium Workshop
Sakai10 Selenium Workshop
coreyjack
 
jQuery Chicago 2014 - Next-generation JavaScript Testing
jQuery Chicago 2014 - Next-generation JavaScript TestingjQuery Chicago 2014 - Next-generation JavaScript Testing
jQuery Chicago 2014 - Next-generation JavaScript Testing
Vlad Filippov
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
How to use_cucumber_rest-assured_api_framework
How to use_cucumber_rest-assured_api_frameworkHow to use_cucumber_rest-assured_api_framework
How to use_cucumber_rest-assured_api_framework
Harshad Ingle
 

Similar to Developing Selenium tests with JUnit 5 (20)

Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
 
Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.
Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.
Continuous Test Automation, by Richard Langlois P. Eng. and Yuri Pechenko.
 
Automated Testing on Web Applications
Automated Testing on Web ApplicationsAutomated Testing on Web Applications
Automated Testing on Web Applications
 
Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
 
Selenium Introduction
Selenium IntroductionSelenium Introduction
Selenium Introduction
 
Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With Selenium
 
Selenium (1)
Selenium (1)Selenium (1)
Selenium (1)
 
TestNGvsJUnit
TestNGvsJUnitTestNGvsJUnit
TestNGvsJUnit
 
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
 
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.pptKKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
 
Test it! Unit, mocking and in-container Meet Arquillian!
Test it! Unit, mocking and in-container Meet Arquillian!Test it! Unit, mocking and in-container Meet Arquillian!
Test it! Unit, mocking and in-container Meet Arquillian!
 
The Test way
The Test wayThe Test way
The Test way
 
First steps with selenium rc
First steps with selenium rcFirst steps with selenium rc
First steps with selenium rc
 
How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?
 
Sel
SelSel
Sel
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
 
Sakai10 Selenium Workshop
Sakai10 Selenium WorkshopSakai10 Selenium Workshop
Sakai10 Selenium Workshop
 
jQuery Chicago 2014 - Next-generation JavaScript Testing
jQuery Chicago 2014 - Next-generation JavaScript TestingjQuery Chicago 2014 - Next-generation JavaScript Testing
jQuery Chicago 2014 - Next-generation JavaScript Testing
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
How to use_cucumber_rest-assured_api_framework
How to use_cucumber_rest-assured_api_frameworkHow to use_cucumber_rest-assured_api_framework
How to use_cucumber_rest-assured_api_framework
 

More from Boni García

APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Selenium Manager: Automated Driver & Browser Management for Selenium WebDriver
Selenium Manager: Automated Driver & Browser Management for Selenium WebDriverSelenium Manager: Automated Driver & Browser Management for Selenium WebDriver
Selenium Manager: Automated Driver & Browser Management for Selenium WebDriver
Boni García
 
WebDriverManager: the Swiss Army Knife for Selenium WebDriver
WebDriverManager: the Swiss Army Knife for Selenium WebDriverWebDriverManager: the Swiss Army Knife for Selenium WebDriver
WebDriverManager: the Swiss Army Knife for Selenium WebDriver
Boni García
 
Extending WebDriver: A cloud approach
Extending WebDriver: A cloud approachExtending WebDriver: A cloud approach
Extending WebDriver: A cloud approach
Boni García
 
A Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test CasesA Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test Cases
Boni García
 
Introducción y novedades de JUnit 5 (04/07/2018)
Introducción y novedades de JUnit 5 (04/07/2018)Introducción y novedades de JUnit 5 (04/07/2018)
Introducción y novedades de JUnit 5 (04/07/2018)
Boni García
 
User Impersonation as a Service in End-to-End Testing
User Impersonation as a Service in End-to-End TestingUser Impersonation as a Service in End-to-End Testing
User Impersonation as a Service in End-to-End Testing
Boni García
 
Introducción y novedades de JUnit 5 (16/01/2018)
Introducción y novedades de JUnit 5 (16/01/2018)Introducción y novedades de JUnit 5 (16/01/2018)
Introducción y novedades de JUnit 5 (16/01/2018)
Boni García
 
WebRTC Testing: State of the Art
WebRTC Testing: State of the ArtWebRTC Testing: State of the Art
WebRTC Testing: State of the Art
Boni García
 
ElasTest: an elastic platform for testing complex distributed large software ...
ElasTest: an elastic platform for testing complex distributed large software ...ElasTest: an elastic platform for testing complex distributed large software ...
ElasTest: an elastic platform for testing complex distributed large software ...
Boni García
 
Analysis of video quality and end-to-end latency in WebRTC
Analysis of video quality and end-to-end latency in WebRTCAnalysis of video quality and end-to-end latency in WebRTC
Analysis of video quality and end-to-end latency in WebRTC
Boni García
 
NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
Boni García
 
NUBOMEDIA Webinar
NUBOMEDIA WebinarNUBOMEDIA Webinar
NUBOMEDIA Webinar
Boni García
 
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
Boni García
 
Cloud Instances of Kurento v6 on FIWARE Lab
Cloud Instances of Kurento v6 on FIWARE LabCloud Instances of Kurento v6 on FIWARE Lab
Cloud Instances of Kurento v6 on FIWARE Lab
Boni García
 
Kurento v6 Development Guide
Kurento v6 Development GuideKurento v6 Development Guide
Kurento v6 Development Guide
Boni García
 
Kurento v6 Installation Guide
Kurento v6 Installation GuideKurento v6 Installation Guide
Kurento v6 Installation Guide
Boni García
 
Introduction to the Stream Oriented GE (Kurento v6)
Introduction to the Stream Oriented GE (Kurento v6)Introduction to the Stream Oriented GE (Kurento v6)
Introduction to the Stream Oriented GE (Kurento v6)
Boni García
 

More from Boni García (18)

APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Selenium Manager: Automated Driver & Browser Management for Selenium WebDriver
Selenium Manager: Automated Driver & Browser Management for Selenium WebDriverSelenium Manager: Automated Driver & Browser Management for Selenium WebDriver
Selenium Manager: Automated Driver & Browser Management for Selenium WebDriver
 
WebDriverManager: the Swiss Army Knife for Selenium WebDriver
WebDriverManager: the Swiss Army Knife for Selenium WebDriverWebDriverManager: the Swiss Army Knife for Selenium WebDriver
WebDriverManager: the Swiss Army Knife for Selenium WebDriver
 
Extending WebDriver: A cloud approach
Extending WebDriver: A cloud approachExtending WebDriver: A cloud approach
Extending WebDriver: A cloud approach
 
A Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test CasesA Proposal to Orchestrate Test Cases
A Proposal to Orchestrate Test Cases
 
Introducción y novedades de JUnit 5 (04/07/2018)
Introducción y novedades de JUnit 5 (04/07/2018)Introducción y novedades de JUnit 5 (04/07/2018)
Introducción y novedades de JUnit 5 (04/07/2018)
 
User Impersonation as a Service in End-to-End Testing
User Impersonation as a Service in End-to-End TestingUser Impersonation as a Service in End-to-End Testing
User Impersonation as a Service in End-to-End Testing
 
Introducción y novedades de JUnit 5 (16/01/2018)
Introducción y novedades de JUnit 5 (16/01/2018)Introducción y novedades de JUnit 5 (16/01/2018)
Introducción y novedades de JUnit 5 (16/01/2018)
 
WebRTC Testing: State of the Art
WebRTC Testing: State of the ArtWebRTC Testing: State of the Art
WebRTC Testing: State of the Art
 
ElasTest: an elastic platform for testing complex distributed large software ...
ElasTest: an elastic platform for testing complex distributed large software ...ElasTest: an elastic platform for testing complex distributed large software ...
ElasTest: an elastic platform for testing complex distributed large software ...
 
Analysis of video quality and end-to-end latency in WebRTC
Analysis of video quality and end-to-end latency in WebRTCAnalysis of video quality and end-to-end latency in WebRTC
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: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
NUBOMEDIA: an Elastic PaaS Enabling the Convergence of Real-Time and Big Data...
 
NUBOMEDIA Webinar
NUBOMEDIA WebinarNUBOMEDIA Webinar
NUBOMEDIA Webinar
 
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
WebRTC/Kurento/NUBOMEDIA Hackathon at IETF’96
 
Cloud Instances of Kurento v6 on FIWARE Lab
Cloud Instances of Kurento v6 on FIWARE LabCloud Instances of Kurento v6 on FIWARE Lab
Cloud Instances of Kurento v6 on FIWARE Lab
 
Kurento v6 Development Guide
Kurento v6 Development GuideKurento v6 Development Guide
Kurento v6 Development Guide
 
Kurento v6 Installation Guide
Kurento v6 Installation GuideKurento v6 Installation Guide
Kurento v6 Installation Guide
 
Introduction to the Stream Oriented GE (Kurento v6)
Introduction to the Stream Oriented GE (Kurento v6)Introduction to the Stream Oriented GE (Kurento v6)
Introduction to the Stream Oriented GE (Kurento v6)
 

Recently uploaded

Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
Drona Infotech
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
ssuserad3af4
 

Recently uploaded (20)

Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
 

Developing Selenium tests with JUnit 5

  • 1. Developing Selenium tests with JUnit 5 Boni García boni.garcia@uc3m.es http://bonigarcia.github.io/ @boni_gg https://github.com/bonigarcia
  • 3. 1. Introduction • Source code: https://github.com/bonigarcia/selenium-jupiter • Documentation: https://bonigarcia.github.io/selenium-jupiter • Examples: https://github.com/bonigarcia/selenium-jupiter- examples Requirements to run these examples: • Java • An IDE or Maven/Gradle • Docker Engine • Linux (only required when running Android in Docker)
  • 4. Table of Contents 1. Introduction 2. JUnit 5 • Introduction • Architecture • Support • Setup • Basic tests • Assertions • Parameterized tests • Features • Extension model 3. Selenium-Jupiter 4. Final remarks and future work
  • 5. 2. JUnit 5 - Introduction • JUnit is the most popular testing framework for Java and can be used to implement different types of tests (unit, integration, end-to-end, …) • JUnit 5 (first GA released on September 2017) provides a brand-new programming an extension model called Jupiter https://junit.org/junit5/docs/current/user-guide/
  • 6. 2. JUnit 5 - Architecture Revolutionary Evolutionary Necessary
  • 7. 2. JUnit 5 - Support • JUnit 5 test can be executed in different ways: 1. Using a build tools: 2. Using an IDE: 3. Using the console launcher (standalone JAR provided by the JUnit 5 team): java -jar junit-platform-console-standalone-version.jar <Options>
  • 8. 2. JUnit 5 - Setup • To execute JUnit 5 with Maven we need to configure pom.xml: <properties> <junit5.version>5.6.2</junit5.version> <maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version> </properties> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>${junit5.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${maven-surefire-plugin.version}</version> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>${junit5.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>${junit5.version}</version> <scope>runtime</scope> </dependency> </dependencies> To be precise, we need the API in compile time for tests and the engine in execution time
  • 9. 2. JUnit 5 - Setup • To execute JUnit 5 with Gradle (4.8+) we need to configure build.gradle: repositories { mavenCentral() } ext { junit5 = '5.6.2' } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' test { useJUnitPlatform() testLogging { events "passed", "skipped", "failed" } } compileTestJava { sourceCompatibility = 1.8 targetCompatibility = 1.8 options.compilerArgs += '-parameters' } dependencies { testCompile("org.junit.jupiter:junit-jupiter-engine:${junit5}") } dependencies { testCompile("org.junit.jupiter:junit-jupiter-api:${junit5}") testRuntime("org.junit.jupiter:junit-jupiter-engine:${junit5}") } To be precise, we need the API in compile time for tests and the engine in execution time
  • 10. 2. JUnit 5 - Basic tests • Basic tests in JUnit 5 are similar to JUnit 4: 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 } } Methods are no required to be public anymore The names of the annotations for test lifecycle have changed in JUnit 5
  • 11. 2. JUnit 5 - Basic tests • We can represent the basic test lifecycle as follows:
  • 12. 2. JUnit 5 - Assertions • An assertion is a predicate (boolean function) that should be evaluated to true to continue with the execution of the program or test
  • 13. 2. JUnit 5 - Assertions • JUnit 5 provides a rich variety of assertions (static methods of the class Assertions): • assertTrue, assertFalse, assertEquals, assertSame, … • In addition, there is a number of Java libraries providing fluent APIs for assertions, such as: • Hamcrest: http://hamcrest.org/ • AssertJ: https://assertj.github.io/doc/ • Truth: https://truth.dev/ <dependency> <groupId>com.google.truth</groupId> <artifactId>truth</artifactId> <version>${truth.version}</version> <scope>test</scope> </dependency> In the examples repository, Truth is used
  • 14. 2. JUnit 5 - Other features • JUnit 5 has many features, such as: • Parameterized tests • Parallel execution • Ordered tests • Display names • Assumptions • Conditional test execution • Tagging and filtering • Nested tests • Repeated tests • Dynamic tests • Timeouts • … https://junit.org/junit5/docs/current/user-guide/
  • 15. 2. JUnit 5 - Extension model •The extension model of Jupiter allows to add custom features to the programming model: • Dependency injection in test methods and constructors • Custom logic in the test lifecycle • Test templates Very convenient for Selenium!
  • 16. Table of Contents 1. Introduction 2. JUnit 5 3. Selenium-Jupiter • Motivation • Setup • Local browsers • Remote browsers • Docker browsers • Test templates • Integration with Jenkins • Beyond Java 4. Final remarks and future work
  • 17. 3. Selenium-Jupiter - Motivation • Selenium-Jupiter is a JUnit 5 extension aimed to ease the use of Selenium from Java tests https://bonigarcia.github.io/selenium-jupiter/ Clean test code (reduced boilerplate) Effortless Docker integration (web browsers and Android devices) Advanced features for tests
  • 18. 3. Selenium-Jupiter - Setup • Selenium-Jupiter can be included in a Java project as follows: <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>selenium-jupiter</artifactId> <version>3.3.5</version> <scope>test</scope> </dependency> dependencies { testCompile("io.github.bonigarcia:selenium-jupiter:3.3.5") } Using the latest version is always recommended!
  • 19. 3. Selenium-Jupiter - Local browsers • JUnit 4 and Selenium JUnit 5 and Selenium-Jupiter:
  • 20. 3. Selenium-Jupiter - Local browsers • Selenium-Jupiter uses JUnit 5’s dependency injection: @ExtendWith(SeleniumJupiter.class) class SeleniumJupiterTest { @Test void test(ChromeDriver chromeDriver) { // Use Chrome in this test } } Valid types: ChromeDriver, FirefoxDriver, OperaDriver, SafariDriver, EdgeDriver, InternetExplorerDriver, HtmlUnitDriver, PhantomJSDriver, AppiumDriver, SelenideDriver Internally, Selenium-Jupiter uses WebDriverManager to resolve properly the required browser drivers (chromedriver in this example)
  • 21. 3. Selenium-Jupiter - Remote browsers • Selenium-Jupiter provides the annotations @DriverUrl and @DriverCapabilities to control remote browsers and mobiles, e.g.: https://saucelabs.com/ http://appium.io/
  • 22. 3. Selenium-Jupiter - Docker browsers • Docker is a software technology which allows to pack and run any application as a lightweight and portable container • The Docker platform has two main components: the Docker Engine, to create and execute containers; and the Docker Hub (https://hub.docker.com/), a cloud service for distributing containers https://www.docker.com/
  • 23. 3. Selenium-Jupiter - Docker browsers • Selenium-Jupiter provides seamless integration with Docker using the annotation @DockerBrowser: • 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 (docker-android project) by Budi Utomo
  • 24. 3. Selenium-Jupiter - Docker browsers @ExtendWith(SeleniumJupiter.class) class DockerBasicTest { @Test void testFirefoxBeta( @DockerBrowser(type = FIREFOX, version = "beta") RemoteWebDriver driver) { driver.get("https://bonigarcia.github.io/selenium-jupiter/"); assertThat(driver.getTitle(), containsString("JUnit 5 extension for Selenium")); } } Supported browser types are: CHROME, FIREFOX, OPERA, EDGE , IEXPLORER and ANDROID If version is not specified, the latest container version in Docker Hub is pulled. This parameter allows fixed versions and also the special values: latest, latest-*, beta, and unstable
  • 25. 3. Selenium-Jupiter - Docker browsers • The use of Docker enables a rich number of features: • Remote session access with VNC • Session recordings • Performance tests
  • 26. 3. Selenium-Jupiter - Docker browsers • The possible Android setup options are the following: 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
  • 27. 3. Selenium-Jupiter - Test templates • Selenium-Jupiter use the JUnit 5’s support for test templates: @ExtendWith(SeleniumJupiter.class) public class TemplateTest { @TestTemplate void templateTest(WebDriver driver) { // test } }
  • 28. 3. Selenium-Jupiter - Integration with Jenkins • Seamless integration with Jenkins through the Jenkins attachment plugin • It allows to attach output files in tests (e.g. PNG screenshots and MP4 recordings) in the Jenkins GUI • For example: $ mvn clean test -Dtest=DockerRecordingTest -Dsel.jup.recording=true -Dsel.jup.screenshot.at.the.end.of.tests=true -Dsel.jup.screenshot.format=png -Dsel.jup.output.folder=surefire-reports
  • 29. 3. Selenium-Jupiter - Beyond Java • Selenium-Jupiter can be also used: 1. As CLI (Command Line Interface) tool: 2. As a server (using a REST-like API): $ java -jar selenium-jupiter-3.3.5-fat.jar chrome unstable [INFO] Using Selenium-Jupiter to execute chrome unstable in Docker ... Selenium-Jupiter allows to control Docker browsers through VNC (manual testing) $ java -jar selenium-jupiter-3.3.5-fat.jar server [INFO] Selenium-Jupiter server listening on http://localhost:4042/wd/hub Selenium-Jupiter becomes into a Selenium Server (Hub)
  • 30. Table of Contents 1. Introduction 2. JUnit 5 3. Selenium-Jupiter 4. Final remarks and future work
  • 31. 4. Final remarks and future work • Selenium-Jupiter has another features such as: • Generic driver (configurable type of browser) • Mapping volumes in Docker containers • Access to Docker client to manage custom containers • Selenium-Jupiter is in constant development. Its roadmap includes: • Improve test template support (e.g. specifying options) • Improve scalability for performance tests using Kubernetes • Enhance diagnostic capabilities (gathering mechanism for the browser console)
  • 32. Developing Selenium tests with JUnit 5 Thank you very much! Boni García boni.garcia@uc3m.es http://bonigarcia.github.io/ @boni_gg https://github.com/bonigarcia