Search in sources :

Example 71 with RemoteWebDriver

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);
}
Also used : HashMap(java.util.HashMap) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions)

Example 72 with RemoteWebDriver

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;
    }
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL)

Example 73 with RemoteWebDriver

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));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) URL(java.net.URL) Before(org.junit.Before)

Example 74 with RemoteWebDriver

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();
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Test(org.junit.Test) AbstractTestBenchTest(com.vaadin.flow.testutil.AbstractTestBenchTest)

Example 75 with RemoteWebDriver

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);
    }
}
Also used : Path(java.nio.file.Path) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Closeable(java.io.Closeable) IOException(java.io.IOException) URL(java.net.URL) ProcessInputStream(org.jenkinsci.utils.process.ProcessInputStream)

Aggregations

RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)101 URL (java.net.URL)39 Test (org.junit.Test)36 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)29 File (java.io.File)16 WebDriver (org.openqa.selenium.WebDriver)14 MalformedURLException (java.net.MalformedURLException)13 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)13 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)12 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)12 IOException (java.io.IOException)11 Dimension (org.openqa.selenium.Dimension)9 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)7 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)6 EventFiringWebDriver (org.openqa.selenium.support.events.EventFiringWebDriver)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5