Java Code Examples for org.openqa.selenium.ie.InternetExplorerDriver

The following examples show how to use org.openqa.selenium.ie.InternetExplorerDriver. 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
Source Project: shadow-automation-selenium   Source File: Shadow.java    License: Apache License 2.0 6 votes vote down vote up
public Shadow(WebDriver driver) {
	
	if (driver instanceof ChromeDriver) {
		sessionId  = ((ChromeDriver)driver).getSessionId();
		chromeDriver = (ChromeDriver)driver;
	} else if (driver instanceof FirefoxDriver) {
		sessionId  = ((FirefoxDriver)driver).getSessionId();
		firfoxDriver = (FirefoxDriver)driver;
	} else if (driver instanceof InternetExplorerDriver) {
		sessionId  = ((InternetExplorerDriver)driver).getSessionId();
		ieDriver = (InternetExplorerDriver)driver;
	} else if (driver instanceof RemoteWebDriver) {
		sessionId  = ((RemoteWebDriver)driver).getSessionId();
		remoteWebDriver = (RemoteWebDriver)driver;
	} 
	this.driver = driver;
}
 
Example 2
Source Project: vividus   Source File: WebDriverFactoryTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testGetRemoteWebDriverIEDriver() throws Exception
{
    mockCapabilities(remoteWebDriver);
    setRemoteDriverUrl();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setBrowserName(BrowserType.IEXPLORE);
    when(remoteWebDriverFactory.getRemoteWebDriver(any(URL.class), any(DesiredCapabilities.class)))
            .thenReturn(remoteWebDriver);
    Timeouts timeouts = mockTimeouts(remoteWebDriver);
    desiredCapabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
    assertEquals(remoteWebDriver,
            ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver());
    verify(timeoutConfigurer).configure(timeouts);
    assertLogger();
}
 
Example 3
Source Project: vividus   Source File: WebDriverTypeTests.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static DesiredCapabilities testGetIExploreWebDriver(WebDriverConfiguration configuration) throws Exception
{
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
    whenNew(InternetExplorerOptions.class).withArguments(desiredCapabilities).thenReturn(internetExplorerOptions);
    whenNew(InternetExplorerOptions.class).withNoArguments().thenReturn(internetExplorerOptions);
    InternetExplorerDriver expected = mock(InternetExplorerDriver.class);
    whenNew(InternetExplorerDriver.class)
            .withParameterTypes(InternetExplorerOptions.class)
            .withArguments(internetExplorerOptions)
            .thenReturn(expected);
    WebDriver actual = WebDriverType.IEXPLORE.getWebDriver(desiredCapabilities, configuration);
    assertEquals(expected, actual);
    Map<String, Object> options = (Map<String, Object>) desiredCapabilities.getCapability(IE_OPTIONS);
    assertTrue((boolean) options.get(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS));
    return desiredCapabilities;
}
 
Example 4
Source Project: coteafs-selenium   Source File: Browser.java    License: Apache License 2.0 6 votes vote down vote up
private static WebDriver setupIeDriver() throws MalformedURLException {
    LOG.i("Setting up Internet Explorer driver...");
    setupDriver(iedriver());
    final InternetExplorerOptions ieOptions = new InternetExplorerOptions();
    ieOptions.destructivelyEnsureCleanSession();
    ieOptions.setCapability("requireWindowFocus", true);
    ieOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    final InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService();
    if (!OS.isWindows()) {
        Assert.fail("IE is not supported.");
    }
    if (appSetting().isHeadlessMode()) {
        LOG.w("IE does not support headless mode. Hence, ignoring the same...");
    }
    return new InternetExplorerDriver(ieService, ieOptions);
}
 
