简体   繁体   中英

Run whole selenium project in docker (Gradle + Selenium + java + junit + docker)

My current project is java selenium (with selenide framework) auto-tests with gradle and junit.

Now, I want to wrap my whole project to docker container, to make it possible to run it on other machines using only docker.

As I see it:

  • User run my docker image
  • Image have installed java + chrome + selenium + gradle
  • Project tests launched within container.
  • (optional) image shares test results outside image (or I can connect to container and take a look at them).

What am I suppose to do?

A saw a lot of tutorials about browsers in containers, selenoid, etc.(which is cool).

But I can't find a solution for my question.

Thanks!

What you need to do is:

  1. Create a docker image that has Java, Chrome, selenium, gradle, junit, etc

  2. Once you have the image, run it on your local on any port example: 4444

  3. Switch to RemoteWebdriver

public static String remote_url_chrome = "http://localhost:4444/wd/hub";
ChromeOptions options = new ChromeOptions();
driver.set(new RemoteWebDriver(new URL(remote_url_chrome), options));
  1. Run the test now

Suggest to run tests as docker-compose multi-container application.

It will have 2 services in docker-compose as i see it:

  • browser - based on selenium Chrome browser image
  • tests - based on custom image extending java base image . Custom image Dockerfile should have gradle installed and tests jar file built in it.

Tests should drive Chrome browser using RemoteWebDriver initialized as below (note browser hostname where remote Chrome is listening).

public void createChromeDriverForRemote(){
    WebDriver driver = new RemoteWebDriver("http://browser:4444/wd/hub", DesiredCapabilities.chrome());
}

See quick start here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM