• Stars
    star
    225
  • Rank 177,187 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JUnit 5 extension for Selenium WebDriver

Maven Central Build Status Quality Gate codecov badge-jdk License badge Backers on Open Collective Sponsors on Open Collective Support badge Twitter Follow

Selenium-Jupiter is an open-source Java library that implements a JUnit 5 extension for developing Selenium WebDriver tests. Selenium-Jupiter uses several features of the Jupiter extension (such as parameters resolution, test templates, or conditional test execution). Thanks to this, the resulting Selenium-Jupiter tests follow a minimalist approach (i.e., the required boilerplate code for WebDriver is reduced) while providing a wide range of advanced features for end-to-end testing.

Documentation

You can find the complete documentation of Selenium-Jupiter here. This site contains all the features, examples, and configuration capabilities of Selenium-Jupiter.

Local browsers

Selenium-Jupiter can be used to control local browsers programmatically using Selenium WebDriver. To do that, we need to specify the flavor of the browser to be used by declaring WebDriver parameters in tests or constructors. For instance, we declare a ChromeDriver parameter to use Chrome, FirefoxDriver for Firefox, and so on. For instance:

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.chrome.ChromeDriver;

import io.github.bonigarcia.seljup.SeleniumJupiter;

@ExtendWith(SeleniumJupiter.class)
class ChromeTest {

    @Test
    void test(ChromeDriver driver) {
        driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
        assertThat(driver.getTitle()).contains("Selenium WebDriver");
    }

}

Internally, Selenium-Jupiter uses WebDriverManager to manage the WebDriver binaries (i.e., chromedriver, geckodriver, etc.) required to use local browsers.

Browsers in Docker containers

Selenium-Jupiter allows using browsers in Docker containers very easily. The only requirement is to get installed Docker Engine in the machine running the tests. The following example shows a test using this feature. Internally, it pulls the image from Docker Hub, starts the container, and instantiates the WebDriver object to use it. This example also enables the recording of the browser session and remote access using noVNC:

import static io.github.bonigarcia.seljup.BrowserType.CHROME;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.WebDriver;

import io.github.bonigarcia.seljup.DockerBrowser;
import io.github.bonigarcia.seljup.SeleniumJupiter;

@ExtendWith(SeleniumJupiter.class)
class DockerChromeTest {

    @Test
    void testChrome(@DockerBrowser(type = CHROME) WebDriver driver) {
        driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
        assertThat(driver.getTitle()).contains("Selenium WebDriver");
    }

}

Conditional tests

Selenium-Jupiter provides the class-level annotation @EnabledIfBrowserAvailable to skip tests conditionally depending on the availability of local browsers. For example:

import static io.github.bonigarcia.seljup.Browser.SAFARI;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.safari.SafariDriver;

import io.github.bonigarcia.seljup.EnabledIfBrowserAvailable;
import io.github.bonigarcia.seljup.SeleniumJupiter;

@EnabledIfBrowserAvailable(SAFARI)
@ExtendWith(SeleniumJupiter.class)
class SafariTest {

    @Test
    void test(SafariDriver driver) {
        driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
        assertThat(driver.getTitle()).contains("Selenium WebDriver");
    }

}

Test templates

Test templates are a special kind of test in which the same test logic is executed several times according to some custom data. In Selenium-Jupiter, the data to feed a test template is referred to as the browser scenario (a JSON file by default).

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.WebDriver;

import io.github.bonigarcia.seljup.SeleniumJupiter;

@ExtendWith(SeleniumJupiter.class)
class TemplateTest {

    @TestTemplate
    void templateTest(WebDriver driver) {
        driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
        assertThat(driver.getTitle()).contains("Selenium WebDriver");
    }

}

... and the browser scenario is:

{
   "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": "dev"
         }
      ]
   ]
}

Support

Selenium-Jupiter is part of OpenCollective, an online funding platform for open and transparent communities. You can support the project by contributing as a backer (i.e., a personal donation or recurring contribution) or as a sponsor (i.e., a recurring contribution by a company).

Backers

Sponsors

Alternatively, you can acknowledge my work by buying me a coffee:



About

Selenium-Jupiter (Copyright © 2017-2023) is a project created and maintained by [Boni García] and licensed under the terms of the Apache 2.0 License.

If you like my work, please consider nominating me for the GitHub Stars program.

More Repositories

1

webdrivermanager

Automated driver management and other helper features for Selenium WebDriver in Java
Java
2,364
star
2

mastering-junit5

Examples of the Packt book "Mastering Software Testing with JUnit 5"
Java
363
star
3

dualsub

DualSub: bilingual subtitles maker
Java
172
star
4

selenium-webdriver-java

Examples of the O'Reilly book "Hands-On Selenium WebDriver with Java"
Java
111
star
5

webdrivermanager-examples

JUnit tests with Selenium WebDriver and WebDriverManager
Java
111
star
6

rate-my-cat

Sample application for the book "Mastering Software Testing with JUnit 5"
Java
25
star
7

novnc

Standalone noVNC client based on Alpine
Dockerfile
21
star
8

web-programming-examples

Examples of web applications using Java and Angular, among other technologies
HTML
20
star
9

bonigarcia.github.io

Personal web page of Boni García
JavaScript
16
star
10

webgl-examples

webgl-examples
HTML
13
star
11

webdrivermanager-spring-boot

Basic project with JUnit tests using Spring-Boot, Selenium WebDriver and WebDriverManager
Java
11
star
12

selenium-jupiter-examples

Test examples using Selenium-Jupiter, Selenium WebDriver, and JUnit 5
Java
10
star
13

webdrivermanager-basic

Basic project with JUnit tests using Selenium Webdriver and WebDriverManager
Java
8
star
14

browserwatcher

Browser extension for console monitoring, tab recording, Content Security Policy (CSP) disabling, and JavaScript/CSS injection
Java
8
star
15

rust-examples

Small programs written in Rust. Warm up for the upcoming Selenium Manager
Rust
7
star
16

android-examples

Sample Android apps created with Java
Java
5
star
17

selenium-jupiter-webrtc

Tests for WebRTC applications using Selenium-Jupiter
Java
5
star
18

android-basic-app

Basic Android app developed with Java
Java
5
star
19

c-examples

Basic C examples
C
4
star
20

react-native-examples

Basic apps using React Native
JavaScript
3
star
21

wdm-agent-example

Example of maven project using Selenium WebDriver and WebDriverManager as Agent
Java
3
star
22

job-tracker

Scheduled automated test for daily tracking jobs about Selenium, Cypress, Puppeteer, and Playwright on Linkedin
Java
3
star
23

test-orchestration

Jenkins library for test orchestration
Groovy
3
star
24

spark-examples

Collection of Spark examples using Python
Python
2
star
25

nodejs-examples

Node.js examples
JavaScript
2
star
26

git-intro

2
star
27

bonigarcia

Visiting Professor @UC3M, Staff Software Engineer @saucelabs, Committer @SeleniumHQ
1
star
28

nlp-examples

Natural Language Processing (NLP) examples with Python
Jupyter Notebook
1
star
29

saucelabs-fat-jars

Basic projects to illustrate how to create fat-jars with Maven and Gradle
Java
1
star
30

genai-selenium

GenAI-assisted development of Selenium tests
Java
1
star
31

nubomedia-test

NUBOMEDIA application example
Java
1
star