Java Code Examples for org.openqa.selenium.remote.DesiredCapabilities#internetExplorer()

The following examples show how to use org.openqa.selenium.remote.DesiredCapabilities#internetExplorer() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static DesiredCapabilities build(RemoteCapability capability){
 DesiredCapabilities desiredCapabilities;
 if(RemoteCapability.CHROME.equals(capability)){
  ChromeOptions options = new ChromeOptions();
     desiredCapabilities = DesiredCapabilities.chrome();
     desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
  return desiredCapabilities;
 } else if (RemoteCapability.FIREFOX.equals(capability)){
  FirefoxProfile profile = new FirefoxProfile();
  desiredCapabilities = DesiredCapabilities.firefox();
  desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile);
  return desiredCapabilities;
 } else if (RemoteCapability.INTERNET_EXPLORER.equals(capability)){
  desiredCapabilities = DesiredCapabilities.internetExplorer();
  return desiredCapabilities;
 } else if (RemoteCapability.PHANTOMJS.equals(capability)){
  desiredCapabilities = DesiredCapabilities.phantomjs();
  return desiredCapabilities;
 }
 throw new IllegalArgumentException("No such capability");
}
 
Example 2
Source Project: SWET   File: BrowserDriver.java    License: MIT License 6 votes vote down vote up
private static DesiredCapabilities capabilitiesInternetExplorer() {

		DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
		final String ieDriverPath = (applicationIeDriverPath == null)
				? "c:/java/selenium/IEDriverServer.exe" : applicationIeDriverPath;
		System.setProperty("webdriver.ie.driver", ieDriverPath
		/* (new File(ieDriverPath)).getAbsolutePath() */);
		capabilities.setCapability(
				InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
				true);
		capabilities.setCapability("ignoreZoomSetting", true);
		capabilities.setCapability("ignoreProtectedModeSettings", true);
		capabilities.setCapability("requireWindowFocus", true);
		capabilities.setBrowserName(
				DesiredCapabilities.internetExplorer().getBrowserName());
		return capabilities;
	}
 
Example 3
@Override
public void start() throws CandybeanException {
	DesiredCapabilities capabilities = new DesiredCapabilities();
	String ieDriverPath = candybean.config.getPathValue("browser.ie.driver.path");
	if(StringUtils.isEmpty(ieDriverPath) || !new File(ieDriverPath).exists()){
		String error = "Unable to find internet explorer driver from the specified location("+ieDriverPath+") in the configuration file! \n"
				+ "Please add a configuration to the candybean config file for key \"browser.ie.driver.path\" "
				+ "that indicates the absolute location the driver.";
		logger.severe(error);
		throw new CandybeanException(error);
	}else{
		logger.info("ieDriverPath: " + ieDriverPath);
		System.setProperty("webdriver.ie.driver", ieDriverPath);
		capabilities = DesiredCapabilities.internetExplorer();
		super.wd = new InternetExplorerDriver(capabilities);
        super.start(); // requires wd to be instantiated first
	}
}
 
Example 4
/**
 * ie浏览器
 */
private void ie()
{
	String initialUrl = enginePro.getProperty(DriverConstants.INITIAL_URL,
			"http://surenpi.com");
	
	DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
	capability.setCapability(
			InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
	capability.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, initialUrl);
	capability.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);
	engineCapMap.put(DRIVER_IE, capability);
}
 
Example 5
public static WebDriver get32IEDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\IEDriverServer32.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
Example 6
public static WebDriver get64IEDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\IEDriverServer64.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(CapabilityType.BROWSER_NAME, "IE");
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);

	return new InternetExplorerDriver(caps);
}
 
Example 7
public static WebDriver getEdgeDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\EdgeWebDriver.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
Example 8
public static WebDriver get32IEDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\IEDriverServer32.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
Example 9
public static WebDriver get64IEDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\IEDriverServer64.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(CapabilityType.BROWSER_NAME, "IE");
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);

	return new InternetExplorerDriver(caps);
}
 
Example 10
public static WebDriver getEdgeDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\EdgeWebDriver.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
Example 11
public static WebDriver get32IEDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\IEDriverServer32.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
Example 12
public static WebDriver get64IEDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\IEDriverServer64.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(CapabilityType.BROWSER_NAME, "IE");
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);

	return new InternetExplorerDriver(caps);
}
 
Example 13
public static WebDriver getEdgeDriver()
{
	String path = System.getProperty("user.dir") + "\\Drivers\\EdgeWebDriver.exe";
	System.setProperty("webdriver.ie.driver", path);
	DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
	caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,	true);
	return new InternetExplorerDriver(caps);
}
 
Example 14
Source Project: PatatiumWebUi   File: TestBaseCase.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 用枚举类型列出浏览器列表,用于设置浏览器类型的函数参数
 * @author zheng
 *
 */
