Configure Selenide to work with Selenoid

Aliaksandr Rasolka
2 min readMay 28, 2019

In this story I will consider several integration options: very simple and simple :D

Photo by John Barkiple on Unsplash

First of all you need to setup and run Selenoid on your environment. It can be easily done follow official documentation.

We going fast way, so let’s use Configuration Manager for it.

./cm selenoid start

After some time as result we have Selenoid stated and it’s ready to run your tests against and tests endpoint is — http://localhost:4444/wd/hub

Now Selenide’s turn. As I said before we going to look on two integration options. First — single line configuration.

Let’s create a test project and integrate, integrate, integrate… I will use Gradle as a build tool and JUnit5 as a testing framework.

Add JUni5 — testImplementation("org.junit.jupiter:junit-jupiter:5.4.2")

Add Selenide — testImplementation("com.codeborne:selenide:5.2.3")

In very simple case we just need to tell Selenide run tests against remote web driver by adding single line:

Configuration.remote = "http://localhost:4444/wd/hub";

Also don’t forget to disable WebDriverManager:

Configuration.driverManagerEnabled = false;

And put it to test setup block:

@BeforeEach
void setUp() {
Configuration.driverManagerEnabled = false;
Configuration.remote = "http://localhost:4444/wd/hub";
}

Create simple test and execute it:

@Test                           
void ableToRunDefaultDriverOnSelenoid() {
open("https://www.google.com");
assertEquals(title(), "Google");
}

As result in logs we can see that session was created inside Selenoid container as RemoteWebDriver:

INFO: BrowserName=chrome Version=74.0.3729.157 Platform=LINUX
INFO: Create webdriver in current thread 1: RemoteWebDriver -> RemoteWebDriver: chrome on LINUX (23b5bb5746fdc8cc16b7f850e9080092)

Perfect!

But what if we need to create a custom WebDriver? And Selenide has such ability. It’s described in Selenide Wiki on GitHub. In my case I just want to execute tests on Firefox and accept insecure certificates:

public static class CustomProvider implements WebDriverProvider {
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setAcceptInsecureCerts(true);
firefoxOptions.merge(capabilities);
try {
return new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), firefoxOptions);
} catch (final MalformedURLException e) {
throw new RuntimeException("Unable to create driver", e);
}
}
}

Also don’t forget to disable WebDriverManager and set custom driver as browser to Selenide:

@BeforeEach
void setUp() {
Configuration.driverManagerEnabled = false;
Configuration.browser = CustomProvider.class.getName();
}

Easy as pie — save, run, relax:

INFO: BrowserName=firefox Version=67.0 Platform=LINUX
INFO: Create webdriver in current thread 1: RemoteWebDriver -> RemoteWebDriver: firefox on LINUX (e5397009-df23–4327–8d69-b031fc10fc3b)

Happy coding and testing! (◕‿◕)

--

--