Search in sources :

Example 66 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project testcontainers-java by testcontainers.

the class BaseWebDriverContainerTest method doSimpleExplore.

protected static void doSimpleExplore(BrowserWebDriverContainer rule) {
    RemoteWebDriver driver = setupDriverFromRule(rule);
    driver.get("http://en.wikipedia.org/wiki/Randomness");
    // Oh! The irony!
    assertTrue("Randomness' description has the word 'pattern'", driver.findElementByPartialLinkText("pattern").isDisplayed());
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver)

Example 67 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project testcontainers-java by testcontainers.

the class BaseWebDriverContainerTest method doSimpleWebdriverTest.

protected void doSimpleWebdriverTest(BrowserWebDriverContainer rule) {
    RemoteWebDriver driver = setupDriverFromRule(rule);
    System.out.println("Selenium remote URL is: " + rule.getSeleniumAddress());
    System.out.println("VNC URL is: " + rule.getVncAddress());
    // Runtime.getRuntime().exec("open " + rule.getVncUrl(driver)); // For debugging, on a Mac
    driver.get("http://www.google.com");
    driver.findElement(By.name("q")).sendKeys("testcontainers");
    driver.findElement(By.name("q")).submit();
    assertEquals("the word 'testcontainers' appears in the search box", "testcontainers", driver.findElement(By.name("q")).getAttribute("value"));
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver)

Example 68 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project cerberus-source by cerberustesting.

the class SeleniumServerService method getIPOfNode.

private static void getIPOfNode(TestCaseExecution tCExecution) {
    try {
        Session session = tCExecution.getSession();
        HttpCommandExecutor ce = (HttpCommandExecutor) ((RemoteWebDriver) session.getDriver()).getCommandExecutor();
        SessionId sessionId = ((RemoteWebDriver) session.getDriver()).getSessionId();
        String hostName = ce.getAddressOfRemoteServer().getHost();
        int port = ce.getAddressOfRemoteServer().getPort();
        HttpHost host = new HttpHost(hostName, port);
        HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
        URL sessionURL = new URL(SeleniumServerService.getBaseUrl(session.getHost(), session.getPort()) + "/grid/api/testsession?session=" + sessionId);
        BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", sessionURL.toExternalForm());
        HttpResponse response = client.execute(host, r);
        if (!response.getStatusLine().toString().contains("403") && !response.getEntity().getContentType().getValue().contains("text/html")) {
            InputStream contents = response.getEntity().getContent();
            StringWriter writer = new StringWriter();
            IOUtils.copy(contents, writer, "UTF8");
            JSONObject object = new JSONObject(writer.toString());
            URL myURL = new URL(object.getString("proxyId"));
            if ((myURL.getHost() != null) && (myURL.getPort() != -1)) {
                tCExecution.setIp(myURL.getHost());
                tCExecution.setPort(String.valueOf(myURL.getPort()));
            }
        }
    } catch (IOException ex) {
        LOG.error(ex.toString());
    } catch (JSONException ex) {
        LOG.error(ex.toString());
    }
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) InputStream(java.io.InputStream) HttpResponse(org.apache.http.HttpResponse) JSONException(org.json.JSONException) IOException(java.io.IOException) Point(org.openqa.selenium.Point) URL(java.net.URL) HttpCommandExecutor(org.openqa.selenium.remote.HttpCommandExecutor) StringWriter(java.io.StringWriter) JSONObject(org.json.JSONObject) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) SessionId(org.openqa.selenium.remote.SessionId) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy) Session(org.cerberus.engine.entity.Session) BasicHttpEntityEnclosingRequest(org.apache.http.message.BasicHttpEntityEnclosingRequest)

Example 69 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project opentest by mcdcorp.

the class SeleniumHelper method createDriver.

