List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities)
From source file:org.glowroot.agent.webdriver.tests.SauceLabs.java
License:Apache License
public static WebDriver getWebDriver(String testName) throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setBrowserName(browserName); if (!Strings.isNullOrEmpty(browserVersion)) { capabilities.setVersion(browserVersion); }/*from w w w . j a v a2 s . c om*/ if (Strings.isNullOrEmpty(deviceName)) { // webdriver capabilities capabilities.setCapability("platform", platform); // currently tests fail with default nativeEvents=true // (can't select radio buttons on capture point page) capabilities.setCapability("nativeEvents", false); } else { // appium capabilities int index = platform.indexOf(' '); String platformName = platform.substring(0, index); String platformVersion = platform.substring(index + 1); capabilities.setCapability("platformName", platformName); capabilities.setCapability("platformVersion", platformVersion); capabilities.setCapability("deviceName", deviceName); } // pass credentials using environment variables String sauceUsername = System.getenv("SAUCE_USERNAME"); String sauceAccessKey = System.getenv("SAUCE_ACCESS_KEY"); capabilities.setCapability("tunnel-identifier", tunnelIdentifier); capabilities.setCapability("name", testName); return new RemoteWebDriver( new URL("http://" + sauceUsername + ":" + sauceAccessKey + "@localhost:4445/wd/hub"), capabilities); }
From source file:org.glowroot.tests.webdriver.SauceLabs.java
License:Apache License
public static WebDriver getWebDriver(String testName) throws MalformedURLException { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.PLATFORM, platform); if (!Strings.isNullOrEmpty(browserName)) { // webdriver capabilities capabilities.setBrowserName(browserName); capabilities.setVersion(browserVersion); // currently tests fail with default nativeEvents=true // (can't select radio buttons on capture point page) capabilities.setCapability("nativeEvents", false); } else if (!Strings.isNullOrEmpty(deviceName)) { // appium capabilities capabilities.setCapability("device", deviceName); capabilities.setCapability("version", deviceVersion); capabilities.setCapability("app", deviceApp); if (deviceType != null) { capabilities.setCapability("device-type", deviceType); }/*from ww w . java 2 s.co m*/ if (deviceOrientation != null) { capabilities.setCapability("device-orientation", deviceOrientation); } } else { throw new AssertionError("Check useSauceLabs() first"); } // pass credentials using environment variables String sauceUsername = System.getenv("SAUCE_USERNAME"); String sauceAccessKey = System.getenv("SAUCE_ACCESS_KEY"); if (tunnelIdentifier != null) { capabilities.setCapability("tunnel-identifier", tunnelIdentifier); } capabilities.setCapability("name", testName); return new RemoteWebDriver( new URL("http://" + sauceUsername + ":" + sauceAccessKey + "@localhost:4445/wd/hub"), capabilities); }
From source file:org.gradle.needle.selenium.BrowserFactory.java
License:Apache License
private void setupBrowserCoreType(int type) { if (type == 1) { browserCore = new FirefoxDriver(); logger.info(" Firefox"); return;//from w w w. j av a 2s . c om } if (type == 2) { chromeServer = new ChromeDriverService.Builder() .usingDriverExecutable(new File(GlobalSettings.chromeDriverPath)).usingAnyFreePort().build(); try { chromeServer.start(); } catch (IOException e) { e.printStackTrace(); } DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized")); browserCore = new RemoteWebDriver(chromeServer.getUrl(), capabilities); logger.info("Chrome"); return; } if (type == 3) { System.setProperty("webdriver.ie.driver", GlobalSettings.ieDriverPath); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); browserCore = new InternetExplorerDriver(capabilities); logger.info(" IE "); return; } if (type == 4) { browserCore = new SafariDriver(); logger.info(" Safari "); return; } Assert.fail("Incorrect browser type"); }
From source file:org.integration.FluentLeniumWaitOnLabsTest.java
License:Apache License
@Override public WebDriver getDefaultDriver() { DesiredCapabilities capabillities = new DesiredCapabilities("firefox", "3.6.", Platform.WINDOWS); capabillities.setCapability("name", "Test of FluentLenium"); WebDriver driver = null;/*from w w w . ja v a2 s .c om*/ try { driver = new RemoteWebDriver(new URL( "http://fluentlenium:8906940f-5638-4c29-beb6-c331df039f48@ondemand.saucelabs.com:80/wd/hub"), capabillities); } catch (MalformedURLException e) { } return driver; }
From source file:org.jboss.arquillian.ajocado2.reusable.TestCapabilitiesSerialization.java
License:Apache License
@Test public void whenGetCapabilitiesFromRunningSessionThenItShouldBeSerializable() { RemoteWebDriver driver = new RemoteWebDriver(HUB_URL, DesiredCapabilities.firefox()); Capabilities initializedCapabilities = driver.getCapabilities(); assertTrue("Capabilities obtained from running session should be serializable", initializedCapabilities instanceof Serializable); driver.quit();// w ww . jav a2 s. c o m }
From source file:org.jboss.arquillian.ajocado2.reusable.TestReusingBrowserSession.java
License:Apache License
@Test public void whenBrowserSessionIsCreatedThenCouldBeReused() throws UnableReuseSessionException { RemoteWebDriver driver = new RemoteWebDriver(HUB_URL, DesiredCapabilities.firefox()); driver.navigate().to(SERVER_URL.toString()); Capabilities reusedCapabilities = serializeDeserialize(driver.getCapabilities()); SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString())); ReusableRemoteWebDriver reusedDriver = new ReusableRemoteWebDriver(HUB_URL, reusedCapabilities, reusedSessionId);/*from w w w .ja v a2s .c o m*/ reusedDriver.navigate().to(HUB_URL.toString()); reusedDriver.quit(); }
From source file:org.jboss.arquillian.ajocado2.reusable.TestReusingBrowserSession.java
License:Apache License
@Test public void whenBrowserSessionIsCreatedAndQuitAndTriedToReuseThenItShouldThrowException() { RemoteWebDriver driver = new RemoteWebDriver(HUB_URL, DesiredCapabilities.firefox()); driver.navigate().to(SERVER_URL.toString()); Capabilities reusedCapabilities = serializeDeserialize(driver.getCapabilities()); SessionId reusedSessionId = new SessionId(serializeDeserialize(driver.getSessionId().toString())); driver.quit();/*from w ww. j a v a 2 s .c o m*/ try { new ReusableRemoteWebDriver(HUB_URL, reusedCapabilities, reusedSessionId); fail("Original driver had quited before, so session should not be reusable"); } catch (UnableReuseSessionException e) { // exception should be thrown } }
From source file:org.jboss.arquillian.drone.webdriver.factory.RemoteWebDriverFactory.java
License:Apache License
private RemoteWebDriver createRemoteDriver(URL remoteAddress, Capabilities desiredCapabilities) { return new RemoteWebDriver(remoteAddress, desiredCapabilities); }
From source file:org.jboss.pressgang.ccms.page.WebDriverFactory.java
License:Open Source License
private WebDriver configureChromeDriver() { driverService = new ChromeDriverService.Builder() .usingDriverExecutable(new File(PropertiesHolder.properties.getProperty("webdriver.chrome.driver"))) .usingAnyFreePort()// w w w . j ava 2s . co m .withEnvironment( ImmutableMap.of("DISPLAY", PropertiesHolder.properties.getProperty("webdriver.display"))) .withLogFile(new File(PropertiesHolder.properties.getProperty("webdriver.log"))).build(); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("chrome.binary", PropertiesHolder.properties.getProperty("webdriver.chrome.bin")); try { driverService.start(); } catch (IOException e) { throw new RuntimeException("fail to start chrome driver service"); } return new RemoteWebDriver(driverService.getUrl(), capabilities); }
From source file:org.jitsi.meet.test.web.WebParticipantFactory.java
License:Apache License
/** * Starts a <tt>WebDriver</tt> instance using default settings. * @param options the options to use when creating the driver. * @return the <tt>WebDriver</tt> instance. *//*from www. j a va2 s . c o m*/ private WebDriver startWebDriver(WebParticipantOptions options) { ParticipantType participantType = options.getParticipantType(); String version = options.getVersion(); File browserBinaryAPath = getFile(options, options.getBinary()); boolean isRemote = options.isRemote(); // by default we load chrome, but we can load safari or firefox if (participantType.isFirefox()) { FirefoxDriverManager.getInstance().setup(); if (browserBinaryAPath != null && (browserBinaryAPath.exists() || isRemote)) { System.setProperty("webdriver.firefox.bin", browserBinaryAPath.getAbsolutePath()); } FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("media.navigator.permission.disabled", true); // Enables tcp in firefox, disabled by default in 44 profile.setPreference("media.peerconnection.ice.tcp", true); profile.setPreference("media.navigator.streams.fake", true); profile.setAcceptUntrustedCertificates(true); profile.setPreference("webdriver.log.file", FailureListener.createLogsFolder() + "/firefox-js-console-" + options.getName() + ".log"); System.setProperty("webdriver.firefox.logfile", FailureListener.createLogsFolder() + "/firefox-console-" + options.getName() + ".log"); if (isRemote) { FirefoxOptions ffOptions = new FirefoxOptions(); ffOptions.setProfile(profile); if (version != null && version.length() > 0) { ffOptions.setCapability(CapabilityType.VERSION, version); } return new RemoteWebDriver(options.getRemoteDriverAddress(), ffOptions); } return new FirefoxDriver(new FirefoxOptions().setProfile(profile)); } else if (participantType == ParticipantType.safari) { // You must enable the 'Allow Remote Automation' option in // Safari's Develop menu to control Safari via WebDriver. // In Safari->Preferences->Websites, select Camera, // and select Allow for "When visiting other websites" if (isRemote) { return new RemoteWebDriver(options.getRemoteDriverAddress(), new SafariOptions()); } return new SafariDriver(); } else if (participantType == ParticipantType.edge) { InternetExplorerDriverManager.getInstance().setup(); InternetExplorerOptions ieOptions = new InternetExplorerOptions(); ieOptions.ignoreZoomSettings(); System.setProperty("webdriver.ie.driver.silent", "true"); return new InternetExplorerDriver(ieOptions); } else { ChromeDriverManager.getInstance().setup(); System.setProperty("webdriver.chrome.verboseLogging", "true"); System.setProperty("webdriver.chrome.logfile", FailureListener.createLogsFolder() + "/chrome-console-" + options.getName() + ".log"); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); final ChromeOptions ops = new ChromeOptions(); ops.addArguments("use-fake-ui-for-media-stream"); ops.addArguments("use-fake-device-for-media-stream"); ops.addArguments("disable-plugins"); ops.addArguments("mute-audio"); ops.addArguments("disable-infobars"); // Since chrome v66 there are new autoplay policies, which broke // shared video tests, disable no-user-gesture to make it work ops.addArguments("autoplay-policy=no-user-gesture-required"); if (options.getChromeExtensionId() != null) { try { ops.addExtensions(downloadExtension(options.getChromeExtensionId())); } catch (IOException e) { throw new RuntimeException(e); } } ops.addArguments("auto-select-desktop-capture-source=Entire screen"); ops.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); if (options.isChromeSandboxDisabled()) { ops.addArguments("no-sandbox"); ops.addArguments("disable-setuid-sandbox"); } if (options.isHeadless()) { ops.addArguments("headless"); ops.addArguments("window-size=1200x600"); } // starting version 46 we see crashes of chrome GPU process when // running in headless mode // which leaves the browser opened and selenium hang forever. // There are reports that in older version crashes like that will // fallback to software graphics, we try to disable gpu for now ops.addArguments("disable-gpu"); if (browserBinaryAPath != null && (browserBinaryAPath.exists() || isRemote)) { ops.setBinary(browserBinaryAPath.getAbsolutePath()); } File uplinkFile = getFile(options, options.getUplink()); if (uplinkFile != null) { ops.addArguments("uplink=" + uplinkFile.getAbsolutePath()); } File downlinkFile = getFile(options, options.getDownlink()); if (downlinkFile != null) { ops.addArguments("downlink=" + downlinkFile.getAbsolutePath()); } String profileDirectory = options.getProfileDirectory(); if (profileDirectory != null && profileDirectory != "") { ops.addArguments("user-data-dir=" + profileDirectory); } File fakeStreamAudioFile = getFile(options, options.getFakeStreamAudioFile()); if (fakeStreamAudioFile != null) { ops.addArguments("use-file-for-fake-audio-capture=" + fakeStreamAudioFile.getAbsolutePath()); } File fakeStreamVideoFile = getFile(options, options.getFakeStreamVideoFile()); if (fakeStreamVideoFile != null) { ops.addArguments("use-file-for-fake-video-capture=" + fakeStreamVideoFile.getAbsolutePath()); } //ops.addArguments("vmodule=\"*media/*=3,*turn*=3\""); ops.addArguments("enable-logging"); ops.addArguments("vmodule=*=3"); if (isRemote) { if (version != null && version.length() > 0) { ops.setCapability(CapabilityType.VERSION, version); } return new RemoteWebDriver(options.getRemoteDriverAddress(), ops); } try { final ExecutorService pool = Executors.newFixedThreadPool(1); // we will retry four times for 1 minute to obtain // the chrome driver, on headless environments chrome hangs // and we wait forever for (int i = 0; i < 2; i++) { Future<ChromeDriver> future = null; try { future = pool.submit(() -> { long start = System.currentTimeMillis(); ChromeDriver resDr = new ChromeDriver(ops); TestUtils.print( "ChromeDriver created for:" + (System.currentTimeMillis() - start) + " ms."); return resDr; }); ChromeDriver res = future.get(2, TimeUnit.MINUTES); if (res != null) return res; } catch (TimeoutException te) { // cancel current task future.cancel(true); TestUtils.print("Timeout waiting for " + "chrome instance! We will retry now, this was our" + "attempt " + i); } } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } // keep the old code TestUtils.print("Just create ChromeDriver, may hang!"); return new ChromeDriver(ops); } }