List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities)
From source file:org.uiautomation.ios.selenium.Demo.java
License:Apache License
public static void main(String[] args) throws Exception { IOSCapabilities catalog = IOSCapabilities.iphone("UICatalog"); RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), catalog); // by default, the app starts in native mode. WebElement web = driver.findElement(By.xpath("//UIATableCell[contains(@name,'Web')]")); web.click();//w w w.j ava 2s. com // now that a webview is displayed, switch to web mode. driver.switchTo().window("Web"); // and select items using natural web selectors. final By cssSelector = By.cssSelector("a[href='http://store.apple.com/']"); // reuse whatever contrust your webdriver tests are using. WebElement el = waitFor(elementToExist(driver, cssSelector)); Assert.assertEquals(el.getAttribute("href"), "http://store.apple.com/"); driver.quit(); }
From source file:org.uiautomation.ios.selenium.Demo.java
License:Apache License
public static void main2(String[] args) throws Exception { DesiredCapabilities safari = IOSCapabilities.iphone("Safari"); RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), safari); driver.get("http://hp.mobileweb.ebay.co.uk/home"); WebElement search = driver.findElement(By.id("srchDv")); search.sendKeys("ipod"); search.submit();/*from w ww . j av a 2s.c om*/ waitFor(pageTitleToBe(driver, "ipod | eBay Mobile Web")); driver.quit(); }
From source file:org.usapi.SeleniumFactory.java
License:Apache License
/** * Returns an instance of WebDriver.//from ww w .j a v a2 s .c om * * This is a singleton that is instantiated with parameters * from system properties with overrides */ public static WebDriver getWebDriverInstance() { if (webDriver == null) { String browser = PropertyHelper.getSeleniumBrowserCommand(); String seleniumServerHost = PropertyHelper.getSeleniumServerHost(); String seleniumServerPort = PropertyHelper.getSeleniumServerPort(); // if selenium server host/port properties are set, they were passed in via // .properties or -D. Either way, this tells us that we are running on the // grid and need to instantiate our web driver such that it knows to use // selenium server if (seleniumServerHost.length() > 0 && seleniumServerPort.length() > 0) { URL seleniumServerUrl = null; try { seleniumServerUrl = new URL( "http://" + seleniumServerHost + ":" + seleniumServerPort + "/wd/hub"); } catch (MalformedURLException e) { // this should never happen, as the default values for serverHost and port are localhost and 4444. Only if // overrides (from .properties or cmd line) result in an invalid URL this exception handler would get invoked. log.error("Invalid value for Selenium Server Host or Selenium Server Port. Provided values: <" + seleniumServerHost + "> <" + seleniumServerPort + ">"); } DesiredCapabilities capability = getDesiredCapabilities(browser); if (browser.toLowerCase().contains(BROWSER_TYPE_FIREFOX)) { capability.setCapability("nativeEvents", PropertyHelper.getEnableNativeEvents()); capability.setCapability("name", "Remote File Upload using Selenium 2's FileDetectors"); } RemoteWebDriver rwd = new RemoteWebDriver(seleniumServerUrl, capability); rwd.setFileDetector(new LocalFileDetector()); webDriver = new Augmenter().augment((WebDriver) rwd); } // no, we are not running on the grid. Just instantiate the driver for the desired // browser directly. else { if (browser.toLowerCase().contains(BROWSER_TYPE_FIREFOX)) { FirefoxProfile p = new FirefoxProfile(); p.setEnableNativeEvents(PropertyHelper.getEnableNativeEvents()); webDriver = new FirefoxDriver(p); } else if (browser.toLowerCase().contains(BROWSER_TYPE_IEXPLORE)) { webDriver = new InternetExplorerDriver(); } else if (browser.toLowerCase().contains(BROWSER_TYPE_CHROME)) { webDriver = new RemoteWebDriver(getChromeDriverURL(), DesiredCapabilities.chrome()); webDriver = new Augmenter().augment((WebDriver) webDriver); } else if (browser.toLowerCase().contains(BROWSER_TYPE_SAFARI)) { webDriver = new SafariDriver(); } else if (browser.toLowerCase().contains(BROWSER_TYPE_HTMLUNIT)) { DesiredCapabilities capabilities = getDesiredCapabilities(browser); capabilities.setJavascriptEnabled(PropertyHelper.getHtmlUnitEnableJavascript()); webDriver = new HtmlUnitDriver(capabilities); } } // default in PropertyHelper is 0. Set this options only if they were explicitly specified (.properties or // in the environment long scriptTimeout = PropertyHelper.getScriptTimeout(); long implicitlyWait = PropertyHelper.getImplicitlyWait(); long pageLoadTimeout = PropertyHelper.getPageLoadTimeout(); if (scriptTimeout > 0) webDriver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.MILLISECONDS); if (implicitlyWait > 0) webDriver.manage().timeouts().implicitlyWait(implicitlyWait, TimeUnit.MILLISECONDS); if (pageLoadTimeout > 0) webDriver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.MILLISECONDS); } return webDriver; }
From source file:org.vaadin.testbenchsauce.BaseTestBenchTestCase.java
private void useGhostDriver() throws Exception { final DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setCapability("takesScreenshot", true); final URL remoteAddress = new URL("http://localhost:" + REMOTE_DRIVER_PORT); if (USE_REMOTE_WEB_DRIVER) { RemoteWebDriver remoteWebDriver = new Retry<RemoteWebDriver>(new Retryable<RemoteWebDriver>() { @Override// ww w . j a v a2 s . c om public RemoteWebDriver run() { return new RemoteWebDriver(remoteAddress, desiredCapabilities); } }).run(); setDriver(TestBench.createDriver(remoteWebDriver)); } else { //Haven't tested this in a while, sicne the remote driver always gave higher performance desiredCapabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, getPhantomJsPath() + "phantomjs.exe"); PhantomJSDriver phantomJSDriver = new PhantomJSDriver(desiredCapabilities); // phantomJSDriver.setLogLevel(java.util.logging.Level.ALL); driver = phantomJSDriver; setDriver(TestBench.createDriver(driver)); } }
From source file:org.webbench.SeleniumServerRun.java
License:Apache License
public static void main(String[] args) throws Exception { // We could use any driver for our tests... DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); // ... but only if it supports javascript capabilities.setJavascriptEnabled(true); // Get a handle to the driver. This will throw an exception // if a matching driver cannot be located WebDriver driver1 = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities); // Query the driver to find out more information // Capabilities actualCapabilities = ((RemoteWebDriver) driver1).getCapabilities(); // And now use it driver1.get("http://www.google.com"); // WebDriver driver2 = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities); // driver2.get("http://www.google.com"); // Thread.sleep(60000); driver1.close();/*w ww.j a v a 2s .co m*/ // driver2.close(); }
From source file:org.webtestingexplorer.driver.ChromeWebDriverFactory.java
License:Open Source License
@Override public WebDriver createWebDriver(WebDriverProxy proxy) throws Exception { DesiredCapabilities driverCapabilities = DesiredCapabilities.chrome(); if (proxy != null) { driverCapabilities.setCapability(CapabilityType.PROXY, proxy.getSeleniumProxy()); }/*from w w w. ja v a 2 s. c o m*/ return new RemoteWebDriver(driverService.getUrl(), driverCapabilities); }
From source file:org.wso2.carbon.automation.extensions.selenium.BrowserManager.java
License:Open Source License
private static void getRemoteWebDriver() throws MalformedURLException, XPathExpressionException { URL url;/*from w w w . j a va 2 s. co m*/ String browserName = automationContext .getConfigurationNodeList(String.format(XPathConstants.SELENIUM_BROWSER_TYPE)).item(0) .getFirstChild().getNodeValue(); String remoteWebDriverURL = automationContext .getConfigurationValue(String.format(XPathConstants.SELENIUM_REMOTE_WEB_DRIVER_URL)); if (log.isDebugEnabled()) { log.debug("Browser selection " + browserName); log.debug("Remote WebDriverURL " + remoteWebDriverURL); } try { url = new URL(remoteWebDriverURL); } catch (MalformedURLException e) { log.error("Malformed URL " + e); throw new MalformedURLException("Malformed URL " + e); } DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setJavascriptEnabled(true); capabilities.setBrowserName(browserName); driver = new RemoteWebDriver(url, capabilities); }
From source file:org.xframium.device.factory.spi.WEBDriverFactory.java
License:Open Source License
@Override protected DeviceWebDriver _createDriver(Device currentDevice) { DeviceWebDriver webDriver = null;/*from w w w . j a v a 2s . c o m*/ try { DesiredCapabilities dc = null; if (currentDevice.getBrowserName() != null && !currentDevice.getBrowserName().isEmpty()) dc = new DesiredCapabilities(currentDevice.getBrowserName(), "", Platform.ANY); else dc = new DesiredCapabilities("", "", Platform.ANY); CloudDescriptor useCloud = CloudRegistry.instance().getCloud(); if (currentDevice.getCloud() != null) { useCloud = CloudRegistry.instance().getCloud(currentDevice.getCloud()); if (useCloud == null) { useCloud = CloudRegistry.instance().getCloud(); log.warn("A separate grid instance was specified but it does not exist in your cloud registry [" + currentDevice.getCloud() + "] - using the default Cloud instance"); } } URL hubUrl = new URL(useCloud.getCloudUrl()); if (currentDevice.getDeviceName() != null && !currentDevice.getDeviceName().isEmpty()) { dc.setCapability(ID, currentDevice.getDeviceName()); dc.setCapability(USER_NAME, CloudRegistry.instance().getCloud().getUserName()); dc.setCapability(PASSWORD, CloudRegistry.instance().getCloud().getPassword()); } else { dc.setCapability(PLATFORM_NAME, currentDevice.getOs()); dc.setCapability(PLATFORM_VERSION, currentDevice.getOsVersion()); dc.setCapability(MODEL, currentDevice.getModel()); dc.setCapability(USER_NAME, CloudRegistry.instance().getCloud().getUserName()); dc.setCapability(PASSWORD, CloudRegistry.instance().getCloud().getPassword()); } if (currentDevice.getBrowserName() != null && !currentDevice.getBrowserName().isEmpty()) dc.setCapability(BROWSER_NAME, currentDevice.getBrowserName()); if (currentDevice.getBrowserVersion() != null && !currentDevice.getBrowserVersion().isEmpty()) dc.setCapability(BROWSER_VERSION, currentDevice.getBrowserVersion()); for (String name : currentDevice.getCapabilities().keySet()) dc = setCapabilities(currentDevice.getCapabilities().get(name), dc, name); for (String name : ApplicationRegistry.instance().getAUT().getCapabilities().keySet()) dc = setCapabilities(ApplicationRegistry.instance().getAUT().getCapabilities().get(name), dc, name); if (log.isInfoEnabled()) log.info("Acquiring Device as: \r\n" + capabilitiesToString(dc) + "\r\nagainst " + hubUrl); webDriver = new DeviceWebDriver(new RemoteWebDriver(hubUrl, dc), DeviceManager.instance().isCachingEnabled(), currentDevice); webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); Capabilities caps = ((RemoteWebDriver) webDriver.getWebDriver()).getCapabilities(); webDriver.setExecutionId(useCloud.getCloudActionProvider().getExecutionId(webDriver)); webDriver.setReportKey(caps.getCapability("reportKey") + ""); webDriver.setDeviceName(caps.getCapability("deviceName") + ""); webDriver.setWindTunnelReport(caps.getCapability("windTunnelReportUrl") + ""); webDriver.setArtifactProducer(getCloudActionProvider(useCloud).getArtifactProducer()); webDriver.setCloud(useCloud); if (ApplicationRegistry.instance().getAUT().getUrl() != null) webDriver.get(ApplicationRegistry.instance().getAUT().getUrl()); return webDriver; } catch (Exception e) { log.fatal("Could not connect to Cloud instance for " + currentDevice, e); if (webDriver != null) { try { webDriver.close(); } catch (Exception e2) { } try { webDriver.quit(); } catch (Exception e2) { } } return null; } }
From source file:org.zanata.page.WebDriverFactory.java
License:Open Source License
private EventFiringWebDriver configureChromeDriver() { System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, PropertiesHolder.getProperty("webdriver.log")); driverService = ChromeDriverService.createDefaultService(); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("chrome.binary", PropertiesHolder.properties.getProperty("webdriver.chrome.bin")); ChromeOptions options = new ChromeOptions(); URL url = Thread.currentThread().getContextClassLoader() .getResource("zanata-testing-extension/chrome/manifest.json"); assert url != null : "can't find extension (check testResource config in pom.xml)"; File file = new File(url.getPath()).getParentFile(); options.addArguments("load-extension=" + file.getAbsolutePath()); capabilities.setCapability(ChromeOptions.CAPABILITY, options); enableLogging(capabilities);/*w w w. j a v a2s . c o m*/ // start the proxy BrowserMobProxy proxy = new BrowserMobProxyServer(); proxy.start(0); proxy.addFirstHttpFilterFactory( new ResponseFilterAdapter.FilterSource((response, contents, messageInfo) -> { // TODO fail test if response >= 500? if (response.getStatus().code() >= 400) { log.warn("Response {} for URI {}", response.getStatus(), messageInfo.getOriginalRequest().getUri()); } else { log.info("Response {} for URI {}", response.getStatus(), messageInfo.getOriginalRequest().getUri()); } }, 0)); Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy); capabilities.setCapability(CapabilityType.PROXY, seleniumProxy); try { driverService.start(); } catch (IOException e) { throw new RuntimeException("fail to start chrome driver service"); } return new EventFiringWebDriver( new Augmenter().augment(new RemoteWebDriver(driverService.getUrl(), capabilities))); }
From source file:org.zaproxy.zap.extension.jxbrowserlinux64.selenium.JxBrowserProvider.java
License:Apache License
private RemoteWebDriver getRemoteWebDriverImpl(final int requesterId, String proxyAddress, int proxyPort) { try {//from www . j ava 2 s . c o m ZapBrowserFrame zbf = this.getZapBrowserFrame(requesterId); File dataDir = Files.createTempDirectory("zap-jxbrowser").toFile(); dataDir.deleteOnExit(); BrowserContextParams contextParams = new BrowserContextParams(dataDir.getAbsolutePath()); if (proxyAddress != null && !proxyAddress.isEmpty()) { String hostPort = proxyAddress + ":" + proxyPort; String proxyRules = "http=" + hostPort + ";https=" + hostPort; contextParams.setProxyConfig(new CustomProxyConfig(proxyRules)); } BrowserPreferences.setChromiumSwitches("--remote-debugging-port=" + chromePort); Browser browser = new Browser(new BrowserContext(contextParams)); final BrowserPanel browserPanel = zbf.addNewBrowserPanel(isNotAutomated(requesterId), browser); if (!ensureExecutable(webdriver)) { throw new IllegalStateException("Failed to ensure WebDriver is executable."); } final ChromeDriverService service = new ChromeDriverService.Builder() .usingDriverExecutable(webdriver.toFile()).usingAnyFreePort().build(); service.start(); DesiredCapabilities capabilities = new DesiredCapabilities(); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("debuggerAddress", "localhost:" + chromePort); capabilities.setCapability(ChromeOptions.CAPABILITY, options); return new RemoteWebDriver(service.getUrl(), capabilities) { @Override public void close() { super.close(); cleanUpBrowser(requesterId, browserPanel); // XXX should stop here too? // service.stop(); } @Override public void quit() { super.quit(); cleanUpBrowser(requesterId, browserPanel); boolean interrupted = Thread.interrupted(); service.stop(); if (interrupted) { Thread.currentThread().interrupt(); } } }; } catch (Exception e) { throw new WebDriverException(e); } }