List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities)
From source file:com.htm.SystemUnderTest.java
License:Open Source License
public static void load(String url, String os, String browser, String saucename, String saucekey) throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platform", os); capabilities.setBrowserName(browser); capabilities.setCapability("name", "HTM-IT Sauce Testing"); System.out.println(saucekey); System.out.println(saucename); driver = new RemoteWebDriver(new URL("http://" + saucename + ":" + saucekey + SAUCEURL), capabilities); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(40000, TimeUnit.SECONDS); driver.get(url);/* www.j ava2s .c o m*/ }
From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java
License:Open Source License
/** * Return the WebDriver/* w w w. j a v a 2 s . c om*/ * * @return {WebDriver} */ public WebDriver getWebDriver() { // browser to test with assertTrue("Requesting webdriver while using the mock transport: " + System.getProperty("testMode"), System.getProperty("testMode") == null); String browserName = System.getProperty(PROP_BROWSER); if (webDriver == null) { logger.info("Creating WebDriver instance"); if (StringUtil.isEmpty(System.getProperty(SELENIUM_HUB))) { if ("ie".equals(browserName)) { initInternetExplorerDriver(); } else if ("chrome".equals(browserName)) { initChromeDriver(); } else if ("safari".equals(browserName)) { webDriver = new SafariDriver(); } else if ("headless".equals(browserName)) { HtmlUnitDriver driver = new HtmlUnitDriver(true); webDriver = driver; } else { webDriver = new FirefoxDriver(); } } else { DesiredCapabilities cap = null; if ("ie".equals(browserName)) { cap = DesiredCapabilities.internetExplorer(); } else if ("chrome".equals(browserName)) { cap = DesiredCapabilities.chrome(); } else if ("safari".equals(browserName)) { cap = DesiredCapabilities.safari(); } else if ("headless".equals(browserName)) { cap = DesiredCapabilities.htmlUnit(); } else { cap = DesiredCapabilities.firefox(); } cap.setCapability(CapabilityType.TAKES_SCREENSHOT, true); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); try { webDriver = new RemoteWebDriver(new URL(System.getProperty(SELENIUM_HUB)), cap); webDriver = new Augmenter().augment(webDriver); } catch (MalformedURLException e) { throw new RuntimeException(e); } } } return webDriver; }
From source file:com.ibm.watson.app.qaclassifier.selenium.drivers.Browser.java
License:Open Source License
private RemoteWebDriver getRemoteDriverWithRetries(URL url) { WebDriverException exception = null; for (int i = 0; i < 5; i++) { try {/*ww w .j a va 2 s. c om*/ return new RemoteWebDriver(url, capabilities); } catch (WebDriverException e) { // Retry in case of a flaky grid node e.printStackTrace(); exception = e; } } throw exception; }
From source file:com.ibm.watson.movieapp.dialog.fvt.config.Driver.java
License:Open Source License
/** * getInstance() // ww w. ja va 2 s .co m * @return RemoteWebDriver */ public WebDriver getInstance() { WebDriver driver = null; String browser = Utils.readConfigProperty("browser"); if (seleniumGridServer.isEmpty()) { logger.info("INFO: Using local client for GUI Automation"); driver = new FirefoxDriver(); } else { try { logger.info("INFO: Using selenium grid for GUI Automation"); DesiredCapabilities capability; if (browser.contains("firefox")) { capability = DesiredCapabilities.firefox(); } else if (browser.contains("chrome")) { capability = DesiredCapabilities.chrome(); } else { throw new RuntimeException( "WebDriver initialisation is not defined for this BrowserType: " + browser); } driver = new RemoteWebDriver(new URL(seleniumGridServer), capability); } catch (MalformedURLException e) { e.printStackTrace(); } } driver.manage().window().maximize(); return driver; }
From source file:com.kurento.kmf.test.client.BrowserClient.java
License:Open Source License
private void initDriver(String hostAddress) { Class<? extends WebDriver> driverClass = browser.getDriverClass(); int hubPort = getProperty("test.hub.port", GridBrowserMediaApiTest.DEFAULT_HUB_PORT); try {/*w w w . java 2 s .c om*/ if (driverClass.equals(FirefoxDriver.class)) { FirefoxProfile profile = new FirefoxProfile(); // This flag avoids granting the access to the camera profile.setPreference("media.navigator.permission.disabled", true); if (remoteNode != null) { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(FirefoxDriver.PROFILE, profile); capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName()); driver = new RemoteWebDriver(new URL("http://" + hostAddress + ":" + hubPort + "/wd/hub"), capabilities); } else { driver = new FirefoxDriver(profile); } if (!usePhysicalCam && video != null) { launchFakeCam(); } } else if (driverClass.equals(ChromeDriver.class)) { String chromedriver = null; if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_LINUX) { chromedriver = "chromedriver"; } else if (SystemUtils.IS_OS_WINDOWS) { chromedriver = "chromedriver.exe"; } System.setProperty("webdriver.chrome.driver", new File("target/webdriver/" + chromedriver).getAbsolutePath()); ChromeOptions options = new ChromeOptions(); // This flag avoids grant the camera options.addArguments("--use-fake-ui-for-media-stream"); // This flag avoids warning in chrome. See: // https://code.google.com/p/chromedriver/issues/detail?id=799 options.addArguments("--test-type"); if (!usePhysicalCam) { // This flag makes using a synthetic video (green with // spinner) in webrtc. Or it is needed to combine with // use-file-for-fake-video-capture to use a file faking the // cam options.addArguments("--use-fake-device-for-media-stream"); if (video != null) { options.addArguments("--use-file-for-fake-video-capture=" + video); // Alternative: lauch fake cam also in Chrome // launchFakeCam(); } } if (remoteNode != null) { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName()); driver = new RemoteWebDriver(new URL("http://" + hostAddress + ":" + hubPort + "/wd/hub"), capabilities); } else { driver = new ChromeDriver(options); } } driver.manage().timeouts().setScriptTimeout(timeout, TimeUnit.SECONDS); } catch (MalformedURLException e) { log.error("MalformedURLException in BrowserClient.initDriver", e); } }
From source file:com.linagora.obm.ui.ioc.Module.java
License:Open Source License
@Override protected void configure() { bind(URL.class).annotatedWith(Names.named(SERVER_URL)).toInstance(readRequiredUrlArg(SERVER_URL)); URL clientUrl = readUrlArg(CLIENT_URL); if (clientUrl != null) { bind(WebDriver.class).toInstance(new RemoteWebDriver(clientUrl, buildDriverCapabilities())); } else {/* w w w .j ava 2 s . co m*/ bind(WebDriver.class).toInstance(new FirefoxDriver()); } }
From source file:com.meschbach.onomate.tests.assembly.scenarios.AcceptanceTestRunner.java
License:Apache License
private WebDriver buildDriver(final String webDriverHost) throws MalformedURLException { DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); URL hostURL = new URL(webDriverHost); RemoteWebDriver driver = new RemoteWebDriver(hostURL, capabilities); driver.getErrorHandler().setIncludeServerErrors(true); driver.setLogLevel(Level.ALL); return driver; }
From source file:com.mgmtp.jfunk.web.RemoteWebDriverProvider.java
License:Apache License
@Override protected WebDriver createWebDriver(final DesiredCapabilities capabilities) { String remoteWebDriverUrl = config.get(WebConstants.REMOTE_WEBDRIVER_URL, ""); Validate.notBlank(remoteWebDriverUrl, "Property '%s' must be set in configuration", WebConstants.REMOTE_WEBDRIVER_URL); URL url;/*from ww w .j a va2 s . c om*/ try { url = new URL(remoteWebDriverUrl); } catch (MalformedURLException e) { throw new IllegalArgumentException("Illegal remote web driver hub url: " + remoteWebDriverUrl); } log.info("Starting remote web driver with capabilitiesMap: {}", capabilitiesMap); return new Augmenter().augment(new RemoteWebDriver(url, capabilities)); }
From source file:com.michaelpidde.testflow.engine.util.TestSuite.java
License:Open Source License
public void setup() { switch (browser) { case "ff": driver = new FirefoxDriver(); break;/*from w w w . j a v a2s .c o m*/ case "ie": try { service = new InternetExplorerDriverService.Builder() .usingDriverExecutable(new File(runPath + "\\IEDriverServer.exe")).usingAnyFreePort() .build(); ((InternetExplorerDriverService) service).start(); DesiredCapabilities ieOptions = DesiredCapabilities.internetExplorer(); ieOptions.setCapability("ignoreProtectedModeSettings", true); driver = new RemoteWebDriver(((InternetExplorerDriverService) service).getUrl(), ieOptions); driver = new Augmenter().augment(driver); } catch (NullPointerException e) { System.out.println(e.toString()); } catch (IOException e) { System.out.println(e.toString()); } break; case "chrome": try { service = new ChromeDriverService.Builder() .usingDriverExecutable(new File(runPath + "\\chromedriver.exe")).usingAnyFreePort().build(); ((ChromeDriverService) service).start(); DesiredCapabilities chromeOptions = DesiredCapabilities.chrome(); chromeOptions.setCapability("chrome.switches", Arrays.asList("--start-maximized")); driver = new RemoteWebDriver(((ChromeDriverService) service).getUrl(), chromeOptions); driver = new Augmenter().augment(driver); } catch (NullPointerException e) { System.out.println(e.toString()); } catch (IOException e) { System.out.println(e.toString()); } break; } // Set a wait period for finding elements, max of 10 seconds. driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Set up logger logger.setDriver(driver); // Start test suite run. driver.get(baseUrl); /* * This is not used currently. It's a step retained from legacy code, but I want * to leave it for now due to its potentially useful nature. A better way to do * this would be to change it to a test of the baseUrl and checking by response * (i.e. 404, 500, 501, etc.). */ // Do a quick smoke test to see if the URL has any errors on it. // CFError cferror = new CFError(driver, baseUrl, logger); // boolean error = false; // try { // error = cferror.run(); // } catch(TestException e) { // // Don't do anything with this error at this time. // } // if(error) { // runSuite = false; // } }
From source file:com.moodle.test.SeleniumManager.java
License:GNU General Public License
/** * Run tests using the RemoteWebdriver.//from w w w . j a v a 2s . c o m * Start Remotes, instantiating driver, desired capabilities are passed via variables from the test cases. * @param baseURL The base URL of the Selenium Server Grid hub. * @param browserType The browser type that the test will run in. See the Selenium API for details. * @throws MalformedURLException Catches an exception caused by a malformed URL. All URL's are malformed so this much be caught. */ //Remote WebDriver public void startRemotes(String baseURL, String browserType) throws MalformedURLException { DesiredCapabilities capability = new DesiredCapabilities(); capability.setBrowserName(browserType); capability.setJavascriptEnabled(true); driver = new RemoteWebDriver(new URL(baseURL), capability); }