Setting up a Continuous Testing Environment With Selenium-Grid, Docker and Jenkins - Part 1

Ahmet Yasin Türkyılmaz
2 min readFeb 3, 2020

--

I would like to show you a way to make your tests work with Jenkins and how to make it continuously integrable. But first of all let’s talk about Selenium Grid.

With Selenium Grid’s Hub and node architecture, you can run your tests on different browsers and operating systems.

Hub is the place that you get your tests into. When you run your tests on your machine, Hub gets the test scripts and then run them in a node. There can be one or more nodes in a Hub. And these nodes can be different browsers or different platforms.

So you can build up your Hub on Amazon Web Service and set up a few nodes. After that you got yourself a fully integrable testing environment.

But before all of that let’s talk about how can you set your Selenium Grid on script side.

Part 1 - Setting Up Drivers and Maven Dependencies

public class BrowserSettings {
private WebDriver driver = null;
private Properties dataDrivenProperties;
DesiredCapabilities capability;

public BrowserSettings() {
dataDrivenProperties = new Properties();
try {
dataDrivenProperties.load(getClass().getClassLoader().getResourceAsStream("datadriven.properties.sample"));
} catch (IOException e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.getMessage(), e);
}
}

public WebDriver getWebDriver() throws IOException {
capability = DesiredCapabilities.chrome();
capability.setCapability("--no-sandbox", true);
capability.setCapability("--disable-impl-side-painting", true);
capability.setCapability("--disable-gpu", true);
capability.setCapability("--disable-gpu-sandbox", true);
capability.setCapability("--test-type=ui", true);
capability.setCapability("--disable-accelerated-2d-canvas", true);
capability.setCapability("--disable-accelerated-jpeg-decoding", true);

if (dataDrivenProperties.getProperty("browser").equals("chrome")) {
String localhost = "selenium-hub:4444";
driver = new RemoteWebDriver(new URL("http://" + localhost + "/wd/hub"), capability);
}

return driver;
}
}

As you can see, we created a new RemoteWebDriver with a URL of Selenium Grid’s Hub. WebDriver will start up a web browser on the computer where the code instantiates it, RemoteWebDriver also does the exact same thing. But the major difference between a WebDriver and a RemoteWebDriver is; RemoteWebDriver sends the request to open and control a web browser to a server.

If you can connect to a local Selenium server, you have the skill and knowledge to connect to a remote Selenium server. With that skill you can run your tests on different operating systems and different browsers in a very short time.

And we have the capability created from DesiredCapabilities.chrome(). Desired Capabilities can be used to set or get the browser name, operating system, version or as I used setting the capabilities method to prevent the issues that could effect the test process. You can find more of those settings on: https://peter.sh/experiments/chromium-command-line-switches/ .

Part-2 link: https://medium.com/@ahmet.turkyilmaz/setting-up-a-continuous-testing-environment-with-selenium-grid-docker-and-jenkins-part-2-4d165e8fb5a2

--

--

Ahmet Yasin Türkyılmaz

I am a Software Engineer studying Electronic Engineering in Gebze Technical University. And also working at Continuous Software.