List of usage examples for org.openqa.selenium.remote RemoteWebDriver getCapabilities
@Override
public Capabilities getCapabilities()
From source file:com.google.caja.plugin.WebDriverHandle.java
License:Apache License
private void reportVersion(RemoteWebDriver driver) { if (reportedVersion) { return;/* ww w.j a v a 2s . c o m*/ } reportedVersion = true; Capabilities caps = driver.getCapabilities(); String name = caps.getBrowserName(); if (name == null) { name = "unknown"; } String version = caps.getVersion(); if (version == null) { version = "unknown"; } // Firefox's version is something like "20.0", which doesn't tell // you the exact build, so we also try to report buildID. String build = (String) executeScript("return String(navigator.buildID || '')"); if (build != null && !"".equals(build)) { version += " build " + build; } Echo.echo("webdriver: browser " + name + " version " + version); }
From source file:com.jhyhh.appium.AndroidDriverWait.java
License:Apache License
@Override protected RuntimeException timeoutException(String message, Throwable lastException) { TimeoutException ex = new TimeoutException(message, lastException); ex.addInfo(WebDriverException.DRIVER_INFO, driver.getClass().getName()); if (driver instanceof RemoteWebDriver) { RemoteWebDriver remote = (RemoteWebDriver) driver; if (remote.getSessionId() != null) { ex.addInfo(WebDriverException.SESSION_ID, remote.getSessionId().toString()); }/*from w ww.j ava 2s. c o m*/ if (remote.getCapabilities() != null) { ex.addInfo("Capabilities", remote.getCapabilities().toString()); } } throw ex; }
From source file:com.liferay.faces.test.selenium.browser.internal.BrowserDriverImpl.java
License:Open Source License
@Override public String getBrowserName() { WebDriver webDriver = getWebDriver(); if (webDriver instanceof RemoteWebDriver) { RemoteWebDriver remoteWebDriver = (RemoteWebDriver) webDriver; return remoteWebDriver.getCapabilities().getBrowserName(); } else {/*from w w w . jav a 2 s. c o m*/ throw new UnsupportedOperationException("getBrowserName() not supported by this browser."); } }
From source file:com.partnet.automation.Browser.java
License:Apache License
/** * Obtains the browser associated with the given driver. * @param driver {@link WebDriver} instance to determine the browser type * @return {@link Browser} enum value of the current web driver *///from w w w . ja v a 2 s .c o m public static Browser getBrowser(WebDriver driver) { if (driver instanceof ChromeDriver) { return Browser.CHROME; } if (driver instanceof FirefoxDriver) { return Browser.FIREFOX; } if (driver instanceof InternetExplorerDriver) { return Browser.IE; } if (driver instanceof PhantomJSDriver) { return Browser.PHANTOMJS; } if (driver instanceof HtmlUnitDriver) { return Browser.HTMLUNIT; } if (!(driver instanceof RemoteWebDriver)) { throw new IllegalArgumentException( String.format("Could not determine the browser type for '%s'", driver.getClass())); } RemoteWebDriver remoteDriver = (RemoteWebDriver) driver; String browserName = remoteDriver.getCapabilities().getBrowserName().toLowerCase(); switch (browserName) { case "chrome": return Browser.CHROME; case "internet explorer": return Browser.IE; case "firefox": return Browser.FIREFOX; case "phantomjs": return Browser.PHANTOMJS; case "htmlunit": return Browser.HTMLUNIT; case "android": return Browser.ANDROID; default: throw new IllegalArgumentException( String.format("Could not determine remote web browser name: '%s'", browserName)); } }
From source file:com.seleniumtests.connectors.selenium.SeleniumGridConnector.java
License:Apache License
public void runTest(RemoteWebDriver driver) { // logging node ip address: try {/* www .j a v a2s. co m*/ JSONObject object = Unirest .get(String.format("http://%s:%d/grid/api/testsession/", hubUrl.getHost(), hubUrl.getPort())) .queryString("session", driver.getSessionId().toString()).asJson().getBody().getObject(); nodeUrl = (String) object.get("proxyId"); String node = nodeUrl.split("//")[1].split(":")[0]; String browserName = driver.getCapabilities().getBrowserName(); String version = driver.getCapabilities().getVersion(); // setting sessionId ensures that this connector is the active one sessionId = driver.getSessionId(); logger.info("WebDriver is running on node " + node + ", " + browserName + " " + version + ", session " + sessionId); } catch (Exception ex) { logger.error(ex); } }
From source file:com.vaadin.testbench.commands.TestBenchCommandExecutorTest.java
private WebDriver mockScreenshotDriver(int nrScreenshotsGrabbed, boolean expectGetCapabilities) throws IOException { RemoteWebDriver driver = createMock(FirefoxDriver.class); byte[] screenshotBytes = ImageLoader.loadImageBytes(IMG_FOLDER, "cursor-bottom-edge-off.png"); expect(driver.getScreenshotAs(OutputType.BYTES)).andReturn(screenshotBytes).times(nrScreenshotsGrabbed); if (expectGetCapabilities) { expect(driver.getCapabilities()).andReturn(createNiceMock(Capabilities.class)).once(); }//from w w w. ja v a2s .c o m return driver; }
From source file:galen.api.server.GalenCommandExecutor.java
License:Apache License
/** * Packages a successful session setup response which can be sent across the Thrift interface. *//*from w ww . j a v a 2 s . co m*/ private Response createSessionInitSuccessResponse(WebDriver driver) { Response response = new Response(); response.setStatus(SUCCESS); RemoteWebDriver remoteDriver = (RemoteWebDriver) driver; ThriftValueWrapper wrappedValue = new ThriftValueWrapper(remoteDriver.getCapabilities().asMap()); response.setResponse_value(wrappedValue.getValue()); response.setContained_values(wrappedValue.getContainedValues()); response.setSession_id(remoteDriver.getSessionId().toString()); response.setState(new ErrorCodes().toState(SUCCESS)); return response; }
From source file:io.selendroid.server.model.SelendroidStandaloneDriver.java
License:Apache License
public String createNewTestSession(JSONObject caps, Integer retries) throws AndroidSdkException, JSONException { SelendroidCapabilities desiredCapabilities = null; // Convert the JSON capabilities to SelendroidCapabilities try {//from w ww.j a v a 2 s. co m desiredCapabilities = new SelendroidCapabilities(caps); } catch (JSONException e) { throw new SelendroidException("Desired capabilities cannot be parsed."); } // Find the App being requested for use AndroidApp app = appsStore.get(desiredCapabilities.getAut()); if (app == null) { throw new SessionNotCreatedException( "The requested application under test is not configured in selendroid server."); } // adjust app based on capabilities (some parameters are session specific) app = augmentApp(app, desiredCapabilities); // Find a device to match the capabilities AndroidDevice device = null; try { device = getAndroidDevice(desiredCapabilities); } catch (AndroidDeviceException e) { SessionNotCreatedException error = new SessionNotCreatedException( "Error occured while finding android device: " + e.getMessage()); e.printStackTrace(); log.severe(error.getMessage()); throw error; } // If we are using an emulator need to start it up if (device instanceof AndroidEmulator) { AndroidEmulator emulator = (AndroidEmulator) device; try { if (emulator.isEmulatorStarted()) { emulator.unlockEmulatorScreen(); } else { Map<String, Object> config = new HashMap<String, Object>(); if (serverConfiguration.getEmulatorOptions() != null) { config.put(AndroidEmulator.EMULATOR_OPTIONS, serverConfiguration.getEmulatorOptions()); } config.put(AndroidEmulator.TIMEOUT_OPTION, serverConfiguration.getTimeoutEmulatorStart()); if (desiredCapabilities.asMap().containsKey(SelendroidCapabilities.DISPLAY)) { Object d = desiredCapabilities.getCapability(SelendroidCapabilities.DISPLAY); config.put(AndroidEmulator.DISPLAY_OPTION, String.valueOf(d)); } Locale locale = parseLocale(desiredCapabilities); emulator.start(locale, deviceStore.nextEmulatorPort(), config); } } catch (AndroidDeviceException e) { deviceStore.release(device, app); if (retries > 0) { return createNewTestSession(caps, retries - 1); } throw new SessionNotCreatedException( "Error occured while interacting with the emulator: " + emulator + ": " + e.getMessage()); } emulator.setIDevice(deviceManager.getVirtualDevice(emulator.getAvdName())); } boolean appInstalledOnDevice = device.isInstalled(app); if (!appInstalledOnDevice || serverConfiguration.isForceReinstall()) { device.install(app); } else { log.info("the app under test is already installed."); } int port = getNextSelendroidServerPort(); Boolean selendroidInstalledSuccessfully = device.isInstalled("io.selendroid." + app.getBasePackage()); if (!selendroidInstalledSuccessfully || serverConfiguration.isForceReinstall()) { AndroidApp selendroidServer = createSelendroidServerApk(app); selendroidInstalledSuccessfully = device.install(selendroidServer); if (!selendroidInstalledSuccessfully) { if (!device.install(selendroidServer)) { deviceStore.release(device, app); if (retries > 0) { return createNewTestSession(caps, retries - 1); } } } } else { log.info( "selendroid-server will not be created and installed because it already exists for the app under test."); } // Run any adb commands requested in the capabilities List<String> adbCommands = new ArrayList<String>(); adbCommands.add("shell setprop log.tag.SELENDROID " + serverConfiguration.getLogLevel().name()); adbCommands.addAll(desiredCapabilities.getPreSessionAdbCommands()); for (String adbCommandParameter : adbCommands) { device.runAdbCommand(adbCommandParameter); } // It's GO TIME! // start the selendroid server on the device and make sure it's up try { device.startSelendroid(app, port); } catch (AndroidSdkException e) { log.info("error while starting selendroid: " + e.getMessage()); deviceStore.release(device, app); if (retries > 0) { return createNewTestSession(caps, retries - 1); } throw new SessionNotCreatedException( "Error occurred while starting instrumentation: " + e.getMessage()); } long start = System.currentTimeMillis(); long startTimeOut = 20000; long timemoutEnd = start + startTimeOut; while (device.isSelendroidRunning() == false) { if (timemoutEnd >= System.currentTimeMillis()) { try { Thread.sleep(2000); } catch (InterruptedException e) { } } else { throw new SelendroidException( "Selendroid server on the device didn't came up after " + startTimeOut / 1000 + "sec:"); } } // arbitrary sleeps? yay... // looks like after the server starts responding // we need to give it a moment before starting a session? try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } // create the new session on the device server RemoteWebDriver driver; try { driver = new RemoteWebDriver(new URL("http://localhost:" + port + "/wd/hub"), desiredCapabilities); } catch (Exception e) { e.printStackTrace(); deviceStore.release(device, app); throw new SessionNotCreatedException("Error occurred while creating session on Android device", e); } String sessionId = driver.getSessionId().toString(); SelendroidCapabilities requiredCapabilities = new SelendroidCapabilities(driver.getCapabilities().asMap()); ActiveSession session = new ActiveSession(sessionId, requiredCapabilities, app, device, port, this); this.sessions.put(sessionId, session); // We are requesting an "AndroidDriver" so automatically switch to the webview if (BrowserType.ANDROID.equals(desiredCapabilities.getAut())) { // arbitrarily high wait time, will this cover our slowest possible device/emulator? WebDriverWait wait = new WebDriverWait(driver, 60); // wait for the WebView to appear wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("android.webkit.WebView"))); driver.switchTo().window("WEBVIEW"); // the 'android-driver' webview has an h1 with id 'AndroidDriver' embedded in it wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("AndroidDriver"))); } return sessionId; }
From source file:io.selendroid.standalone.server.model.SelendroidStandaloneDriver.java
License:Apache License
public String createNewTestSession(JSONObject caps, Integer retries) { AndroidDevice device = null;/*from w ww. j a v a 2 s. c o m*/ AndroidApp app = null; Exception lastException = null; while (retries >= 0) { try { SelendroidCapabilities desiredCapabilities = getSelendroidCapabilities(caps); String desiredAut = desiredCapabilities.getDefaultApp(appsStore.keySet()); app = getAndroidApp(desiredCapabilities, desiredAut); log.info("'" + desiredAut + "' will be used as app under test."); device = deviceStore.findAndroidDevice(desiredCapabilities); // If we are using an emulator need to start it up if (device instanceof AndroidEmulator) { startAndroidEmulator(desiredCapabilities, (AndroidEmulator) device); } boolean appInstalledOnDevice = device.isInstalled(app) || app instanceof InstalledAndroidApp; if (!appInstalledOnDevice || serverConfiguration.isForceReinstall()) { device.install(app); } else { log.info("the app under test is already installed."); } if (!serverConfiguration.isNoClearData()) { device.clearUserData(app); } int port = getNextSelendroidServerPort(); boolean serverInstalled = device.isInstalled("io.selendroid." + app.getBasePackage()); if (!serverInstalled || serverConfiguration.isForceReinstall()) { try { device.install(createSelendroidServerApk(app)); } catch (AndroidSdkException e) { throw new SessionNotCreatedException("Could not install selendroid-server on the device", e); } } else { log.info( "Not creating and installing selendroid-server because it is already installed for this app under test."); } // Run any adb commands requested in the capabilities List<String> preSessionAdbCommands = desiredCapabilities.getPreSessionAdbCommands(); runPreSessionCommands(device, preSessionAdbCommands); // Push extension dex to device if specified String extensionFile = desiredCapabilities.getSelendroidExtensions(); pushExtensionsToDevice(device, extensionFile); // Configure logging on the device device.setLoggingEnabled(serverConfiguration.isDeviceLog()); // It's GO TIME! // start the selendroid server on the device and make sure it's up eventListener.onBeforeDeviceServerStart(); device.startSelendroid(app, port, desiredCapabilities); waitForServerStart(device); eventListener.onAfterDeviceServerStart(); // arbitrary sleeps? yay... // looks like after the server starts responding // we need to give it a moment before starting a session? try { Thread.sleep(500); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); } // create the new session on the device server RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:" + port + "/wd/hub"), desiredCapabilities); String sessionId = driver.getSessionId().toString(); SelendroidCapabilities requiredCapabilities = new SelendroidCapabilities( driver.getCapabilities().asMap()); ActiveSession session = new ActiveSession(sessionId, requiredCapabilities, app, device, port, this); this.sessions.put(sessionId, session); // We are requesting an "AndroidDriver" so automatically switch to the webview if (BrowserType.ANDROID.equals(desiredCapabilities.getAut())) { switchToWebView(driver); } return sessionId; } catch (Exception e) { lastException = e; log.log(Level.SEVERE, "Error occurred while starting Selendroid session", e); retries--; // Return device to store if (device != null) { deviceStore.release(device, app); device = null; } } } if (lastException instanceof RuntimeException) { // Don't wrap the exception throw (RuntimeException) lastException; } else { throw new SessionNotCreatedException("Error starting Selendroid session", lastException); } }
From source file:library.utils.WebDriverUtils.java
License:Open Source License
protected String remoteBrowserName(RemoteWebDriver webDriver) { return webDriver.getCapabilities().getBrowserName(); }