use of org.openqa.selenium.remote.RemoteWebDriver in project hippo by NHS-digital-website.
the class WebDriverProvider method initialise.
/**
* Initialises the WebDriver (client).
*
* This method should be called once before each test to ensure that the session state doesn't bleed from one test
* to another (such as user being logged in).
*/
public void initialise() {
final ChromeOptions chromeOptions = new ChromeOptions();
final Map<String, Object> chromePrefs = new HashMap<>();
log.info("Setting WebDriver download directory to '{}'.", downloadDirectory);
chromePrefs.put("download.default_directory", downloadDirectory.toAbsolutePath().toString());
chromeOptions.setExperimentalOption("prefs", chromePrefs);
chromeOptions.addArguments("window-size=1920,1080");
log.info("Configuring WebDriver to run in {} mode.", isHeadlessMode ? "headless" : "full, graphical");
if (isHeadlessMode) {
chromeOptions.addArguments("--headless");
}
chromeOptions.addArguments("--host-resolver-rules=MAP consent.cookiebot.com 127.0.0.1");
webDriver = new RemoteWebDriver(webDriverServiceProvider.getUrl(), chromeOptions);
}
use of org.openqa.selenium.remote.RemoteWebDriver in project elastest-instrumentation-manager by elastest.
the class EimBaseTest method setupTestBrowser.
public void setupTestBrowser(TestInfo testInfo, BrowserType browser, String browserVersion, WebDriver driver) throws MalformedURLException {
String testName = testInfo.getTestMethod().get().getName();
log.info("EUS hub URL: {}", eusURL);
if (eusURL != null) {
DesiredCapabilities caps = new DesiredCapabilities();
if (browser.equals(BrowserType.CHROME)) {
DesiredCapabilities.chrome();
caps.setBrowserName("chrome");
} else {
DesiredCapabilities.firefox();
caps.setBrowserName("firefox");
}
caps.setCapability("testName", testName);
if (!browserVersion.equals(BROWSER_VERSION_LATEST)) {
log.info("Use this browser version: {}", browserVersion);
caps.setVersion(browserVersion);
}
this.driver = new RemoteWebDriver(new URL(eusURL), caps);
driver = this.driver;
} else {
this.driver = driver;
}
}
use of org.openqa.selenium.remote.RemoteWebDriver in project flow by vaadin.
the class ChromeDeviceTest method setup.
@Before
@Override
public void setup() throws Exception {
ChromeOptions chromeOptions = customizeChromeOptions(new ChromeOptions());
WebDriver driver;
if (Browser.CHROME == getRunLocallyBrowser()) {
driver = new ChromeDriver(chromeOptions);
} else {
URL remoteURL = new URL(getHubURL());
driver = new RemoteWebDriver(remoteURL, chromeOptions);
setDevToolsRuntimeCapabilities((RemoteWebDriver) driver, remoteURL);
}
devTools = new DevToolsWrapper(driver);
setDriver(TestBench.createDriver(driver));
}
use of org.openqa.selenium.remote.RemoteWebDriver in project flow by vaadin.
the class RedeployLeakIT method deployUseUndeployCheck.
@Test
public void deployUseUndeployCheck() throws Exception {
// DO NOT RUN FROM ECLIPSE
// The test uses files from the target folder
setup(7778);
RemoteWebDriver driver = new RemoteWebDriver(Browser.CHROME.getDesiredCapabilities());
try {
driver.get("http://" + getCurrentHostAddress() + ":7778/");
Assert.assertNotNull(driver.findElement(By.id("hello")));
} finally {
driver.close();
driver.quit();
}
shutdownAndVerify();
}
use of org.openqa.selenium.remote.RemoteWebDriver in project acceptance-test-harness by jenkinsci.
the class FallbackConfig method createContainerWebDriver.
private WebDriver createContainerWebDriver(TestCleaner cleaner, String image, MutableCapabilities capabilities) throws IOException {
try {
final int controlPort = IOUtil.randomTcpPort();
final int vncPort = IOUtil.randomTcpPort(5900, 6000);
final int displayNumber = vncPort - 5900;
Path log = Files.createTempFile("ath-docker-browser", "log");
LOGGER.info("Starting selenium container. Logs in " + log);
Docker.cmd("pull", image).popen().verifyOrDieWith("Failed to pull image " + image);
// While this only needs to expose two ports (controlPort, vncPort), it needs to be able to talk to Jenkins running
// out of container so using host networking is the most straightforward way to go.
String[] args = { "run", "-d", "--shm-size=2g", "--network=host", "-e", "SE_OPTS=-port " + controlPort, "-e", "DISPLAY=:" + displayNumber, image };
ProcessInputStream popen = Docker.cmd(args).popen();
popen.waitFor();
String cid = popen.verifyOrDieWith("Failed to run selenium container").trim();
new ProcessBuilder(Docker.cmd("logs", "-f", cid).toCommandArray()).redirectErrorStream(true).redirectOutput(log.toFile()).start();
Closeable cleanContainer = new Closeable() {
@Override
public void close() {
try {
Docker.cmd("kill", cid).popen().verifyOrDieWith("Failed to kill " + cid);
Docker.cmd("rm", cid).popen().verifyOrDieWith("Failed to rm " + cid);
} catch (IOException | InterruptedException e) {
throw new Error("Failed removing container", e);
}
}
@Override
public String toString() {
return "Kill and remove selenium container";
}
};
// Give the container and selenium some time to spawn
Thread.sleep(3000);
try {
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL("http://127.0.0.1:" + controlPort + "/wd/hub"), capabilities);
cleaner.addTask(cleanContainer);
return remoteWebDriver;
} catch (RuntimeException e) {
cleanContainer.close();
throw e;
} catch (Throwable e) {
cleanContainer.close();
throw new Error(e);
}
} catch (InterruptedException e) {
throw new Error(e);
}
}
Aggregations