Example usage for org.openqa.selenium.remote DesiredCapabilities setBrowserName

List of usage examples for org.openqa.selenium.remote DesiredCapabilities setBrowserName

Introduction

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

Prototype

public void setBrowserName(String browserName) 

Source Link

Usage

From source file:com.algomedica.service.AlgomedicaTest.java

@Parameters("browser")
@BeforeTest/*from  w ww.  ja v a 2  s  .c o m*/
public void launchapp(@Optional("chrome") String browser) throws MalformedURLException {
    URL = "http://10.4.1.70:8080/AlgomedicaLS/#/";
    if (browser.equalsIgnoreCase("firefox")) {
        System.setProperty("webdriver.gecko.driver", "driver/geckodriver.exe");
        String Node = "http://10.4.1.70:5555/wd/hub";
        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setBrowserName("firefox");

        driver = new RemoteWebDriver(new URL(Node), cap);
        // Puts an Implicit wait, Will wait for 10 seconds before throwing exception
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        // Launch website
        driver.navigate().to(URL);
        driver.manage().window().maximize();
    } else if (browser.equalsIgnoreCase("chrome")) {
        System.out.println(" Executing on CHROME");
        //     System.setProperty("webdriver.chrome.driver", "D://selenium//chromedriver.exe");

        DesiredCapabilities cap = DesiredCapabilities.chrome();
        cap.setBrowserName("chrome");
        String Node = "http://10.4.1.70:5558/wd/hub";
        driver = new RemoteWebDriver(new URL(Node), cap);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        // Launch website
        driver.navigate().to(URL);
        driver.manage().window().maximize();
    }
}

From source file:com.ceiwc.compugain.setup.TestBase.java