private static WebDriver createDriver() {
    WebDriver webDriver = null;
    DesiredCapabilities caps;
    setSystemProperties();
    if (config.hasProperty("selenium.seleniumServerUrl")) {
        String seleniumServerUrl = config.getString("selenium.seleniumServerUrl");
        Logger.info(String.format("Using remote Selenium server %s", seleniumServerUrl));
        try {
            caps = new DesiredCapabilities();
            injectCapsFromConfig(caps);
            webDriver = new RemoteWebDriver(new URL(seleniumServerUrl), caps);
        } catch (Exception ex) {
            throw new RuntimeException(String.format("Falied to connect to Selenium server %s", seleniumServerUrl), ex);
        }
    } else {
        Logger.info("Using local Selenium server");
        String browserName = config.getString("selenium.desiredCapabilities.browserName").toLowerCase();
        switch(browserName) {
            case "chrome":
                setDriverExecutable(config.getString("selenium.chromeDriverExePath", null), "chrome");
                caps = getCapsForBrowser("chrome");
                injectCapsFromConfig(caps);
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.merge(caps);
                webDriver = new ChromeDriver(chromeOptions);
                break;
            case "edge":
                setDriverExecutable(config.getString("selenium.edgeDriverExePath", null), "edge");
                caps = getCapsForBrowser("edge");
                injectCapsFromConfig(caps);
                webDriver = new EdgeDriver(caps);
                break;
            case "firefox":
                setDriverExecutable(config.getString("selenium.firefoxDriverExePath", null), "firefox");
                caps = getCapsForBrowser("firefox");
                injectCapsFromConfig(caps);
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.merge(caps);
                webDriver = new FirefoxDriver(firefoxOptions);
                break;
            case "internet explorer":
                setDriverExecutable(config.getString("selenium.ieDriverExePath", null), "internet explorer");
                caps = getCapsForBrowser("internet explorer");
                // Avoid the browser zoom level error
                caps.setCapability("ignoreZoomSetting", true);
                injectCapsFromConfig(caps);
                InternetExplorerOptions ieOptions = new InternetExplorerOptions();
                ieOptions.merge(caps);
                webDriver = new InternetExplorerDriver(ieOptions);
                break;
            case "opera":
                setDriverExecutable(config.getString("selenium.operaDriverExePath", null), "opera");
                caps = getCapsForBrowser("opera");
                injectCapsFromConfig(caps);
                webDriver = new OperaDriver(caps);
                break;
            case "safari":
                setDriverExecutable(config.getString("selenium.safariDriverExePath", null), "safari");
                caps = getCapsForBrowser("safari");
                injectCapsFromConfig(caps);
                webDriver = new SafariDriver();
                break;
            default:
                throw new RuntimeException(String.format("The \"selenium.browserName\" config property specifies a browser " + "that is invalid or not supported. The property value was \"%s\". " + "The valid values are: \"chrome\", \"edge\", \"firefox\", \"internet " + "explorer\" and \"safari\".", browserName));
        }
    }
    webDriver.manage().timeouts().setScriptTimeout(config.getInteger("selenium.scriptTimeout", 20), TimeUnit.SECONDS);
    webDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    Boolean maximizeWindow = config.getBoolean("selenium.maximizeWindow", true);
    if (maximizeWindow) {
        try {
            webDriver.manage().window().maximize();
        } catch (Exception ex) {
            Logger.warning(String.format("Failed to maximize browser window"), ex);
        }
    }
    return webDriver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) OperaDriver(org.openqa.selenium.opera.OperaDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 70 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project nutch by apache.

the class HttpWebClient method createFirefoxRemoteWebDriver.

public static RemoteWebDriver createFirefoxRemoteWebDriver(URL seleniumHubUrl, boolean enableHeadlessMode) {
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    if (enableHeadlessMode) {
        firefoxOptions.setHeadless(true);
    }
    RemoteWebDriver driver = new RemoteWebDriver(seleniumHubUrl, firefoxOptions);
    return driver;
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver)

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