use of org.openqa.selenium.support.events.EventFiringWebDriver in project acceptance-test-harness by jenkinsci.
the class FallbackConfig method createWebDriver.
/**
* Creates a {@link WebDriver} for each test, then make sure to clean it up at the end.
*/
@Provides
@TestScope
public WebDriver createWebDriver(TestCleaner cleaner, TestName testName, ElasticTime time) throws IOException {
WebDriver base = createWebDriver(cleaner, testName);
// Make sure the window has minimal resolution set, even when out of the visible screen.
// Note - not maximizing here any more because that doesn't do anything.
Dimension oldSize = base.manage().window().getSize();
if (oldSize.height < 1050 || oldSize.width < 1680) {
base.manage().window().setSize(new Dimension(1680, 1050));
}
final EventFiringWebDriver d = new EventFiringWebDriver(base);
d.register(new Scroller());
try {
d.manage().timeouts().pageLoadTimeout(time.seconds(PAGE_LOAD_TIMEOUT), TimeUnit.MILLISECONDS);
d.manage().timeouts().implicitlyWait(time.seconds(IMPLICIT_WAIT_TIMEOUT), TimeUnit.MILLISECONDS);
} catch (UnsupportedCommandException e) {
// sauce labs RemoteWebDriver doesn't support this
LOGGER.info(base + " doesn't support page load timeout");
}
cleaner.addTask(new Statement() {
@Override
public void evaluate() {
switch(getBrowser()) {
case "firefox":
case "saucelabs-firefox":
case "remote-webdriver-firefox":
// https://github.com/mozilla/geckodriver/issues/1151
// https://bugzilla.mozilla.org/show_bug.cgi?id=1264259
// https://bugzilla.mozilla.org/show_bug.cgi?id=1434872
d.navigate().to("about:mozilla");
Alert alert = ExpectedConditions.alertIsPresent().apply(d);
if (alert != null) {
alert.accept();
d.navigate().refresh();
}
}
d.quit();
}
@Override
public String toString() {
return "Close WebDriver after test";
}
});
return d;
}
Aggregations