public WebDriver initializeDriver(String sbrowser, String sgrid) {
    WebDriver driver = null;/*from  w ww.  j  a va 2 s. c o  m*/
    logger.info("Test Base Version is" + Configuration.getGrid());
    logger.info("Test Base Browser is" + sbrowser);
    sgrid = Configuration.getGrid();
    if (sgrid.equalsIgnoreCase("")) {
        sbrowser = Configuration.getAutomationBrowser();
        return driver = initializeDriver(sbrowser);
    } else if (!sgrid.equalsIgnoreCase("") && !sbrowser.equalsIgnoreCase("")) {
        logger.info("I am in Grid Intialization");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        URL hubUrl = null;
        try {
            hubUrl = new URL("http://localhost:4444/wb/hub");
            if (sbrowser.equalsIgnoreCase("firefox")) {
                FirefoxProfile profile = new FirefoxProfile();
                profile.setPreference("browser.download.folderList", 2);
                capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
                capabilities.setPlatform(Platform.WINDOWS);
                driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
                //remoteWebDriver.setFileDetector(new LocalFileDetector());
            }
            if (sbrowser.equalsIgnoreCase("chrome")) {
                System.setProperty("webdriver.chrome.driver", getFilePath(CHROMEPATH));
                capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
                //capabilities.setVersion(sversion1);
                capabilities.setPlatform(Platform.WINDOWS);
                driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    return driver;

}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method build a RemoteWebDriver based on the passed in browser request
 *
 * @param browser//from   w w w  .ja v  a 2 s.c  o  m
 * @return RemoteWebDriver
 *
 */
private static RemoteWebDriver buildRemoteWebDriver(String browserName) {
    DesiredCapabilities capability = null;
    BrowserType browserType = BrowserType.getBrowserTypeFromString(browserName);
    switch (browserType) {
    case MARIONETTE:
        FirefoxProfile ffProfile = null;
        ffProfile = new FirefoxProfile();
        ffProfile.setAcceptUntrustedCertificates(true);
        ffProfile.setAssumeUntrustedCertificateIssuer(false);
        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setCapability("marionette", true);
        cap.setCapability("firefox_profile", ffProfile);
        cap.setCapability("handlesAlerts", true);
        sysEnv = System.getenv("webdriver.firefox.marionette");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "geckodriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.firefox.marionette in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.firefox.marionette", sysEnv);
            }
        }
        return new MarionetteDriver(capability);
    case FIREFOX_DRIVER:
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new FirefoxDriver(capability);
    case CHROME_DRIVER:
        sysEnv = System.getenv("webdriver.chrome.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "chromedriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.chrome.driver in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.chrome.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.addArguments(new String[] { "--allow-running-insecure-content" });
        options.addArguments(new String[] { "--ignore-certificate-errors" });
        options.addArguments(new String[] { "--enable-npapi" });
        options.addArguments(new String[] { "--disable-extensions" });
        options.addArguments(new String[] { "--start-maximized" });
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability(ChromeOptions.CAPABILITY, options);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new ChromeDriver(capability);
    case INTERNET_EXPLORER:
        sysEnv = System.getenv("webdriver.ie.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "IEDriverServer.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.ie.driver in system environment variables and restart the PC");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.ie.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.internetExplorer();
        capability.setCapability("ignoreProtectedModeSettings", true);
        String browserVersion = capability.getVersion();
        if (browserVersion != null && browserVersion.equals("10")) {
            capability.setPlatform(Platform.WINDOWS);
            capability.setVersion(browserVersion);
        } else if (browserVersion != null && browserVersion.equals("11")) {
            capability.setPlatform(Platform.WIN8_1);
            capability.setVersion(browserVersion);
        }
        capability.setBrowserName("internet explorer");
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        return new InternetExplorerDriver(capability);
    case SAFARI:
        capability = DesiredCapabilities.safari();
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability("ensureCleanSession", true);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(null);
        return new SafariDriver(capability);
    /*         case OPERA_DRIVER:
    capability = DesiredCapabilities.opera();
    capability.setCapability("opera.profile", "/test");
    return new OperaDriver();
    */
    case EDGE:
        capability = DesiredCapabilities.edge();
        EdgeOptions option = new EdgeOptions();
        capability.setCapability("edgeOptions", option);
        return new EdgeDriver(capability);
    default:
        log.info(
                "Currenty support is there for Chrome, Firefox, Firefox Marionette, Internet Explorer, Edge, Safari & Opera. Support is not there for "
                        + browserName);
        capability = DesiredCapabilities.firefox();
        firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new FirefoxDriver(capability);
    }
}

From source file:com.elastica.browserfactory.ChromeCapabilitiesFactory.java

License:Apache License

public DesiredCapabilities createCapabilities(final DriverConfig webDriverConfig) {

    DesiredCapabilities capability = null;
    capability = DesiredCapabilities.chrome();
    capability.setBrowserName(DesiredCapabilities.chrome().getBrowserName());

    ChromeOptions options = new ChromeOptions();
    if (webDriverConfig.getUserAgentOverride() != null) {
        options.addArguments("--user-agent=" + webDriverConfig.getUserAgentOverride());
    }//w ww  . ja v a  2 s .com

    capability.setCapability(ChromeOptions.CAPABILITY, options);

    if (webDriverConfig.isEnableJavascript()) {
        capability.setJavascriptEnabled(true);
    } else {
        capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    if (webDriverConfig.getBrowserVersion() != null) {
        capability.setVersion(webDriverConfig.getBrowserVersion());
    }

    if (webDriverConfig.getPlatform() != null) {
        capability.setPlatform(webDriverConfig.getPlatform());
    }

    if (webDriverConfig.getProxyHost() != null) {
        Proxy proxy = webDriverConfig.getProxy();
        capability.setCapability(CapabilityType.PROXY, proxy);
    }

    if (webDriverConfig.getChromeBinPath() != null) {
        capability.setCapability("chrome.binary", webDriverConfig.getChromeBinPath());
    }

    // Set ChromeDriver for local mode
    if (webDriverConfig.getMode() == DriverMode.LOCAL) {
        String chromeDriverPath = webDriverConfig.getChromeDriverPath();
        if (chromeDriverPath == null) {
            try {
                if (System.getenv("webdriver.chrome.driver") != null) {
                    System.out.println(
                            "get Chrome driver from property:" + System.getenv("webdriver.chrome.driver"));
                    System.setProperty("webdriver.chrome.driver", System.getenv("webdriver.chrome.driver"));
                } else {
                    handleExtractResources();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } else {
            System.setProperty("webdriver.chrome.driver", chromeDriverPath);
        }
    }

    return capability;
}

From source file:com.elastica.browserfactory.FirefoxCapabilitiesFactory.java

License:Apache License

/**
 * Create firefox capabilities.//from  w w w  .  j  a v a  2s.  c  om
 */
public DesiredCapabilities createCapabilities(final DriverConfig webDriverConfig) {
    DesiredCapabilities capability;
    capability = new DesiredCapabilities();
    capability.setBrowserName(DesiredCapabilities.firefox().getBrowserName());

    FirefoxProfile profile = getFirefoxProfile(webDriverConfig);
    configProfile(profile, webDriverConfig);
    capability.setCapability(FirefoxDriver.PROFILE, profile);

    if (webDriverConfig.isEnableJavascript()) {
        capability.setJavascriptEnabled(true);
    } else {
        capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    if (webDriverConfig.getBrowserVersion() != null) {
        capability.setVersion(webDriverConfig.getBrowserVersion());
    }

    if (webDriverConfig.getPlatform() != null) {
        capability.setPlatform(webDriverConfig.getPlatform());
    }

    if (webDriverConfig.getProxyHost() != null) {
        capability.setCapability(CapabilityType.PROXY, webDriverConfig.getProxy());
    }

    return capability;
}

From source file:com.elastica.browserfactory.IECapabilitiesFactory.java

License:Apache License

public DesiredCapabilities createCapabilities(final DriverConfig cfg) {

    // Set IEDriver for Local Mode
    if (cfg.getMode() == DriverMode.LOCAL) {
        if (cfg.getIeDriverPath() != null) {
            System.setProperty("webdriver.ie.driver", cfg.getIeDriverPath());
        } else {//from w  w  w  .  java2s.  c  o m
            if (System.getenv("webdriver.ie.driver") != null) {
                System.out.println("Get IE Driver from property:" + System.getenv("webdriver.ie.driver"));
                System.setProperty("webdriver.ie.driver", System.getenv("webdriver.ie.driver"));
            } else {
                try {
                    handleExtractResources();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    DesiredCapabilities capability = DesiredCapabilities.internetExplorer();

    capability.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());

    if (cfg.isEnableJavascript()) {
        capability.setJavascriptEnabled(true);
    } else {
        capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capability.setCapability("ignoreZoomSetting", true);

    if (cfg.getBrowserVersion() != null) {
        capability.setVersion(cfg.getBrowserVersion());
    }

    if (cfg.getPlatform() != null) {
        capability.setPlatform(cfg.getPlatform());
    }

    if (cfg.getProxyHost() != null) {
        Proxy proxy = cfg.getProxy();
        capability.setCapability(CapabilityType.PROXY, proxy);
    }

    capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    return capability;
}

From source file:com.elastica.browserfactory.OperaCapabilitiesFactory.java

License:Apache License

public DesiredCapabilities createCapabilities(final DriverConfig cfg) {
    DesiredCapabilities capability = DesiredCapabilities.opera();

    capability.setBrowserName(DesiredCapabilities.opera().getBrowserName());

    if (cfg.isEnableJavascript()) {
        capability.setJavascriptEnabled(true);
    } else {/*from   w  w w  .  j  a  v  a2s .  co  m*/
        capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    if (cfg.getBrowserVersion() != null) {
        capability.setVersion(cfg.getBrowserVersion());
    }

    if (cfg.getPlatform() != null) {
        capability.setPlatform(cfg.getPlatform());
    }

    OperaProfile profile = getOperaProfile(cfg);
    capability.setCapability("opera.profile", profile);

    if (cfg.getProxyHost() != null) {
        Proxy proxy = cfg.getProxy();
        capability.setCapability(CapabilityType.PROXY, proxy);
    }

    return capability;
}

From source file:com.elastica.browserfactory.PhantomJSCapabilitiesFactory.java

License:Apache License

public DesiredCapabilities createCapabilities(final DriverConfig cfg) {
    DesiredCapabilities capability = new DesiredCapabilities();
    capability.setBrowserName(DesiredCapabilities.phantomjs().getBrowserName());

    if (cfg.isEnableJavascript()) {
        capability.setJavascriptEnabled(true);
    } else {/*from w  w  w .  jav a 2s.c om*/
        capability.setJavascriptEnabled(false);
    }

    capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    if (cfg.getBrowserVersion() != null) {
        capability.setVersion(cfg.getBrowserVersion());
    }

    if (cfg.getPlatform() != null) {
        capability.setPlatform(cfg.getPlatform());
    }

    if (cfg.getProxyHost() != null) {
        Proxy proxy = cfg.getProxy();
        capability.setCapability(CapabilityType.PROXY, proxy);
    }

    return capability;
}

From source file:com.epam.gepard.selenium.browsers.WebDriverUtil.java

License:Open Source License

private DesiredCapabilities detectCapabilities() {
    DesiredCapabilities capabilities = null;
    try {//  w w  w .  j  a  v  a 2  s.  c  o m
        if (browserString.compareTo(environmentHelper.getProperty(SELENIUM_BROWSER_GOOGLE_CHROME)) == 0) {
            capabilities = DesiredCapabilities.chrome();
            capabilities.setBrowserName("chrome");
        }
        if (browserString.compareTo(environmentHelper.getProperty(SELENIUM_BROWSER_FIREFOX)) == 0) {
            capabilities = DesiredCapabilities.firefox();
            capabilities.setBrowserName("firefox");
            capabilities.setVersion("ANY");
        }
        if (browserString.compareTo(environmentHelper.getProperty(SELENIUM_BROWSER_INTERNET_EXPLORER)) == 0) {
            capabilities = DesiredCapabilities.internetExplorer();
            capabilities.setBrowserName("internetExplorer");
        }
        if (browserString.compareTo(environmentHelper.getProperty(SELENIUM_BROWSER_SAFARI)) == 0) {
            capabilities = DesiredCapabilities.safari();
            capabilities.setBrowserName("safari");
        }
        if (capabilities == null) {
            throw new SimpleGepardException("Specified browser:'" + browserString + "' is not supported.");
        }
    } catch (NullPointerException e) {
        throw new SimpleGepardException("Gepard property values for Selenium Browsers are not available.");
    }
    return capabilities;
}

From source file:com.epam.jdi.uitests.mobile.appium.driver.SauceLabRunner.java

License:Open Source License

public static DesiredCapabilities getSauceDesiredCapabilities(DriverTypes driverType) {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName(getenv("SELENIUM_BROWSER"));
    capabilities.setVersion(getenv("SELENIUM_VERSION"));
    capabilities.setCapability(PLATFORM, getenv("SELENIUM_PLATFORM"));
    return capabilities;
}