Search in sources :

Example 26 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project jmeter-plugins by undera.

the class InternetExplorerDriverConfigTest method shouldNotCreateInternetExplorerWhenStartingServiceThrowsAnException.

@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();
}
Also used : InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) InternetExplorerDriverService(org.openqa.selenium.ie.InternetExplorerDriverService) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project jmeter-plugins by undera.

the class InternetExplorerDriverConfigTest method shouldNotStopServiceIfNotRunningWhenQuitBrowserIsInvoked.

@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();
}
Also used : InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) InternetExplorerDriverService(org.openqa.selenium.ie.InternetExplorerDriverService) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project xwiki-platform by xwiki.

the class WebDriverFactory method createWebDriver.

public XWikiWebDriver createWebDriver(String browserName) {
    WebDriver driver;
    if (browserName.startsWith("*firefox")) {
        // Native events are disabled by default for Firefox on Linux as it may cause tests which open many windows
        // in parallel to be unreliable. However, native events work quite well otherwise and are essential for some
        // of the new actions of the Advanced User Interaction. We need native events to be enable especially for
        // testing the WYSIWYG editor. See http://code.google.com/p/selenium/issues/detail?id=2331 .
        FirefoxProfile profile = new FirefoxProfile();
        profile.setEnableNativeEvents(true);
        // Make sure Firefox doesn't upgrade automatically on CI agents.
        profile.setPreference("app.update.auto", false);
        profile.setPreference("app.update.enabled", false);
        profile.setPreference("app.update.silent", false);
        driver = new FirefoxDriver(profile);
        // Hide the Add-on bar (from the bottom of the window, with "WebDriver" written on the right) because it can
        // prevent buttons or links from being clicked when they are beneath it and native events are used.
        // See https://groups.google.com/forum/#!msg/selenium-users/gBozOynEjs8/XDxxQNmUSCsJ
        // We need to load a page before sending the keys otherwise WebDriver throws ElementNotVisible exception.
        driver.get("data:text/plain;charset=utf-8,XWiki");
        driver.switchTo().activeElement().sendKeys(Keys.chord(Keys.CONTROL, "/"));
    } else if (browserName.startsWith("*iexplore")) {
        driver = new InternetExplorerDriver();
    } else if (browserName.startsWith("*chrome")) {
        driver = new ChromeDriver();
    } else if (browserName.startsWith("*phantomjs")) {
        DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
        capabilities.setCapability("handlesAlerts", true);
        try {
            driver = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), capabilities);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("Unsupported browser name [" + browserName + "]");
    }
    // Maximize the browser window by default so that the page has a standard layout. Individual tests can resize
    // the browser window if they want to test how the page layout adapts to limited space. This reduces the
    // probability of a test failure caused by an unexpected layout (nested scroll bars, floating menu over links
    // and buttons and so on).
    driver.manage().window().maximize();
    return new XWikiWebDriver((RemoteWebDriver) driver);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) IOException(java.io.IOException) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 29 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project selenified by Coveros.

the class TestSetup method setupDriver.

/**
 * this creates the webdriver object, which will be used to interact with
 * for all browser web tests
 *
 * @param browser      - what browser is being tested on
 * @param capabilities - what capabilities are being tested with
 * @return WebDriver: the driver to interact with for the test
 * @throws InvalidBrowserException If a browser that is not one specified in the
 *                                 Selenium.Browser class is used, this exception will be thrown
 */