Example 5
Source Project: htmlunit   Source File: HtmlFileInputTest.java    License: Apache License 2.0 6 votes vote down vote up
private void contentType(final String extension) throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/upload1", Upload1Servlet.class);
    servlets.put("/upload2", ContentTypeUpload2Servlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get(URL_FIRST + "upload1");

    final File tmpFile = File.createTempFile("htmlunit-test", "." + extension);
    try {
        String path = tmpFile.getAbsolutePath();
        if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
            path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
        }
        driver.findElement(By.name("myInput")).sendKeys(path);
        driver.findElement(By.id("mySubmit")).click();
    }
    finally {
        assertTrue(tmpFile.delete());
    }

    final String pageSource = driver.getPageSource();
    assertTrue(pageSource, pageSource.contains(getExpectedAlerts()[0]));
    assertFalse(pageSource, pageSource.contains(getExpectedAlerts()[1]));
}
 
Example 6
@Test
public void shouldCreateInternetExplorerAndStartService() throws Exception {
    InternetExplorerDriver mockInternetExplorerDriver = mock(InternetExplorerDriver.class);
    whenNew(InternetExplorerDriver.class).withParameterTypes(InternetExplorerDriverService.class, Capabilities.class).withArguments(isA(InternetExplorerDriverService.class), isA(Capabilities.class)).thenReturn(mockInternetExplorerDriver);
    InternetExplorerDriverService.Builder mockServiceBuilder = mock(InternetExplorerDriverService.Builder.class);
    whenNew(InternetExplorerDriverService.Builder.class).withNoArguments().thenReturn(mockServiceBuilder);
    when(mockServiceBuilder.usingDriverExecutable(isA(File.class))).thenReturn(mockServiceBuilder);
    InternetExplorerDriverService mockService = mock(InternetExplorerDriverService.class);
    when(mockServiceBuilder.build()).thenReturn(mockService);

    final InternetExplorerDriver browser = config.createBrowser();

    assertThat(browser, is(mockInternetExplorerDriver));
    verifyNew(InternetExplorerDriver.class, times(1)).withArguments(isA(InternetExplorerDriverService.class), isA(Capabilities.class));
    verify(mockServiceBuilder, times(1)).build();
    assertThat(config.getServices().size(), is(1));
    assertThat(config.getServices().values(), hasItem(mockService));
}
 
Example 7
Source Project: teasy   Source File: IECaps.java    License: MIT License 6 votes vote down vote up
private InternetExplorerOptions getIEOptions() {
    InternetExplorerOptions caps = new InternetExplorerOptions();
    caps.setCapability("version", this.version);
    caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    caps.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
    caps.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
    caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
    caps.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
    caps.setCapability("platform", Platform.WINDOWS);
    caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    caps.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, this.alertBehaviour);

    //Found that setting this capability could increase IE tests speed. Should be checked.
    caps.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
    setLoggingPrefs(caps);
    return caps;
}
 
