Skip to content

Commit

Permalink
use DesiredCapabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jun 27, 2024
1 parent a9dce3f commit 017a2f3
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions src/test/java/org/openqa/selenium/htmlunit/WebDriverTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.GeckoDriverService;
import org.openqa.selenium.remote.Browser;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.htmlunit.options.HtmlUnitDriverOptions;
import org.openqa.selenium.remote.UnreachableBrowserException;

/**
Expand Down Expand Up @@ -542,24 +541,20 @@ protected WebDriver buildWebDriver() throws IOException {
throw new RuntimeException("Unexpected BrowserVersion: " + getBrowserVersion());
}
if (webDriver_ == null) {
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(Browser.HTMLUNIT.browserName());
capabilities.setVersion(getBrowserName(getBrowserVersion()));
webDriver_ = new HtmlUnitDriver(capabilities) {
@Override
protected WebClient newWebClient(final BrowserVersion version) {
final WebClient webClient = super.newWebClient(version);
if (isWebClientCached()) {
webClient.getOptions().setHistorySizeLimit(0);
}
final WebClientOptions options = new WebClientOptions();
if (isWebClientCached()) {
options.setHistorySizeLimit(0);
}

final Integer timeout = getWebClientTimeout();
if (timeout != null) {
webClient.getOptions().setTimeout(timeout.intValue());
}
return webClient;
}
};
final Integer timeout = getWebClientTimeout();
if (timeout != null) {
options.setTimeout(timeout.intValue());
}

final HtmlUnitDriverOptions driverOptions = new HtmlUnitDriverOptions(getBrowserVersion());
driverOptions.importOptions(options);

webDriver_ = new HtmlUnitDriver(driverOptions);
webDriver_.setExecutor(EXECUTOR_POOL);
}
return webDriver_;
Expand All @@ -581,16 +576,6 @@ private static FirefoxDriver createFirefoxDriver(final String geckodriverBinary,
return new FirefoxDriver(service, options);
}

private static String getBrowserName(final BrowserVersion browserVersion) {
if (browserVersion == BrowserVersion.FIREFOX) {
return browserVersion.getNickname() + '-' + browserVersion.getBrowserVersionNumeric();
}
if (browserVersion == BrowserVersion.FIREFOX_ESR) {
return browserVersion.getNickname() + '-' + browserVersion.getBrowserVersionNumeric();
}
return browserVersion.getNickname();
}

/**
* Starts the web server delivering response from the provided connection.
* @param mockConnection the sources for responses
Expand Down

0 comments on commit 017a2f3

Please sign in to comment.