List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities)
From source file:org.kuali.rice.testtools.selenium.SauceLabsWebDriverHelper.java
License:Educational Community License
/** * <p>/* w ww. j a v a2 s . com*/ * Saucelabs setUp. * </p><p> * Creates a {@link org.openqa.selenium.remote.RemoteWebDriver} instance with the DesiredCapabilities as configured * using the JVM arguments described as SAUCE_ Constants in this class. After setUp the WebDriver can be accessed via * {@see #getDriver}. You'll also need {@see #getSessionId} for when you call {@see #tearDown} * </p> * * @param className class name of the test being setup as a String * @param testName test name of the test being setup as a String * @throws Exception */ public void setUp(String className, String testName) throws Exception { if (System.getProperty(REMOTE_DRIVER_SAUCELABS_PROPERTY) == null) { // dup guard so WebDriverUtils doesn't have to be used. return; } if (System.getProperty(SAUCE_USER_PROPERTY) == null || System.getProperty(SAUCE_KEY_PROPERTY) == null) { Assert.fail("-D" + SAUCE_USER_PROPERTY + " and -D" + SAUCE_KEY_PROPERTY + " must be set to saucelabs user and access key."); } DesiredCapabilities capabilities = null; if ("ff".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.firefox(); } else if ("ie".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, System.getProperty(SAUCE_IE_INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS_PROPERTY, "true")); } else if ("chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.chrome(); } else if ("opera".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.opera(); } else if ("android".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.android(); } else if ("safari".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.safari(); } else if ("ipad".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.ipad(); } else if ("iphone".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { capabilities = DesiredCapabilities.iphone(); } else { capabilities = DesiredCapabilities.firefox(); } String version = System.getProperty(SAUCE_VERSION_PROPERTY); if (version == null || "0".equals(version)) { // Blank or 0 leaves version blank for use with chrome if (!"chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) { throw new RuntimeException("Blank or 0 version for a browser not chrome " + System.getProperty(SAUCE_BROWSER_PROPERTY)); } capabilities.setCapability("version", ""); // saucelabs requires blank for chrome (latest version) } else { capabilities.setCapability("version", version); // saucelabs requires blank for chrome (latest version) } capabilities.setCapability("platform", System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()).replaceAll("_", " ")); capabilities.setCapability("idle-timeout", Integer.parseInt(System.getProperty(SAUCE_IDLE_TIMEOUT_SECONDS_PROPERTY, "180"))); capabilities.setCapability("max-duration", Integer.parseInt(System.getProperty(SAUCE_MAX_DURATION_SECONDS_PROPERTY, "600"))); capabilities.setCapability("name", className + "." + testName + "-" + AutomatedFunctionalTestUtils.DTS); capabilities.setCapability("disable-popup-handler", System.getProperty(SAUCE_POPUP_PROPERTY, "false")); capabilities.setCapability("public", System.getProperty(SAUCE_SHARE_PROPERTY, "public restricted")); System.out.println( "Requesting Saucelabs RemoteWebDriver with DesiredCapabilities of " + capabilities.toString()); this.driver = new RemoteWebDriver(new URL("http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"), capabilities); this.sessionId = ((RemoteWebDriver) driver).getSessionId().toString(); System.out.println("SauceLabs job can be viewed at https://saucelabs.com/jobs/" + this.sessionId); }
From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java
License:Educational Community License
/** * <p>// w ww . java 2 s . c o m * remote.public.driver set to chrome or firefox (null assumes firefox). * </p><p> * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid) * if proxy.host is set, the web driver is setup to use a proxy * </p> * * @return WebDriver or null if unable to create */ public static WebDriver getWebDriver() { String driverParam = System.getProperty(HUB_DRIVER_PROPERTY); String hubParam = System.getProperty(HUB_PROPERTY); String proxyParam = System.getProperty(PROXY_HOST_PROPERTY); // setup proxy if specified as VM Arg DesiredCapabilities capabilities = new DesiredCapabilities(); WebDriver webDriver = null; if (StringUtils.isNotEmpty(proxyParam)) { capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam)); } if (hubParam == null) { if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) { FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(false); capabilities.setCapability(FirefoxDriver.PROFILE, profile); return new FirefoxDriver(capabilities); } else if ("chrome".equalsIgnoreCase(driverParam)) { return new ChromeDriver(capabilities); } else if ("safari".equals(driverParam)) { System.out.println("SafariDriver probably won't work, if it does please contact Erik M."); return new SafariDriver(capabilities); } } else { try { if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) { return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.firefox()); } else if ("chrome".equalsIgnoreCase(driverParam)) { return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.chrome()); } } catch (MalformedURLException mue) { System.out.println(getHubUrlString() + " " + mue.getMessage()); mue.printStackTrace(); } } return null; }
From source file:org.kurento.test.browser.Browser.java
License:Apache License
public void createSaucelabsDriver(DesiredCapabilities capabilities) throws MalformedURLException { assertPublicIpNotNull();/*from w w w . ja v a 2s. co m*/ String sauceLabsUser = getProperty(SAUCELAB_USER_PROPERTY); String sauceLabsKey = getProperty(SAUCELAB_KEY_PROPERTY); if (sauceLabsUser == null || sauceLabsKey == null) { throw new RuntimeException("Invalid Saucelabs credentials: " + SAUCELAB_USER_PROPERTY + "=" + sauceLabsUser + " " + SAUCELAB_KEY_PROPERTY + "=" + sauceLabsKey); } capabilities.setCapability("version", browserVersion); capabilities.setCapability("platform", platform); String seleniumVersion = getProperty(SELENIUM_VERSION); if (seleniumVersion != null) { capabilities.setCapability("seleniumVersion", seleniumVersion); } if (parentTunnel != null) { capabilities.setCapability("parent-tunnel", parentTunnel); } if (avoidProxy) { capabilities.setCapability("avoid-proxy", avoidProxy); } int idleTimeout = getProperty(SAUCELAB_IDLE_TIMEOUT_PROPERTY, SAUCELAB_IDLE_TIMEOUT_DEFAULT); int commandTimeout = getProperty(SAUCELAB_COMMAND_TIMEOUT_PROPERTY, SAUCELAB_COMMAND_TIMEOUT_DEFAULT); int maxDuration = getProperty(SAUCELAB_MAX_DURATION_PROPERTY, SAUCELAB_MAX_DURATION_DEFAULT); capabilities.setCapability("idleTimeout", idleTimeout); capabilities.setCapability("commandTimeout", commandTimeout); capabilities.setCapability("maxDuration", maxDuration); if (name != null) { capabilities.setCapability("name", name); } driver = new RemoteWebDriver( new URL("http://" + sauceLabsUser + ":" + sauceLabsKey + "@ondemand.saucelabs.com:80/wd/hub"), capabilities); jobId = ((RemoteWebDriver) driver).getSessionId().toString(); log.debug("%%%%%%%%%%%%% Saucelabs URL job for {} ({} {} in {}) %%%%%%%%%%%%%", id, browserType, browserVersion, platform); log.debug("https://saucelabs.com/tests/{}", jobId); }
From source file:org.kurento.test.browser.Browser.java
License:Apache License
public void createRemoteDriver(final DesiredCapabilities capabilities) throws MalformedURLException { assertPublicIpNotNull();//from w w w .j ava2 s .c o m String remoteHubUrl = getProperty(SELENIUM_REMOTE_HUB_URL_PROPERTY); GridNode gridNode = null; if (remoteHubUrl == null) { log.debug("Creating remote webdriver for {}", id); if (!GridHandler.getInstance().containsSimilarBrowserKey(id)) { if (login != null) { System.setProperty(TEST_NODE_LOGIN_PROPERTY, login); } if (passwd != null) { System.setProperty(TEST_NODE_PASSWD_PROPERTY, passwd); } if (pem != null) { System.setProperty(TEST_NODE_PEM_PROPERTY, pem); } // Filtering valid nodes (just the first time will be effective) GridHandler.getInstance().filterValidNodes(); if (!node.equals(host) && login != null && !login.isEmpty() && (passwd != null && !passwd.isEmpty() || pem != null && !pem.isEmpty())) { gridNode = new GridNode(node, browserType, browserPerInstance, login, passwd, pem); GridHandler.getInstance().addNode(id, gridNode); } else { gridNode = GridHandler.getInstance().getRandomNodeFromList(id, browserType, browserPerInstance); } // Start Hub (just the first time will be effective) GridHandler.getInstance().startHub(); // Start node GridHandler.getInstance().startNode(gridNode); // Copy video (if necessary) if (video != null && browserType == BrowserType.CHROME) { GridHandler.getInstance().copyRemoteVideo(gridNode, video); } } else { // Wait for node boolean started = false; do { gridNode = GridHandler.getInstance().getNode(id); if (gridNode != null) { started = gridNode.isStarted(); } if (!started) { log.debug("Node {} is not started ... waiting 1 second", id); waitSeconds(1); } } while (!started); } // At this moment we are able to use the argument for remote video if (video != null && browserType == BrowserType.CHROME) { ChromeOptions options = (ChromeOptions) capabilities.getCapability(ChromeOptions.CAPABILITY); options.addArguments("--use-file-for-fake-video-capture=" + GridHandler.getInstance().getFirstNode(id).getRemoteVideo(video)); capabilities.setCapability(ChromeOptions.CAPABILITY, options); } final int hubPort = GridHandler.getInstance().getHubPort(); final String hubHost = GridHandler.getInstance().getHubHost(); log.debug("Creating remote webdriver of {} ({})", id, gridNode.getHost()); remoteHubUrl = "http://" + hubHost + ":" + hubPort + "/wd/hub"; } final String remoteHub = remoteHubUrl; Thread t = new Thread() { @Override public void run() { boolean exception = false; do { try { driver = new RemoteWebDriver(new URL(remoteHub), capabilities); exception = false; } catch (MalformedURLException | WebDriverException e) { log.error("Exception {} creating RemoteWebDriver ... retrying in 1 second", e.getClass()); waitSeconds(1); exception = true; } } while (exception); } }; t.start(); int timeout = getProperty(SELENIUM_REMOTEWEBDRIVER_TIME_PROPERTY, SELENIUM_REMOTEWEBDRIVER_TIME_DEFAULT); String nodeMsg = gridNode != null ? " (" + gridNode.getHost() + ")" : ""; for (int i = 0; i < timeout; i++) { if (t.isAlive()) { log.debug("Waiting for RemoteWebDriver {}{}", id, nodeMsg); } else { log.debug("Remote webdriver of {}{} created", id, nodeMsg); return; } waitSeconds(1); } String exceptionMessage = "Remote webdriver of " + id + nodeMsg + " not created in " + timeout + "seconds"; log.error(">>>>>>>>>> " + exceptionMessage); throw new RuntimeException(exceptionMessage); }
From source file:org.kurento.test.client.BrowserClient.java
License:Open Source License
public void createSaucelabsDriver(DesiredCapabilities capabilities) throws MalformedURLException { assertPublicIpNotNull();//from ww w . j a va 2 s . c o m String sauceLabsUser = getProperty(SAUCELAB_USER_PROPERTY); String sauceLabsKey = getProperty(SAUCELAB_KEY_PROPERTY); int idleTimeout = getProperty(SAUCELAB_IDLE_TIMEOUT_PROPERTY, SAUCELAB_IDLE_TIMEOUT_DEFAULT); int commandTimeout = getProperty(SAUCELAB_COMMAND_TIMEOUT_PROPERTY, SAUCELAB_COMMAND_TIMEOUT_DEFAULT); if (sauceLabsUser == null || sauceLabsKey == null) { throw new RuntimeException("Invalid Saucelabs credentials: " + SAUCELAB_USER_PROPERTY + "=" + sauceLabsUser + " " + SAUCELAB_KEY_PROPERTY + "=" + sauceLabsKey); } capabilities.setCapability("version", browserVersion); capabilities.setCapability("platform", platform); if (parentTunnel != null) { capabilities.setCapability("parent-tunnel", parentTunnel); } if (avoidProxy) { capabilities.setCapability("avoid-proxy", avoidProxy); } capabilities.setCapability("idleTimeout", idleTimeout); capabilities.setCapability("commandTimeout", commandTimeout); if (name != null) { capabilities.setCapability("name", name); } driver = new RemoteWebDriver( new URL("http://" + sauceLabsUser + ":" + sauceLabsKey + "@ondemand.saucelabs.com:80/wd/hub"), capabilities); jobId = ((RemoteWebDriver) driver).getSessionId().toString(); log.info("%%%%%%%%%%%%% Saucelabs URL job ({} {} in {}) %%%%%%%%%%%%%", browserType, browserVersion, platform); log.info("https://saucelabs.com/tests/{}", jobId); }
From source file:org.kurento.test.client.BrowserClient.java
License:Open Source License
public void createRemoteDriver(DesiredCapabilities capabilities) throws MalformedURLException { assertPublicIpNotNull();//w w w. j a v a 2 s.c o m if (!GridHandler.getInstance().containsSimilarBrowserKey(id)) { GridNode gridNode = null; if (login != null) { System.setProperty(TEST_NODE_LOGIN_PROPERTY, login); } if (passwd != null) { System.setProperty(TEST_NODE_PASSWD_PROPERTY, passwd); } if (pem != null) { System.setProperty(TEST_NODE_PEM_PROPERTY, pem); } if (!node.equals(host) && login != null && !login.isEmpty() && (passwd != null && !passwd.isEmpty() || pem != null && !pem.isEmpty())) { gridNode = new GridNode(node, browserType, browserPerInstance, login, passwd, pem); GridHandler.getInstance().addNode(id, gridNode); } else { gridNode = GridHandler.getInstance().getRandomNodeFromList(id, browserType, browserPerInstance); } // Start Hub (just the first time will be effective) GridHandler.getInstance().startHub(); // Start node GridHandler.getInstance().startNode(gridNode); // Copy video (if necessary) if (video != null && browserType == BrowserType.CHROME) { GridHandler.getInstance().copyRemoteVideo(gridNode, video); } } // At this moment we are able to use the argument for remote video if (video != null && browserType == BrowserType.CHROME) { ChromeOptions options = (ChromeOptions) capabilities.getCapability(ChromeOptions.CAPABILITY); options.addArguments("--use-file-for-fake-video-capture=" + GridHandler.getInstance().getFirstNode(id).getRemoteVideo(video)); capabilities.setCapability(ChromeOptions.CAPABILITY, options); } int hubPort = GridHandler.getInstance().getHubPort(); String hubHost = GridHandler.getInstance().getHubHost(); driver = new RemoteWebDriver(new URL("http://" + hubHost + ":" + hubPort + "/wd/hub"), capabilities); }
From source file:org.me.seleniumGridUI.SeleniumGridOperation.java
/** * * @param response/*ww w .j ava 2s .c om*/ * @return sessionId * @throws Throwable */ private String startBrowser(StartSeleniumResponse response) throws Throwable { final String hostname = response.getHostName(); final int port = response.getFreePort(); String remoteClientUrl = String.format(Constants.SELENIUM_REMOTE_WEBDRIVER_URL_FORMAT, hostname, port); WebDriver driver = new RemoteWebDriver(new URL(remoteClientUrl), CreateBrowserCapbility(response.getBrowser())); if (driver == null) { return "NO_WEB_DRIVER"; } return ((RemoteWebDriver) driver).getSessionId().toString(); }
From source file:org.me.seleniumGridUI.SeleniumStatus.java
public String getEnvironment() throws Throwable { if (IsThisDeviceTesting()) { return StringUtils.EMPTY; }/*from www.ja va2s . c o m*/ Map<String, String> myMap = new HashMap<String, String>(); SeleniumGridOperation seleniumOperation = SeleniumGridOperation.getInstance(); WebDriver driver = new RemoteWebDriver(new URL(hubUrl), seleniumOperation.CreateBrowserCapbility("phantomjs")); driver.get("http://www.autoscout24.de/build.txt"); String siteContent = driver.findElement(By.tagName("pre")).getText(); if (driver != null) { driver.quit(); } String[] elements = siteContent.split("\\n"); for (String s1 : elements) { s1 = s1.replaceAll("\\s", ""); String[] keyValue = s1.split(":"); myMap.put(keyValue[0], keyValue[1]); } return myMap.get("Environment"); }
From source file:org.mousephenotype.cda.selenium.ChartsPageTest.java
License:Apache License
@Before public void setUp() throws Exception { driver = new RemoteWebDriver(new URL(seleniumUrl), desiredCapabilities); if (commonUtils.tryParseInt(System.getProperty("TIMEOUT_IN_SECONDS")) != null) timeoutInSeconds = commonUtils.tryParseInt(System.getProperty("TIMEOUT_IN_SECONDS")); if (commonUtils.tryParseInt(System.getProperty("THREAD_WAIT_IN_MILLISECONDS")) != null) threadWaitInMilliseconds = commonUtils.tryParseInt(System.getProperty("THREAD_WAIT_IN_MILLISECONDS")); wait = new WebDriverWait(driver, timeoutInSeconds); }
From source file:org.mousephenotype.cda.selenium.GenePageTest.java
License:Apache License
@Before public void setup() throws MalformedURLException { driver = new RemoteWebDriver(new URL(seleniumUrl), desiredCapabilities); if (commonUtils.tryParseInt(System.getProperty("TIMEOUT_IN_SECONDS")) != null) timeoutInSeconds = commonUtils.tryParseInt(System.getProperty("TIMEOUT_IN_SECONDS")); if (commonUtils.tryParseInt(System.getProperty("THREAD_WAIT_IN_MILLISECONDS")) != null) threadWaitInMilliseconds = commonUtils.tryParseInt(System.getProperty("THREAD_WAIT_IN_MILLISECONDS")); wait = new WebDriverWait(driver, timeoutInSeconds); }