Example 8
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        InternetExplorerOptions internetExplorerOptions = (InternetExplorerOptions) getOptions(
                parameter, testInstance);
        if (capabilities.isPresent()) {
            internetExplorerOptions.merge(capabilities.get());
        }
        object = new InternetExplorerDriver(internetExplorerOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example 9
Source Project: java-maven-selenium   Source File: DriverFactory.java    License: MIT License 6 votes vote down vote up
static WebDriver getDriver() {

        String browser = System.getenv("BROWSER");
        if (browser == null) {
            WebDriverManager.chromedriver().setup();
            return new ChromeDriver();
        }
        switch (browser)
        {
            case "IE":
                WebDriverManager.iedriver().setup();
                return new InternetExplorerDriver();
            case "EDGE":
                WebDriverManager.edgedriver().setup();
                return new EdgeDriver();
            case "FIREFOX":
                WebDriverManager.firefoxdriver().setup();
                return new FirefoxDriver();
            default:
                WebDriverManager.chromedriver().setup();
                return new ChromeDriver();

        }
    }
 
Example 10
Source Project: SWET   Source 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 11
Source Project: seleniumtestsframework   Source File: IEDriverFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public WebDriver createWebDriver() throws IOException {

    // killProcess();
    if (!OSUtility.isWindows()) {
        throw new RuntimeException("With gods grace IE browser is only supported on windows, Imagine a "
                + "situation when you have to fix IE bugs on Unix and Mac as well");
    }

    DriverConfig cfg = this.getWebDriverConfig();

    driver = new InternetExplorerDriver(new IECapabilitiesFactory().createCapabilities(cfg));

    // Implicit Waits to handle dynamic element. The default value is 5 seconds.
    setImplicitWaitTimeout(cfg.getImplicitWaitTimeout());
    if (cfg.getPageLoadTimeout() >= 0) {
        driver.manage().timeouts().pageLoadTimeout(cfg.getPageLoadTimeout(), TimeUnit.SECONDS);
    }

    this.setWebDriver(driver);
    return driver;
}
 
Example 12
@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 13
Source Project: at.info-knowledge-base   Source File: upload_file.java    License: MIT License 6 votes vote down vote up
static public void main(String[] args) {
	// Creating webdriver
	System.setProperty("webdriver.ie.driver", "C:\\WORK\\IEDriverServer_Win32_2.37.0\\IEDriverServer.exe");
	WebDriver driver = new InternetExplorerDriver();

// Opening page. In this case - local HTML file.
   	driver.get("file://C:/WORK/test.html");

   	// Find element that uploads file.
   	WebElement fileInput = driver.findElement(By.id("file"));

   	// Set direct path to local file that needs to be uploaded. 
   	// That also can be a direct link to file in web, like - https://www.google.com.ua/images/srpr/logo11w.png
   	fileInput.sendKeys("file://C:/WORK/lenna.png");

   	// find button that sends form and click it.
   	driver.findElement(By.id("submit")).click();

   	// Closing driver and session
   	driver.quit();
}
 
Example 14
Source Project: keycloak   Source File: LocaleDropdown.java    License: Apache License 2.0 6 votes vote down vote up
public void selectByText(String text) {
    // open the menu
    if (driver instanceof IOSDriver) { // TODO: Fix this! It's a very, very, ... very nasty hack for Safari on iOS - see KEYCLOAK-7947
        ((IOSDriver) driver).executeScript("arguments[0].setAttribute('style', 'display: block')", dropDownMenu);
    }
    else if (driver instanceof AndroidDriver || driver instanceof InternetExplorerDriver) { // Android needs to tap (no cursor)
                                                                                            // and IE has some bug so needs to click as well (instead of moving cursor)
        currentLocaleLink.click();
    }
    else {
        Actions actions = new Actions(driver);
        log.info("Moving mouse cursor to the localization menu");
        actions.moveToElement(currentLocaleLink).perform();
    }

    // click desired locale
    clickLink(dropDownMenu.findElement(By.xpath("./li/a[text()='" + text + "']")));
}
 
Example 15
Source Project: keycloak   Source File: URLUtils.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static boolean urlCheck(ExpectedCondition condition, boolean secondTry) {
    WebDriver driver = getCurrentDriver();

    try {
        (new WebDriverWait(driver, 5, 100)).until(condition);
    }
    catch (TimeoutException e) {
        if (driver instanceof InternetExplorerDriver && !secondTry) {
            // IE WebDriver has sometimes invalid current URL
            log.info("IE workaround: checking URL failed at first attempt - refreshing the page and trying one more time...");
            driver.navigate().refresh();
            urlCheck(condition, true);
        }
        else {
            return false;
        }
    }
    return true;
}
 
Example 16
Source Project: keycloak   Source File: PatternFlyClosableAlert.java    License: Apache License 2.0 6 votes vote down vote up
public void close() {
    try {
        closeButton.click();
        WaitUtils.pause(500); // Sometimes, when a test is too fast,
                                    // one of the consecutive alerts is not displayed;
                                    // to prevent this we need to slow down a bit
    }
    catch (WebDriverException e) {
        if (driver instanceof InternetExplorerDriver) {
            log.warn("Failed to close the alert; test is probably too slow and alert has already closed itself");
        }
        else {
            throw e;
        }
    }
}
 
Example 17
Source Project: vividus   Source File: WebDriverTypeTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@PrepareForTest(fullyQualifiedNames = "org.vividus.selenium.WebDriverType$2")
@SuppressWarnings("unchecked")
public void testGetIExploreWebDriverWithCommandLineArguments() throws Exception
{
    String argument = "private";
    WebDriverConfiguration configuration = new WebDriverConfiguration();
    configuration.setCommandLineArguments(new String[] { argument });
    DesiredCapabilities desiredCapabilities = testGetIExploreWebDriver(configuration);
    Map<String, Object> options = (Map<String, Object>) desiredCapabilities.getCapability(IE_OPTIONS);
    assertEquals(argument, options.get(InternetExplorerDriver.IE_SWITCHES));
}
 
Example 18
@Override
public Browser getBrowser() {
    BrowserName browserName = browserProfile.getBrowserName();
    RemoteWebDriver driver;
    IDriverSettings driverSettings = browserProfile.getDriverSettings();
    String webDriverVersion = driverSettings.getWebDriverVersion();
    Architecture systemArchitecture = driverSettings.getSystemArchitecture();
    switch (browserName) {
        case CHROME:
            WebDriverManager.chromedriver().version(webDriverVersion).setup();
            driver = getDriver(ChromeDriver.class, driverSettings.getCapabilities());
            break;
        case FIREFOX:
            WebDriverManager.firefoxdriver().version(webDriverVersion).setup();
            driver = getDriver(FirefoxDriver.class, driverSettings.getCapabilities());
            break;
        case IEXPLORER:
            WebDriverManager.iedriver().architecture(systemArchitecture).version(webDriverVersion).setup();
            driver = getDriver(InternetExplorerDriver.class, driverSettings.getCapabilities());
            break;
        case EDGE:
            WebDriverManager.edgedriver().version(webDriverVersion).setup();
            driver = getDriver(EdgeDriver.class, driverSettings.getCapabilities());
            break;
        case SAFARI:
            driver = getDriver(SafariDriver.class, driverSettings.getCapabilities());
            break;
        default:
            throw getLoggedWrongBrowserNameException();
    }
    logBrowserIsReady(browserName);

    return new Browser(driver);
}
 
Example 19
/**
 * ��ʼ��WebDriver
 * @return ���س�ʼ�����
 * @throws IOException ��ȡ�����ļ��쳣
 */
public static WebDriver setWebDriverForLocal() throws IOException{
	File directory = new File("");
	String drivenpath=directory.getCanonicalPath()+File.separator+"BrowserDriven"+File.separator;
	System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
	WebDriver webDriver = new InternetExplorerDriver();
	webDriver.manage().window().maximize();
	//����ҳ��������ʱ��30��
	webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
	//����Ԫ�س������ʱ��30��  
	webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);  
       return webDriver;
}
 
