Git Product home page Git Product logo

selenium-jupiter's Introduction

Maven Central Build Status Quality Gate codecov badge-jdk License badge Support badge Twitter

Selenium-Jupiter

Selenium-Jupiter is a JUnit 5 extension aimed to ease the use of Selenium (WebDriver and Grid) in JUnit 5 tests. This library is open source, released under the terms of Apache 2.0 License.

Basic usage

In order to include Selenium-Jupiter in a Maven project, first add the following dependency to your pom.xml (Java 8 required):

<dependency>
	<groupId>io.github.bonigarcia</groupId>
	<artifactId>selenium-jupiter</artifactId>
	<version>2.2.0</version>
</dependency>

Selenium-Jupiter is typically used by tests. In that case, the scope of the dependency should be test (<scope>test</scope>).

Once we have included this dependency, Selenium-Jupiter manages the WebDriver instances and inject them as parameters in your JUnit 5 tests:

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

import io.github.bonigarcia.SeleniumExtension;

@ExtendWith(SeleniumExtension.class)
public class SeleniumJupiterTest {

    @Test
    public void testChrome(ChromeDriver driver) {
    	// use chrome in this test
    }

    @Test
    public void testFirefox(FirefoxDriver driver) {
    	// use firefox in this test
    }

}

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

Docker browsers

As of version 2, Selenium-Jupiter allows to use browsers in Docker containers. The only requirement is to get installed Docker Engine in the machine running the tests. A simple example using this feature is the following:

import static io.github.bonigarcia.BrowserType.ANDROID;
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 SeleniumJupiterDockerTest {

    @Test
    public void testChrome(
            @DockerBrowser(type = CHROME, version = "latest") RemoteWebDriver driver) {
        // use Chrome (latest version) in this test
    }

    @Test
    public void testFirefox(
            @DockerBrowser(type = FIREFOX, version = "60.0") RemoteWebDriver driver) {
        // use Firefox (version 60.0) in this test
    }

    @Test
    public void testAndroid(
            @DockerBrowser(type = ANDROID, version = "7.1.1") RemoteWebDriver driver) {
        // use Android (version 7.1.1) in this test
    }

}

Documentation

You can find more details and examples on the Selenium-Jupiter user guide.

About

Selenium-Jupiter (Copyright © 2017-2018) is a project by Boni Garcia licensed under Apache 2.0 License. Comments, questions and suggestions are always very welcome!

selenium-jupiter's People

Contributors

bonigarcia avatar thc202 avatar alrega avatar sormuras avatar based2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.