public static WebDriver setupDriver(Browser browser, DesiredCapabilities capabilities) throws InvalidBrowserException {
    WebDriver driver;
    // check the browser
    switch(browser) {
        case HTMLUNIT:
            capabilities.setBrowserName("htmlunit");
            capabilities.setJavascriptEnabled(true);
            System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
            java.util.logging.Logger.getLogger("org.apache.http").setLevel(Level.OFF);
            driver = new HtmlUnitDriver(capabilities);
            break;
        case FIREFOX:
            FirefoxDriverManager.getInstance().forceCache().setup();
            FirefoxOptions firefoxOptions = new FirefoxOptions(capabilities);
            if (System.getProperty(HEADLESS_INPUT) != null && "true".equals(System.getProperty(HEADLESS_INPUT))) {
                firefoxOptions.setHeadless(true);
            }
            driver = new FirefoxDriver(firefoxOptions);
            break;
        case CHROME:
            ChromeDriverManager.getInstance().forceCache().setup();
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions = chromeOptions.merge(capabilities);
            if (System.getProperty(HEADLESS_INPUT) != null && "true".equals(System.getProperty(HEADLESS_INPUT))) {
                chromeOptions.setHeadless(true);
            }
            driver = new ChromeDriver(chromeOptions);
            break;
        case INTERNETEXPLORER:
            InternetExplorerDriverManager.getInstance().forceCache().setup();
            InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions(capabilities);
            driver = new InternetExplorerDriver(internetExplorerOptions);
            break;
        case EDGE:
            EdgeDriverManager.getInstance().forceCache().setup();
            EdgeOptions edgeOptions = new EdgeOptions();
            edgeOptions = edgeOptions.merge(capabilities);
            driver = new EdgeDriver(edgeOptions);
            break;
        case SAFARI:
            SafariOptions safariOptions = new SafariOptions(capabilities);
            driver = new SafariDriver(safariOptions);
            break;
        case OPERA:
            OperaDriverManager.getInstance().forceCache().setup();
            driver = new OperaDriver(capabilities);
            break;
        case PHANTOMJS:
            PhantomJsDriverManager.getInstance().forceCache().setup();
            driver = new PhantomJSDriver(capabilities);
            break;
        // if the browser is not listed, throw an error
        default:
            throw new InvalidBrowserException("The selected browser " + browser + " is not an applicable choice");
    }
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) OperaDriver(org.openqa.selenium.opera.OperaDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) SafariOptions(org.openqa.selenium.safari.SafariOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) EdgeOptions(org.openqa.selenium.edge.EdgeOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) InvalidBrowserException(com.coveros.selenified.exceptions.InvalidBrowserException)

Example 30 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project keycloak by keycloak.

the class URLUtils method navigateToUri.

private static void navigateToUri(String uri, boolean enableIEWorkaround) {
    WebDriver driver = getCurrentDriver();
    log.info("starting navigation");
    // equals the current URL
    if (driver instanceof InternetExplorerDriver && driver.getCurrentUrl().equals(uri)) {
        log.info("IE workaround: target URL equals current URL - refreshing the page");
        driver.navigate().refresh();
        waitForPageToLoad();
    }
    log.info("current URL:  " + driver.getCurrentUrl());
    log.info("navigating to " + uri);
    if (driver.getCurrentUrl().equals(uri)) {
        // Some browsers won't do anything if navigating to the same URL; this "fixes" it
        log.info("target URL equals current URL - refreshing the page");
        driver.navigate().refresh();
    } else {
        driver.navigate().to(uri);
    }
    waitForPageToLoad();
    log.info("new current URL:  " + driver.getCurrentUrl());
    // address bar states the correct URL; seemingly this is another bug in IE WebDriver)
    if (enableIEWorkaround && driver instanceof InternetExplorerDriver && (driver.getCurrentUrl().matches("^[^#]+/#state=[^#/&]+&code=[^#/&]+$") || driver.getCurrentUrl().matches("^.+/auth/admin/[^/]+/console/$"))) {
        log.info("IE workaround: reloading the page after deleting the cookies...");
        navigateToUri(uri, false);
    } else {
        log.info("navigation complete");
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver)

Aggregations

InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)56 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)27 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)26 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)21 SafariDriver (org.openqa.selenium.safari.SafariDriver)17 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)16 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)15 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)15 WebDriver (org.openqa.selenium.WebDriver)13 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)10 URL (java.net.URL)9 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)9 File (java.io.File)8 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)8 Test (org.junit.Test)7 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)7 InternetExplorerDriverService (org.openqa.selenium.ie.InternetExplorerDriverService)7 WebDriverException (org.openqa.selenium.WebDriverException)5 OperaDriver (org.openqa.selenium.opera.OperaDriver)5 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)4