Using WebDriverManager with Serenity

1,820 views
Skip to first unread message

Jeff Nyman

unread,
Oct 10, 2016, 10:51:00 AM10/10/16
to Serenity BDD Users Group
In just about any JVM-based project I'm asked to work on, people are using the tool WebDriverManager:



The main thing to note there are the lines that show ChromeDriverManager, MarionetteDriverManager, and so on. Those are providing a means to download the binaries for the drivers if they are not present on the system.

So I want to try to do the same thing in Serenity. What I ended up doing was creating a CustomChromeDriver like this:


public class CustomChromeDriver implements DriverSource {
@Override
public WebDriver newDriver() {
try {
ChromeDriverManager.getInstance().setup();

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--no-default-browser-check", "--start-maximized"));
HashMap<String, String> chromePreferences = new HashMap<String, String>();
chromePreferences.put("profile.password_manager_enabled", "false");
capabilities.setCapability("chrome.prefs", chromePreferences);

return new ChromeDriver(capabilities);
} catch(Exception e) {
throw new Error(e);
}
}

@Override
public boolean takesScreenshots() {
return false;
}
}


I put the appropriate configuration in my serenity.properties file and everything works in that my CustomChromeDriver is being used. However, notice the first statement under the try block.

  ChromeDriverManager.getInstance().setup();

For some reason, that does not execute at all. What it should do is download a ChromeDriver if it is not available. This does happen in my own project, but not in the Serenity one.

In the context of a Serenity project, I have no idea where to put this line such that it will actually work. I was looking at the following in the Serenity documentation:


That's where I was figuring out how to do the custom driver. That documentation shows this line:

    return new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), capabilities);

I have no idea where "ResolvingPhantomJSDriverService" is even coming from so perhaps I'm not setting up my custom driver correctly. (Although it seems to work.) But that still wouldn't explain why the line in the try() block appears not to be executing.

Has anyone used WebDriverManager with Serenity? If so, I'd definitely be curious to hear some experience reports.

Jeff Nyman

unread,
Oct 10, 2016, 11:14:08 AM10/10/16
to Serenity BDD Users Group
So one thing I found is that perhaps the hooks (like `@Before`) are absolutely necessary to run this.

Currently I'm using Serenity with Cucumber so I found I could this:

import cucumber.api.java.Before;
import io.github.bonigarcia.wdm.ChromeDriverManager;

public class Hooks {
@Before
public void setupDriver() {
ChromeDriverManager.getInstance().setup();
}

}

That's perfectly fine and seems to work but, of course, as with the example, I showed from my other repository, there are a slew of drivers that someone may be using. So I would have to somehow make sure that the `@Before` hook is executed such that it is aware of what browser has been specified for a given test run and then it only executes the "manager" for that browser.
Reply all
Reply to author
Forward
0 new messages