Example 20
Source Project: htmlunit   Source File: HTMLFormElementTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Ensure that text/plain form parameters are correctly encoded.
 * @throws Exception if the test fails
 */
@Test
@Alerts({"application/x-www-form-urlencoded", "myFile=htmlunit-test", ".txt"})
public void submitUrlEncodedFile() throws Exception {
    final String html = "<html>\n"
            + "<body>\n"
            + "  <form action='foo.html' enctype='application/x-www-form-urlencoded' method='post'>\n"
            + "    <input type='file' id='f' name='myFile'>\n"
            + "    <input id='clickMe' type='submit' value='Click Me'>\n"
            + "  </form>\n"
            + "</body>\n"
            + "</html>";

    getMockWebConnection().setDefaultResponse("");

    final WebDriver driver = loadPage2(html);

    final File tmpFile = File.createTempFile("htmlunit-test", ".txt");
    try {
        String path = tmpFile.getAbsolutePath();
        if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
            path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
        }
        driver.findElement(By.id("f")).sendKeys(path);
        driver.findElement(By.id("clickMe")).click();
    }
    finally {
        assertTrue(tmpFile.delete());
    }

    final String headerContentType = getMockWebConnection().getLastWebRequest().getAdditionalHeaders()
            .get(HttpHeader.CONTENT_TYPE);
    assertEquals(getExpectedAlerts()[0], headerContentType);

    final String body = getMockWebConnection().getLastWebRequest()
            .getRequestParameters().get(0).toString();
    assertTrue(body, body.startsWith(getExpectedAlerts()[1]));
    assertTrue(body, body.endsWith(getExpectedAlerts()[2]));
    assertNull(getMockWebConnection().getLastWebRequest().getRequestBody());
}
 
