BrowserCapabilitiesRegistry registry = registryInstance.get();
// first, try to create a BrowserCapabilities object based on Field/Parameter type of @Drone annotated field
BrowserCapabilities browser = registry.getEntryFor(getDriverReadableName());
WebDriverConfiguration configuration = new WebDriverConfiguration(browser).configure(descriptor, qualifier);
// then, check if legacy implementationClass was set in the configuration and try to update accordingly
if (browser == null && Validate.nonEmpty(configuration.getImplementationClass())) {
browser = registry.getEntryByImplementationClassName(configuration.getImplementationClass());
if (browser == null) {
log.log(Level.FINE, "Available implementationClasses are {}", getAvailableImplementationClasses());
throw new IllegalStateException(
MessageFormat
.format("Unable to initialize WebDriver instance. Please specify a browserCapabilities property instead of implementationClass {1}. Available options are: {0}",
getAvailableBrowserCapabilities(), configuration.getImplementationClass()));
}
configuration.setBrowserCapabilitiesInternal(browser);
log.log(Level.WARNING,
"Please use browserCapability to specify browser type instead of implementationClass. Available options are: {0}",
getAvailableBrowserCapabilities());
}
// otherwise, we hit a webdriver configuration and we want to use browserCapabilities
if (browser == null && Validate.nonEmpty(configuration.getBrowserCapabilities())) {
browser = registry.getEntryFor(configuration.getBrowserCapabilities());
if (browser == null) {
throw new IllegalStateException(
MessageFormat
.format("Unable to initialize WebDriver instance. Please specify a valid browserCapabilities instead of {1}. Available options are: {0}",
getAvailableBrowserCapabilities(), configuration.getBrowserCapabilities()));
}
configuration.setBrowserCapabilitiesInternal(browser);
}
// if it is still null, go with defaults
if (browser == null) {
browser = registry.getEntryFor(WebDriverConfiguration.DEFAULT_BROWSER_CAPABILITIES);
log.log(Level.INFO, "Property \"browserCapabilities\" was not specified, using default value of {0}",
WebDriverConfiguration.DEFAULT_BROWSER_CAPABILITIES);
configuration.setBrowserCapabilitiesInternal(browser);
}
return configuration;
}