private WebDriver setDriver(String browsername)
{
	switch (browsername)
	{

		case "FirefoxDriver" :
			System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
			FirefoxProfile firefoxProfile=new FirefoxProfile();
			//设置默认下载路径
			firefoxProfile.setPreference("browser.download.folderList", 2);
			firefoxProfile.setPreference("browser.download.dir", "D:\\自动化测试下载文件");
			//加载firebug插件
			firefoxProfile.setPreference("extensions.firebug.currentVersion", "2.0.13");
			firefoxProfile.setPreference("extensions.firebug.allPagesActivation", "none");
			//加载firepath插件
			firefoxProfile.setPreference("extensions.firepath.currentVersion", "0.9.7.1.1");
			firefoxProfile.setPreference("extensions.firepath.allPagesActivation", "on");
			this.driver=new FirefoxDriver(firefoxProfile);
			break;
		case "ChormeDriver":
			System.setProperty("webdriver.chrome.driver", "resource\\chromedriver.exe");
			this.driver=new ChromeDriver();
			break;
		case "InternetExplorerDriver":
			System.setProperty("webdriver.ie.driver", "resource\\IEDriverServer_Win32_2.48.0\\IEDriverServer.exe");
			DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
			dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
			dc.setCapability("ignoreProtectedModeSettings", true);
			this.driver=new InternetExplorerDriver(dc);
			break;
		case "HtmlUnitDriver":
			this.driver=new HtmlUnitDriver();
			break;
		default:
			this.driver=new FirefoxDriver();
			break;
	}
	return driver;
}
 
Example 15
public Capabilities getIExplorerCapabilities() {
	DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
	cap.setCapability(InternetExplorerDriver.ELEMENT_SCROLL_BEHAVIOR,
			ElementScrollBehavior.BOTTOM);
	cap.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
	cap.setCapability(
			InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
			true);
	cap.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
	cap.setJavascriptEnabled(true);
	return cap;
}
 
Example 16
@BeforeMethod
public void setUpProxy() throws Exception {
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(CapabilityType.PROXY, getProxy());
    //or
    //capabilities.setCapability(CapabilityType.PROXY, server.seleniumProxy());
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
}
 
Example 17
/**
 * setDriver method to create driver instance
 *
 * @param browser
 * @param environment
 * @param platform
 * @param optPreferences
 * @throws Exception
 */
@SafeVarargs
public final void setDriver(String browser,
                            String platform,
                            String environment,
                            Map<String, Object>... optPreferences)
                            throws Exception {

    DesiredCapabilities caps = null;
    String getPlatform = null;
    props.load(new FileInputStream(Global_VARS.SE_PROPS));

    switch (browser) {
        case "firefox":
            caps = DesiredCapabilities.firefox();

            FirefoxOptions ffOpts = new FirefoxOptions();
            FirefoxProfile ffProfile = new FirefoxProfile();

            ffProfile.setPreference("browser.autofocus", true);
            ffProfile.setPreference("browser.tabs.remote.autostart.2", false);

            caps.setCapability(FirefoxDriver.PROFILE, ffProfile);
            caps.setCapability("marionette", true);

            // then pass them to the local WebDriver
            if ( environment.equalsIgnoreCase("local") ) {
                System.setProperty("webdriver.gecko.driver", props.getProperty("gecko.driver.windows.path"));
                webDriver.set(new FirefoxDriver(ffOpts.merge(caps)));
            }

            break;
        case "chrome":
            caps = DesiredCapabilities.chrome();

            ChromeOptions chOptions = new ChromeOptions();
            Map<String, Object> chromePrefs = new HashMap<String, Object>();

            chromePrefs.put("credentials_enable_service", false);

            chOptions.setExperimentalOption("prefs", chromePrefs);
            chOptions.addArguments("--disable-plugins", "--disable-extensions", "--disable-popup-blocking");

            caps.setCapability(ChromeOptions.CAPABILITY, chOptions);
            caps.setCapability("applicationCacheEnabled", false);

            if ( environment.equalsIgnoreCase("local") ) {
                System.setProperty("webdriver.chrome.driver", props.getProperty("chrome.driver.windows.path"));
                webDriver.set(new ChromeDriver(chOptions.merge(caps)));
            }

            break;
        case "internet explorer":
            caps = DesiredCapabilities.internetExplorer();

            InternetExplorerOptions ieOpts = new InternetExplorerOptions();

            ieOpts.requireWindowFocus();
            ieOpts.merge(caps);

            caps.setCapability("requireWindowFocus", true);

            if ( environment.equalsIgnoreCase("local") ) {
                System.setProperty("webdriver.ie.driver", props.getProperty("ie.driver.windows.path"));
                webDriver.set(new InternetExplorerDriver(ieOpts.merge(caps)));
            }

            break;
    }

    getEnv = environment;
    getPlatform = platform;
    sessionId.set(((RemoteWebDriver) webDriver.get()).getSessionId().toString());
    sessionBrowser.set(caps.getBrowserName());
    sessionVersion.set(caps.getVersion());
    sessionPlatform.set(getPlatform);

    System.out.println("\n*** TEST ENVIRONMENT = "
            + getSessionBrowser().toUpperCase()
            + "/" + getSessionPlatform().toUpperCase()
            + "/" + getEnv.toUpperCase()
            + "/Selenium Version=" + props.getProperty("selenium.revision")
            + "/Session ID=" + getSessionId() + "\n");

    getDriver().manage().timeouts().implicitlyWait(IMPLICIT_TIMEOUT, TimeUnit.SECONDS);
    getDriver().manage().window().maximize();
}
 