Example 21
Source Project: htmlunit   Source File: HTMLFormElementTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Ensure that text/plain form parameters are correctly encoded.
 * @throws Exception if the test fails
 */
@Test
@Alerts({"text/plain", "myFile=htmlunit-test", ".txt\r\n"})
public void submitPlainTextFile() throws Exception {
    final String html = "<html>\n"
            + "<body>\n"
            + "  <form action='foo.html' enctype='text/plain' method='post'>\n"
            + "    <input type='file' id='f' name='myFile'>\n"
            + "    <input id='clickMe' type='submit' value='Click Me'>\n"
            + "  </form>\n"
            + "</body>\n"
            + "</html>";

    getMockWebConnection().setDefaultResponse("");

    final WebDriver driver = loadPage2(html);

    final File tmpFile = File.createTempFile("htmlunit-test", ".txt");
    try {
        String path = tmpFile.getAbsolutePath();
        if (driver instanceof InternetExplorerDriver || driver instanceof ChromeDriver) {
            path = path.substring(path.indexOf('/') + 1).replace('/', '\\');
        }
        driver.findElement(By.id("f")).sendKeys(path);
        driver.findElement(By.id("clickMe")).click();
    }
    finally {
        assertTrue(tmpFile.delete());
    }

    final String headerContentType = getMockWebConnection().getLastWebRequest().getAdditionalHeaders()
            .get(HttpHeader.CONTENT_TYPE);
    assertEquals(getExpectedAlerts()[0], headerContentType);

    final String body = getMockWebConnection().getLastWebRequest().getRequestBody();
    assertTrue(body, body.startsWith(getExpectedAlerts()[1]));
    assertTrue(body, body.endsWith(getExpectedAlerts()[2]));
}
 
Example 22
Source Project: htmlunit   Source File: HTMLDocumentTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Property lastModified returns the last modification date of the document.
 * @throws Exception if the test fails
 */
@Test
@Alerts({"string", "Fri, 16 Oct 2009 13:59:47 GMT"})
public void lastModified() throws Exception {
    final List<NameValuePair> responseHeaders = new ArrayList<>();
    // TODO When ran with the IEDriver the IE is in a mysterious state after this test and cannot be restored
    // to normal in an automatic way.
    // All following tests will break until you restart your PC.
    if (!(getWebDriver() instanceof InternetExplorerDriver && "IE".equals(getBrowserVersion().getNickname()))) {
        responseHeaders.add(new NameValuePair("Last-Modified", "Fri, 16 Oct 2009 13:59:47 GMT"));
        testLastModified(responseHeaders);

        // Last-Modified header has priority compared to Date header
        responseHeaders.add(new NameValuePair("Date", "Fri, 17 Oct 2009 13:59:47 GMT"));
        testLastModified(responseHeaders);
    }

    // but Date is taken, if no Last-Modified header is present (if not IE)
    responseHeaders.clear();
    responseHeaders.add(new NameValuePair("Date", "Fri, 16 Oct 2009 13:59:47 GMT"));
    testLastModified(responseHeaders);

    // for some strange reasons, the selenium driven browser is in an invalid
    // state after this test
    releaseResources();
    shutDownAll();
}
 
Example 23
@Override
public void quitBrowser(final InternetExplorerDriver browser) {
    super.quitBrowser(browser);
    final InternetExplorerDriverService service = services.remove(currentThreadName());
    if (service != null && service.isRunning()) {
        service.stop();
    }
}
 
