List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver
public RemoteWebDriver(URL remoteAddress, Capabilities capabilities)
From source file:io.github.bonigarcia.wdm.test.WebRtcRemoteFirefoxTest.java
License:Apache License
@Before public void setup() throws MalformedURLException { DesiredCapabilities capabilities = firefox(); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("media.navigator.permission.disabled", true); profile.setPreference("media.navigator.streams.fake", true); capabilities.setCapability(PROFILE, profile); driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities); }
From source file:io.github.mmichaelis.selenium.client.provider.internal.SilentAugmenterTest.java
License:Apache License
@Test public void augments_remote_webdriver_instance() throws Exception { final WebDriver driver = new RemoteWebDriver(SELENIUM_SERVER_RULE.getUrl(), DesiredCapabilities.htmlUnitWithJs()); final WebDriver augmented1 = new SilentAugmenter().augment(driver); errorCollector.checkThat("First augmentation should have changed instance.", driver, Matchers.not(Matchers.sameInstance(augmented1))); final WebDriver augmented2 = new SilentAugmenter().augment(augmented1); errorCollector.checkThat("Second augmentation should have changed instance.", augmented1, Matchers.not(Matchers.sameInstance(augmented2))); }
From source file:io.github.mmichaelis.selenium.client.provider.RemoteWebDriverProvider.java
License:Apache License
@CheckReturnValue @Override// w ww. j a va 2s. co m @Nonnull protected WebDriver instantiateDriver() { try { return new RemoteWebDriver(url, desiredCapabilities); } catch (final WebDriverException e) { throw new WebDriverInstantiationException( format("Failed to instantiate RemoteWebDriver with server URL %s and desired capabilities %s.", url, desiredCapabilities), e); } }
From source file:io.kahu.hawaii.cucumber.glue.html.HtmlSteps.java
License:Apache License
private WebDriver createRemoteWebDriverForCapabilities(DesiredCapabilities capabilities) throws Exception { WebDriver driver;/*w w w .ja v a2 s. c om*/ Proxy proxy = getHttpProxy(); if (proxy != null) { capabilities.setCapability(CapabilityType.PROXY, getHttpProxy()); } driver = new RemoteWebDriver(new URL(seleniumHub), capabilities); return driver; }
From source file:io.openvidu.test.browsers.ChromeAndroidUser.java
License:Apache License
public ChromeAndroidUser(String userName, int timeOfWaitInSeconds) { super(userName, timeOfWaitInSeconds); Map<String, String> mobileEmulation = new HashMap<>(); mobileEmulation.put("deviceName", "Pixel 2"); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setAcceptInsecureCerts(true); capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); // This flag avoids to grant the user media chromeOptions.addArguments("--use-fake-ui-for-media-stream"); // This flag fakes user media with synthetic video chromeOptions.addArguments("--use-fake-device-for-media-stream"); String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME"); if (REMOTE_URL != null) { log.info("Using URL {} to connect to remote web driver", REMOTE_URL); try {// ww w . j a v a 2 s . com this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } else { log.info("Using local web driver"); this.driver = new ChromeDriver(capabilities); } this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.configureDriver(); }
From source file:io.openvidu.test.browsers.ChromeUser.java
License:Apache License
private ChromeUser(String userName, int timeOfWaitInSeconds, ChromeOptions options) { super(userName, timeOfWaitInSeconds); options.setAcceptInsecureCerts(true); options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE); options.addArguments("--disable-infobars"); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.media_stream_mic", 1); prefs.put("profile.default_content_setting_values.media_stream_camera", 1); options.setExperimentalOption("prefs", prefs); String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME"); if (REMOTE_URL != null) { log.info("Using URL {} to connect to remote web driver", REMOTE_URL); try {/* w ww . j ava 2s. co m*/ this.driver = new RemoteWebDriver(new URL(REMOTE_URL), options); } catch (MalformedURLException e) { e.printStackTrace(); } } else { log.info("Using local web driver"); this.driver = new ChromeDriver(options); } this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS); this.configureDriver(); }
From source file:io.openvidu.test.browsers.FirefoxUser.java
License:Apache License
public FirefoxUser(String userName, int timeOfWaitInSeconds) { super(userName, timeOfWaitInSeconds); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setAcceptInsecureCerts(true); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); FirefoxProfile profile = new FirefoxProfile(); // This flag avoids granting the access to the camera profile.setPreference("media.navigator.permission.disabled", true); // This flag force to use fake user media (synthetic video of multiple color) profile.setPreference("media.navigator.streams.fake", true); capabilities.setCapability(FirefoxDriver.PROFILE, profile); String REMOTE_URL = System.getProperty("REMOTE_URL_FIREFOX"); if (REMOTE_URL != null) { log.info("Using URL {} to connect to remote web driver", REMOTE_URL); try {//w ww.j a v a 2 s . c o m this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } } else { log.info("Using local web driver"); this.driver = new FirefoxDriver(capabilities); } this.configureDriver(); }
From source file:io.selendroid.server.e2e.SessionCreationE2ETests.java
License:Apache License
private void testMethod(SelendroidCapabilities capa) throws Exception { WebDriver driver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"), capa); String activityClass = "io.selendroid.testapp." + "HomeScreenActivity"; driver.get("and-activity://" + activityClass); driver.getCurrentUrl();//from w w w. j a v a 2s . c o m try { driver.findElement(By.id("not there")); Assert.fail(); } catch (NoSuchElementException e) { // expected } WebElement inputField = driver.findElement(By.id("my_text_field")); Assert.assertEquals("true", inputField.getAttribute("enabled")); inputField.sendKeys("Selendroid"); Assert.assertEquals("Selendroid", inputField.getText()); driver.findElement(By.id("buttonStartWebview")).click(); driver.switchTo().window("WEBVIEW"); WebElement element = driver.findElement(By.id("name_input")); element.clear(); ((JavascriptExecutor) driver).executeScript("var inputs = document.getElementsByTagName('input');" + "for(var i = 0; i < inputs.length; i++) { " + " inputs[i].value = 'helloJavascript';" + "}"); Assert.assertEquals("helloJavascript", element.getAttribute("value")); driver.quit(); }
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 {/*ww w . ja v a 2 s . c o 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 ww w.ja va 2s . 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); } }