I spent quite some time getting Selenium working on my development container. At the end, the solution was quite simple and I thought it would be a good idea to share it.
I have tried to get this running by installing all the required software on my development container directly, but nothing really seemed to work, specifically I was unable to successfully launch the Chrome.
Luckily, the solution is quite simple and as I was already using Docker compose anyway.
The solution that worked was to simply have a dedicated container to run a standalone Selenium instance.
myapp-chrome:
image: selenium/standalone-chrome:124.0
ports:
- "4444:4444"
- "7900:7900"
shm_size: "2g"
That’s basically it. To connect Selenium, I use these configuration options:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
options.addArguments("--disable-gpu");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--no-sandbox");
options.addArguments("window-size=1920,1080");
options.setAcceptInsecureCerts(true);
String hubUrl = "http://myapp-chrome:4444/wd/hub";
driver = new RemoteWebDriver(new URL(hubUrl), options);
Hope someone finds this useful. 🙂