Example 24
@Test
public void shouldNotCreateInternetExplorerWhenStartingServiceThrowsAnException() throws Exception {
    InternetExplorerDriverService.Builder mockServiceBuilder = mock(InternetExplorerDriverService.Builder.class);
    whenNew(InternetExplorerDriverService.Builder.class).withNoArguments().thenReturn(mockServiceBuilder);
    when(mockServiceBuilder.usingDriverExecutable(isA(File.class))).thenReturn(mockServiceBuilder);
    InternetExplorerDriverService mockService = mock(InternetExplorerDriverService.class);
    when(mockServiceBuilder.build()).thenReturn(mockService);
    doThrow(new IOException("Stubbed exception")).when(mockService).start();

    final InternetExplorerDriver browser = config.createBrowser();

    assertThat(browser, is(nullValue()));
    assertThat(config.getServices(), is(Collections.<String, InternetExplorerDriverService>emptyMap()));
    verify(mockServiceBuilder, times(1)).build();
}
 
Example 25
@Test
public void shouldQuitWebDriverAndStopServiceWhenQuitBrowserIsInvoked() throws Exception {
    InternetExplorerDriver mockInternetExplorerDriver = mock(InternetExplorerDriver.class);
    InternetExplorerDriverService mockService = mock(InternetExplorerDriverService.class);
    when(mockService.isRunning()).thenReturn(true);
    config.getServices().put(config.currentThreadName(), mockService);

    config.quitBrowser(mockInternetExplorerDriver);

    verify(mockInternetExplorerDriver).quit();
    assertThat(config.getServices(), is(Collections.<String, InternetExplorerDriverService>emptyMap()));
    verify(mockService, times(1)).stop();
}
 
Example 26
@Test
public void shouldNotStopServiceIfNotRunningWhenQuitBrowserIsInvoked() throws Exception {
    InternetExplorerDriver mockInternetExplorerDriver = mock(InternetExplorerDriver.class);
    InternetExplorerDriverService mockService = mock(InternetExplorerDriverService.class);
    when(mockService.isRunning()).thenReturn(false);
    config.getServices().put(config.currentThreadName(), mockService);

    config.quitBrowser(mockInternetExplorerDriver);

    verify(mockInternetExplorerDriver).quit();
    assertThat(config.getServices(), is(Collections.<String, InternetExplorerDriverService>emptyMap()));
    verify(mockService, times(0)).stop();
}
 
Example 27
@Test
public void shouldBeAbleToCallQuitBrowserMultipleTimes() throws Exception {
    InternetExplorerDriver mockInternetExplorerDriver = mock(InternetExplorerDriver.class);
    InternetExplorerDriverService mockService = mock(InternetExplorerDriverService.class);
    when(mockService.isRunning()).thenReturn(true);
    config.getServices().put(config.currentThreadName(), mockService);

    config.quitBrowser(mockInternetExplorerDriver);
    config.quitBrowser(mockInternetExplorerDriver);

    assertThat(config.getServices(), is(Collections.<String, InternetExplorerDriverService>emptyMap()));
    verify(mockService, times(1)).stop();
}
 
Example 28
Source Project: phoenix.webui.framework   Source File: CapabilityConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 29
Source Project: NoraUi   Source File: DriverFactory.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Generates an ie webdriver. Unable to use it with a proxy. Causes a crash.
 *
 * @return
 *         An ie webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generateIEDriver() throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.IE);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    log.info("Generating IE driver ({}) ...", pathWebdriver);

    System.setProperty(Driver.IE.getDriverName(), pathWebdriver);

    final InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
    internetExplorerOptions.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
    internetExplorerOptions.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
    internetExplorerOptions.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
    internetExplorerOptions.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
    internetExplorerOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
    internetExplorerOptions.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    internetExplorerOptions.setCapability("disable-popup-blocking", true);

    setLoggingLevel(internetExplorerOptions);

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        internetExplorerOptions.setCapability(CapabilityType.PROXY, Context.getProxy());
    }

    return new InternetExplorerDriver(internetExplorerOptions);
}
 
Example 30
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);
}