Example 18
Source Project: marathonv5   File: IEWebDriverProxyTest.java    License: Apache License 2.0 4 votes vote down vote up
public IEWebDriverProxyTest() {
    super(IEWebDriverProxy.class, DesiredCapabilities.internetExplorer());
}
 
Example 19
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 {
                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.getWebPlatform() != null) {
            capability.setPlatform(cfg.getWebPlatform());
        }

        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;
    }
 
Example 20
/**
 * <p>
 * Saucelabs setUp.
 * </p><p>
 * Creates a {@link org.openqa.selenium.remote.RemoteWebDriver} instance with the DesiredCapabilities as configured
 * using the JVM arguments described as SAUCE_ Constants in this class.  After setUp the WebDriver can be accessed via
 * {@see #getDriver}.  You'll also need {@see #getSessionId} for when you call {@see #tearDown}
 * </p>
 *
 * @param className class name of the test being setup as a String
 * @param testName test name of the test being setup as a String
 * @throws Exception
 */
public void setUp(String className, String testName) throws Exception {
    if (System.getProperty(REMOTE_DRIVER_SAUCELABS_PROPERTY) == null) { // dup guard so WebDriverUtils doesn't have to be used.
        return;
    }

    if (System.getProperty(SAUCE_USER_PROPERTY) == null || System.getProperty(SAUCE_KEY_PROPERTY) == null) {
        Assert.fail("-D" + SAUCE_USER_PROPERTY + " and -D" + SAUCE_KEY_PROPERTY + " must be set to saucelabs user and access key.");
    }

    DesiredCapabilities capabilities = null;
    if ("ff".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
        capabilities = DesiredCapabilities.firefox();
    } else if ("ie".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
            System.getProperty(SAUCE_IE_INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS_PROPERTY, "true"));
    } else if ("chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.chrome();
    } else if ("opera".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.opera();
    } else if ("android".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.android();
    } else if ("safari".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.safari();
    } else if ("ipad".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.ipad();
    } else if ("iphone".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY)))  {
        capabilities = DesiredCapabilities.iphone();
    } else {
        capabilities = DesiredCapabilities.firefox();
    }

    String version = System.getProperty(SAUCE_VERSION_PROPERTY);
    if (version == null || "0".equals(version)) { // Blank or 0 leaves version blank for use with chrome

        if (!"chrome".equalsIgnoreCase(System.getProperty(SAUCE_BROWSER_PROPERTY))) {
            throw new RuntimeException("Blank or 0 version for a browser not chrome " + System.getProperty(SAUCE_BROWSER_PROPERTY));
        }

        capabilities.setCapability("version", ""); // saucelabs requires blank for chrome (latest version)
    } else {
        capabilities.setCapability("version", version); // saucelabs requires blank for chrome (latest version)
    }

    capabilities.setCapability("platform", System.getProperty(SAUCE_PLATFORM_PROPERTY, Platform.UNIX.toString()).replaceAll("_", " "));
    capabilities.setCapability("idle-timeout", Integer.parseInt(System.getProperty(SAUCE_IDLE_TIMEOUT_SECONDS_PROPERTY, "180")));
    capabilities.setCapability("max-duration", Integer.parseInt(System.getProperty(SAUCE_MAX_DURATION_SECONDS_PROPERTY, "600")));
    capabilities.setCapability("name",  className + "." + testName + "-" + AutomatedFunctionalTestUtils.DTS);
    capabilities.setCapability("disable-popup-handler", System.getProperty(SAUCE_POPUP_PROPERTY, "false"));
    capabilities.setCapability("public", System.getProperty(SAUCE_SHARE_PROPERTY, "public restricted"));

    System.out.println("Requesting Saucelabs RemoteWebDriver with DesiredCapabilities of " + capabilities.toString());

    this.driver = new RemoteWebDriver(
            new URL("http://" + authentication.getUsername() + ":" + authentication.getAccessKey() + "@ondemand.saucelabs.com:80/wd/hub"),
            capabilities);
    this.sessionId = ((RemoteWebDriver)driver).getSessionId().toString();

    System.out.println("SauceLabs job can be viewed at https://saucelabs.com/jobs/" + this.sessionId);
}