In just about any JVM-based project I'm asked to work on, people are using the tool WebDriverManager:
A good example of how I use that in non-Serenity projects is here:
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.