Example usage for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver

List of usage examples for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver

Introduction

In this page you can find the example usage for org.openqa.selenium.remote RemoteWebDriver RemoteWebDriver.

Prototype

public RemoteWebDriver(URL remoteAddress, Capabilities capabilities) 

Source Link

Usage

From source file:com.example.selenium.grid.SeleniumGridTest.java

@Parameters({ "platform", "browser", "version", "url" })
@BeforeTest(alwaysRun = true)/* w  ww .j  a v  a2s. c o m*/
public void setup(String platform, String browser, String version, String url) throws MalformedURLException {

    DesiredCapabilities caps = new DesiredCapabilities();

    // Platforms
    if (platform.equalsIgnoreCase("Windows")) {
        caps.setPlatform(org.openqa.selenium.Platform.WINDOWS);
    }

    if (platform.equalsIgnoreCase("MAC")) {
        caps.setPlatform(org.openqa.selenium.Platform.MAC);
    }

    // Browsers
    if (browser.equalsIgnoreCase("Internet Explorer")) {
        caps = DesiredCapabilities.internetExplorer();
        caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        caps.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
        caps.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, true);
        caps.setCapability("requireWindowFocus", true);

    }

    if (browser.equalsIgnoreCase("Firefox")) {
        caps = DesiredCapabilities.firefox();
    }

    if (browser.equalsIgnoreCase("Chrome")) {
        caps = DesiredCapabilities.chrome();
        caps.setCapability("chrome.switches", Arrays.asList("--no-default-browser-check"));
        HashMap<String, String> chromePreferences = new HashMap<String, String>();
        chromePreferences.put("profile.password_manager_enabled", "false");
        caps.setCapability("chrome.prefs", chromePreferences);

    }

    if (browser.equalsIgnoreCase("Safari")) {
        caps = DesiredCapabilities.safari();
    }

    // Version
    caps.setVersion(version);

    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), caps);
    //driver.manage().window().maximize();
    // Open the BMI Calculator Application
    driver.get(url);

}

From source file:com.expedia.lux.accountsettingstest.core.CreateWebDriverHelper.java

License:Open Source License

/**
 * Create webdriver entry//from  w ww  .ja  v a  2s  .  c  om
 * 
 * @param testName
 * @param browserType
 *            1 is chrome, 2 is firefox, 0 is internet explorer, 3 is safari
 * @param logging
 * @return
 */
