Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 343
TemirlanU Avatar asked Aug 05 '26 13:08

TemirlanU


1 Answers

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

like image 169
rok Avatar answered Aug 08 '26 02:08

rok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!