public static WebDriver createWebDriver(String testName, String testBrowser) {
    WebDriver driver = null;
    String isCloud = String.valueOf(isRemoteTest);

    if (!isRemoteTest) {
        DesiredCapabilities capabillities = new DesiredCapabilities();
        capabillities.setCapability(CapabilityType.SUPPORTS_WEB_STORAGE, false);
        switch (testBrowser.toUpperCase()) {
        case "IE":
            // Need set iedriver.exe file path
            System.setProperty("webdriver.ie.driver", ieDriverPath);
            driver = new InternetExplorerDriver(capabillities);
            break;
        case "FF":
            // TODO: Not stable
            capabillities.setCapability(FirefoxDriver.BINARY, new FirefoxBinary(new File(firefoxPath)));
            FirefoxProfile profile = new FirefoxProfile();
            profile.setAcceptUntrustedCertificates(true);
            capabillities.setCapability(FirefoxDriver.PROFILE, profile);
            driver = new FirefoxDriver(capabillities);
            break;
        case "SF":
            // TODO: No one's machine has safari installed in SZ
            driver = new SafariDriver(capabillities);
            break;
        default:
            // Need set the chromedriver.exe file path.
            System.setProperty("webdriver.chrome.driver", chromeDriverPath);
            driver = new ChromeDriver(capabillities);
            break;
        }
    } else {
        DesiredCapabilities capabillities;
        switch (testBrowser.toUpperCase()) {
        case "IE9":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability(CapabilityType.VERSION, "9");
            break;
        case "FF":
            capabillities = DesiredCapabilities.firefox();
            break;
        case "SF":
            capabillities = DesiredCapabilities.safari();
            capabillities.setCapability("platform", "OS X 10.6");
            capabillities.setCapability("version", "5");
            capabillities.setCapability("disable-popup-handler", true);
            break;
        case "IE7":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability(CapabilityType.VERSION, "7");
            break;
        case "IE8":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability(CapabilityType.VERSION, "8");
            break;
        case "IE10":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability(CapabilityType.VERSION, "10");
            break;
        case "IE11":
            capabillities = DesiredCapabilities.internetExplorer();
            capabillities.setCapability("version", "11");
            break;
        case "OP":
            capabillities = DesiredCapabilities.opera();
            capabillities.setCapability("version", "12");
            break;
        //Note: may not support HTTPS via sauceConnect with mobile platform yet
        case "IOS":
            capabillities = DesiredCapabilities.iphone();
            capabillities.setCapability("version", "6.1");
            capabillities.setCapability("platform", "OS X 10.8");
            capabillities.setCapability("device-orientation", "portrait");
            capabillities.setCapability("disable-popup-handler", true);
            break;
        case "AND":
            capabillities = DesiredCapabilities.android();
            capabillities.setCapability("version", "4.0");
            capabillities.setCapability("platform", "Linux");
            capabillities.setCapability("device-type", "tablet");
            capabillities.setCapability("device-orientation", "portrait");
            break;
        case "SAUCE":
            return createWebDriverSaucelab(testName + " (SauceLabs)");
        default:
            capabillities = DesiredCapabilities.chrome();
            capabillities.setBrowserName("chrome");
            break;
        }

        try {
            driver = new RemoteWebDriver(new URL("http://10.208.52.16:5555/wd/hub"), capabillities);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    fillBrowserName(testBrowser, isCloud);
    return driver;
}

From source file:com.expedia.lux.accountsettingstest.core.CreateWebDriverHelper.java

License:Open Source License

public static WebDriver createWebDriverSaucelab(String testName) {
    DesiredCapabilities capabillities = new DesiredCapabilities();
    // Set test name, use to show the test case name on remote site
    List tags = new ArrayList<String>();
    tags.add("LUX5");
    tags.add("PromotionsTest");
    capabillities.setCapability("tags", tags);
    capabillities.setCapability("build", buildNum);
    capabillities.setCapability("idle-timeout", 120);
    capabillities.setCapability("disable-popup-handler", true);
    capabillities.setCapability("record-video", false);
    capabillities.setCapability("video-upload-on-pass", false);
    capabillities.setCapability("capture-html", true);
    capabillities.setCapability("webdriver.remote.quietExceptions", false);
    capabillities.setCapability("sauce-advisor", false);
    // Set test use and password for remote site
    capabillities.setCapability("username", SAUCE_USER);
    capabillities.setCapability("accessKey", SAUCE_KEY);
    capabillities.setCapability("tunnel-identifier", identifier);
    capabillities.setCapability("name", testName);
    capabillities = DesiredCapabilities.chrome();
    capabillities.setBrowserName("chrome");

    try {//from  w w  w  . j  a v a2  s  .  c o  m
        WebDriver driver = new RemoteWebDriver(new URL(remoteSite), capabillities);
        // Set driver implicit time to wait for element to appear
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return driver;
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:com.fmb.common.BrowserEmulator.java

License:Apache License

private void setupBrowserCoreType(int type) {
    if (type == 1) {
        browserCore = new FirefoxDriver();
        logger.info("Using Firefox");
        return;//ww w .j a v a2  s .  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("Using 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("Using IE");
        return;
    }
    if (type == 4) {
        browserCore = new SafariDriver();
        logger.info("Using Safari");
        return;
    }

    Assert.fail("Incorrect browser type");
}

From source file:com.fullteaching.backend.e2e.ChromeUser.java

License:Apache License

public ChromeUser(String userName, int timeOfWaitInSeconds) {
    super(userName, timeOfWaitInSeconds);

    ChromeOptions options = new ChromeOptions();
    // This flag avoids to grant the user media
    options.addArguments("--use-fake-ui-for-media-stream");
    // This flag fakes user media with synthetic video
    options.addArguments("--use-fake-device-for-media-stream");
    // This flag selects the entire screen as video source when screen sharing
    options.addArguments("--auto-select-desktop-capture-source=Entire screen");

    String eusApiURL = System.getenv("ET_EUS_API");

    if (eusApiURL == null) {
        this.driver = new ChromeDriver(options);
    } else {//from   w w w  .j  a  v  a  2  s . com

        try {
            DesiredCapabilities caps = new DesiredCapabilities();
            caps.setBrowserName("chrome");
            //caps.setVersion("61");
            caps.setCapability(ChromeOptions.CAPABILITY, options);

            this.driver = new RemoteWebDriver(new URL(eusApiURL), caps);

        } catch (MalformedURLException e) {
            throw new RuntimeException("Exception creaing eusApiURL", e);
        }
    }

    this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);

    this.configureDriver();
}

From source file:com.fullteaching.backend.e2e.FirefoxUser.java

License:Apache License

public FirefoxUser(String userName, int timeOfWaitInSeconds) {
    super(userName, timeOfWaitInSeconds);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("acceptInsecureCerts", true);
    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 eusApiURL = System.getenv("ET_EUS_API");

    if (eusApiURL == null) {
        this.driver = new FirefoxDriver(capabilities);
    } else {/*from   www . java 2  s .  co m*/
        try {
            capabilities.setBrowserName("firefox");

            this.driver = new RemoteWebDriver(new URL(eusApiURL), capabilities);

        } catch (MalformedURLException e) {
            throw new RuntimeException("Exception creaing eusApiURL", e);
        }
    }

    this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);

    this.configureDriver();
}

From source file:com.galenframework.browser.SeleniumGridBrowserFactory.java

License:Apache License

@Override
public Browser openBrowser() {
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();

    if (platform != null) {
        desiredCapabilities.setPlatform(platform);
    }//from  ww w .ja  va  2 s. c o  m

    if (browser != null) {
        desiredCapabilities.setBrowserName(browser);
    }

    if (browserVersion != null) {
        desiredCapabilities.setVersion(browserVersion);
    }

    for (Map.Entry<String, String> dc : this.desiredCapabilities.entrySet()) {
        desiredCapabilities.setCapability(dc.getKey(), dc.getValue());
    }

    try {

        WebDriver driver = new RemoteWebDriver(new URL(gridUrl), desiredCapabilities);
        WebDriver augmentedDriver = new Augmenter().augment(driver);
        return new SeleniumBrowser(augmentedDriver);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.ggasoftware.jdiuitest.web.selenium.driver.SeleniumDriverFactory.java

License:Open Source License

public void registerDriver(DriverTypes driverType) {
    switch (runType) {
    case LOCAL:/*from  w w  w  .j a  va2s.c o m*/
        registerLocalDriver(driverType);
        return;
    case SAUCE_LAB:
        registerDriver("SauceLab " + driverType, () -> new RemoteWebDriver(SauceLabRunner.getSauceUrl(),
                SauceLabRunner.getSauceDesiredCapabilities(driverType)));
        return;
    }
    throw exception("Unknown driver: " + driverType);
}

From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * initialization RemoteWebDriver//from   w w  w .j a v a  2  s .  c  o  m
 *
 * @param remoteUrl    - remote host
 * @param capabilities - desired capabilities
 * @throws MalformedURLException - exception
 */
public static void initRemoteWebDriver(String remoteUrl, Capabilities capabilities)
        throws MalformedURLException {
    ReporterNGExt.logTechnical(String.format("Initialization Remote Web Driver at url '%s'", remoteUrl));
    setWebDriver(new RemoteWebDriver(new URL(remoteUrl), capabilities));
    setTimeout(TIMEOUT);
    getDriver().manage().window().maximize();
}

From source file:com.github.dactiv.common.unit.selenium.WebDriverFactory.java

License:Apache License

/**
 * ?driverName??WebDriver.//  ww w.ja  v  a 2s .c  o m
 * 
 * ??firefox,ie,chrome??.
 * 
 * ????Windows, IE?XWindows, ???remote driverWindows.
 * drivernameremote:192.168.0.2:4444:firefox, ??http://192.168.0.2:4444/wd/hub?selenium remote?.
 */
public static WebDriver createDriver(String driverName) {
    WebDriver driver = null;

    if (BrowserType.firefox.name().equals(driverName)) {
        driver = new FirefoxDriver();
    } else if (BrowserType.ie.name().equals(driverName)) {
        driver = new InternetExplorerDriver();
    } else if (BrowserType.chrome.name().equals(driverName)) {
        driver = new ChromeDriver();
    } else if (driverName.startsWith(BrowserType.remote.name())) {
        String[] params = driverName.split(":");
        Assert.isTrue(params.length == 4,
                "Remote driver is not right, accept format is \"remote:localhost:4444:firefox\", but the input is\""
                        + driverName + "\"");

        String remoteHost = params[1];
        String remotePort = params[2];
        String driverType = params[3];

        String remoteUrl = "http://" + remoteHost + ":" + remotePort + "/wd/hub";

        DesiredCapabilities cap = null;
        if (BrowserType.firefox.name().equals(driverType)) {
            cap = DesiredCapabilities.firefox();
        } else if (BrowserType.ie.name().equals(driverType)) {
            cap = DesiredCapabilities.internetExplorer();
        } else if (BrowserType.chrome.name().equals(driverType)) {
            cap = DesiredCapabilities.chrome();
        }

        try {
            driver = new RemoteWebDriver(new URL(remoteUrl), cap);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }

    Assert.notNull(driver, "Driver could be found by name:" + driverName);

    return driver;
}