Search in sources :

Example 21 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project selenium_java by sergueik.

the class InternetExplorerTest method beforeMethod.

@SuppressWarnings("deprecation")
@BeforeMethod
public void beforeMethod() throws Exception {
    instance = AutoItX.getInstance();
    System.setProperty("webdriver.ie.driver", "c:/java/selenium/IEDriverServer.exe");
    // Started InternetExplorerDriver server (32-bit) 2.42.0.0
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    driver = new InternetExplorerDriver(capabilities);
    // org.openqa.selenium.WebDriverException: java.net.SocketException:
    // Software caused connection abort: recv failed
    // https://stackoverflow.com/questions/21330079/i-o-exception-and-unable-to-find-element-in-ie-using-selenium-webdriver/21373224
    // possibly caused by incorrect IE security settings or the lagging
    // iedriverserver.exe
    // installing 3.14.0 (32 bit) from https://www.seleniumhq.org/download/
    // resolves the issue
    // For IE Internet zones see https://github.com/allquixotic/iepmm (NOTE:
    // cryptic)
    originalHandle = driver.getWindowHandle();
    System.err.println("The current window handle " + originalHandle);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
Also used : InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 22 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project selenium_java by sergueik.

the class BrowserFactory method getBrowser.

/**
 * Gets the Selenium WebDriver instance.
 *
 * @param browserConfig the {@code browser} specified in
 *                      {@code framework.properties}
 * @return WebDriver - the Selenium WebDriver
 */
public static WebDriver getBrowser(String browserConfig) {
    WebDriver driver = null;
    StringBuilder builder = new StringBuilder();
    builder.append(System.getProperty("user.dir").replace("\\", "/"));
    builder.append("/src/test/resources/jcucumberng/framework/drivers/");
    String driverPath = builder.toString().trim();
    try {
        Browser browser = Browser.valueOf(browserConfig.toUpperCase());
        switch(browser) {
            case CHROME32:
                System.setProperty("webdriver.chrome.driver", driverPath + "chromedriver_win32.exe");
                driver = new ChromeDriver();
                break;
            case CHROME32_NOHEAD:
                System.setProperty("webdriver.chrome.driver", driverPath + "chromedriver_win32.exe");
                ChromeOptions chromeOpts = new ChromeOptions();
                chromeOpts.addArguments("--headless");
                driver = new ChromeDriver(chromeOpts);
                break;
            case FF32:
                System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver_win32.exe");
                driver = new FirefoxDriver();
                break;
            case FF32_NOHEAD:
                driver = BrowserFactory.initFirefoxNoHead(driverPath, "geckodriver_win32.exe");
                break;
            case FF64:
                System.setProperty("webdriver.gecko.driver", driverPath + "geckodriver_win64.exe");
                driver = new FirefoxDriver();
                break;
            case FF64_NOHEAD:
                driver = BrowserFactory.initFirefoxNoHead(driverPath, "geckodriver_win64.exe");
                break;
            case EDGE:
                System.setProperty("webdriver.edge.driver", driverPath + "MicrosoftWebDriver.exe");
                driver = new EdgeDriver();
                break;
            case IE32:
                System.setProperty("webdriver.ie.driver", driverPath + "IEDriverServer_win32.exe");
                driver = new InternetExplorerDriver();
                break;
            case IE64:
                System.setProperty("webdriver.ie.driver", driverPath + "IEDriverServer_win64.exe");
                driver = new InternetExplorerDriver();
                break;
            default:
                // Handled in try-catch
                break;
        }
    } catch (IllegalArgumentException iae) {
        if (StringUtils.isBlank(browserConfig)) {
            browserConfig = "BLANK";
        }
        throw new UnsupportedBrowserException(Messages.UNSUPPORTED_BROWSER + browserConfig);
    }
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) UnsupportedBrowserException(jcucumberng.framework.exceptions.UnsupportedBrowserException) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Browser(jcucumberng.framework.enums.Browser)

Example 23 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project selenium_java by sergueik.

the class ProtractorDriver method init.

@Before
public void init() throws MalformedURLException {
    log.info("Launching (protractor) in " + browser + "...");
    DesiredCapabilities capabilities = null;
    if (browser.toLowerCase().equals("firefox")) {
        capabilities = capabilitiesFirefox(capabilities);
    } else if (browser.toLowerCase().equals("phantomjs")) {
        capabilities = capabilitiesPhantomJS(capabilities);
    } else if (browser.toLowerCase().equals("chrome")) {
        capabilities = capabilitiesChrome(capabilities);
    } else if (browser.toLowerCase().equals("iexplore")) {
        capabilities = capabilitiesExplorer(capabilities);
    } else if (browser.toLowerCase().equals("android")) {
        capabilities = capabilitiesAndroid(capabilities);
    } else if (browser.toLowerCase().equals("iphone")) {
        capabilities = capabilitiesiPhone(capabilities);
    } else if (browser.toLowerCase().equals("ipad")) {
        capabilities = capabilitiesiPad(capabilities);
    }
    if (!location.toLowerCase().contains("local")) {
        log.info("Running on Selenium Grid: " + location);
        driver = new RemoteWebDriver(new URL(location), capabilities);
    } else if (browser.toLowerCase().equals("firefox")) {
        driver = new FirefoxDriver(capabilities);
    } else if (browser.toLowerCase().equals("phantomjs")) {
        driver = new PhantomJSDriver(capabilities);
    } else if (browser.toLowerCase().equals("chrome")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("iexplore")) {
        driver = new InternetExplorerDriver(capabilities);
    } else if (browser.toLowerCase().equals("android")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("iphone")) {
        driver = new ChromeDriver(capabilities);
    } else if (browser.toLowerCase().equals("ipad")) {
        driver = new ChromeDriver(capabilities);
    }
    ngDriver = new NgWebDriver(driver);
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    actions = new Actions(driver);
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) NgWebDriver(com.jprotractor.NgWebDriver) Actions(org.openqa.selenium.interactions.Actions) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) URL(java.net.URL) Before(cucumber.api.java.Before)

Example 24 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project opentest by mcdcorp.

the class SeleniumHelper method createDriver.

private static WebDriver createDriver() {
    WebDriver webDriver = null;
    DesiredCapabilities caps;
    setSystemProperties();
    if (config.hasProperty("selenium.seleniumServerUrl")) {
        String seleniumServerUrl = config.getString("selenium.seleniumServerUrl");
        Logger.info(String.format("Using remote Selenium server %s", seleniumServerUrl));
        try {
            caps = new DesiredCapabilities();
            injectCapsFromConfig(caps);
            webDriver = new RemoteWebDriver(new URL(seleniumServerUrl), caps);
        } catch (Exception ex) {
            throw new RuntimeException(String.format("Falied to connect to Selenium server %s", seleniumServerUrl), ex);
        }
    } else {
        Logger.info("Using local Selenium server");
        String browserName = config.getString("selenium.desiredCapabilities.browserName").toLowerCase();
        switch(browserName) {
            case "chrome":
                setDriverExecutable(config.getString("selenium.chromeDriverExePath", null), "chrome");
                caps = getCapsForBrowser("chrome");
                injectCapsFromConfig(caps);
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.merge(caps);
                if (config.hasProperty("selenium.chromeBinaryExePath")) {
                    chromeOptions.setBinary(config.getString("selenium.chromeBinaryExePath"));
                }
                if (config.hasProperty("selenium.chromeDriverExeArgs")) {
                    chromeOptions.addArguments(config.getList("selenium.chromeDriverExeArgs"));
                }
                if (config.hasProperty("selenium.chromeAcceptInsecureCerts")) {
                    chromeOptions.setAcceptInsecureCerts(config.getBoolean("selenium.chromeAcceptInsecureCerts"));
                }
                if (config.hasProperty("selenium.chromeExperimentalOptions")) {
                    config.getMap("selenium.chromeExperimentalOptions").forEach((key, value) -> {
                        chromeOptions.setExperimentalOption(key.toString(), value);
                    });
                }
                webDriver = new ChromeDriver(chromeOptions);
                break;
            case "edge":
                setDriverExecutable(config.getString("selenium.edgeDriverExePath", null), "edge");
                caps = getCapsForBrowser("edge");
                injectCapsFromConfig(caps);
                EdgeOptions edgeOptions = new EdgeOptions();
                edgeOptions.merge(caps);
                webDriver = new EdgeDriver(edgeOptions);
                break;
            case "firefox":
                setDriverExecutable(config.getString("selenium.firefoxDriverExePath", null), "firefox");
                caps = getCapsForBrowser("firefox");
                injectCapsFromConfig(caps);
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                if (config.hasProperty("selenium.firefoxBinaryExePath")) {
                    firefoxOptions.setBinary(config.getString("selenium.firefoxBinaryExePath"));
                }
                firefoxOptions.merge(caps);
                if (config.hasProperty("selenium.firefoxDriverExeArgs")) {
                    firefoxOptions.addArguments(config.getList("selenium.firefoxDriverExeArgs"));
                }
                webDriver = new FirefoxDriver(firefoxOptions);
                break;
            case "ie":
            case "internet explorer":
                setDriverExecutable(config.getString("selenium.ieDriverExePath", null), "internet explorer");
                caps = getCapsForBrowser("internet explorer");
                // Avoid the browser zoom level error
                caps.setCapability("ignoreZoomSetting", true);
                injectCapsFromConfig(caps);
                InternetExplorerOptions ieOptions = new InternetExplorerOptions();
                ieOptions.merge(caps);
                if (config.hasProperty("selenium.ieDriverExeArgs")) {
                    ieOptions.addCommandSwitches((String[]) config.getList("selenium.ieDriverExeArgs").toArray());
                }
                webDriver = new InternetExplorerDriver(ieOptions);
                break;
            case "opera":
                setDriverExecutable(config.getString("selenium.operaDriverExePath", null), "opera");
                caps = getCapsForBrowser("opera");
                injectCapsFromConfig(caps);
                OperaOptions operaOptions = new OperaOptions();
                if (config.hasProperty("selenium.operaBinaryExePath")) {
                    operaOptions.setBinary(config.getString("selenium.operaBinaryExePath"));
                }
                operaOptions.merge(caps);
                if (config.hasProperty("selenium.operaDriverExeArgs")) {
                    operaOptions.addArguments(config.getList("selenium.operaDriverExeArgs"));
                }
                webDriver = new OperaDriver(operaOptions);
                break;
            case "safari":
                caps = getCapsForBrowser("safari");
                injectCapsFromConfig(caps);
                SafariOptions safariOptions = new SafariOptions(caps);
                webDriver = new SafariDriver(safariOptions);
                safariOptions.setUseTechnologyPreview(config.getBoolean("selenium.safariUseTechnologyPreview", false));
                break;
            default:
                throw new RuntimeException(String.format("The \"selenium.browserName\" config property specifies a browser " + "that is invalid or not supported. The property value was \"%s\". " + "The valid values are: \"chrome\", \"edge\", \"firefox\", \"internet " + "explorer\", \"opera\" and \"safari\".", browserName));
        }
    }
    webDriver.manage().timeouts().setScriptTimeout(config.getInteger("selenium.scriptTimeout", 20), TimeUnit.SECONDS);
    webDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    Boolean maximizeWindow = config.getBoolean("selenium.maximizeWindow", !SystemUtils.IS_OS_MAC);
    Boolean fullScreen = config.getBoolean("selenium.fullScreen", null);
    Rectangle resolution = SeleniumHelper.parseResolution(config.getString("selenium.resolution", ""));
    if (resolution != null) {
        webDriver.manage().window().setPosition(new Point(resolution.x, resolution.y));
        webDriver.manage().window().setSize(new Dimension(resolution.width, resolution.height));
    } else {
        if (maximizeWindow && !Boolean.TRUE.equals(fullScreen)) {
            try {
                webDriver.manage().window().maximize();
            } catch (Exception ex) {
                Logger.warning(String.format("Failed to maximize browser window"), ex);
            }
        }
        if (fullScreen != null && fullScreen) {
            try {
                if (maximizeWindow && SystemUtils.IS_OS_MAC) {
                    // We have to wait for the macOS window resize animation to
                    // finish, otherwise the full-screen won't take
                    Thread.sleep(1000);
                }
                webDriver.manage().window().fullscreen();
            } catch (Exception ex) {
                Logger.warning(String.format("Failed to set full-sceen browser mode"), ex);
            }
        }
    }
    return webDriver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) OperaDriver(org.openqa.selenium.opera.OperaDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Rectangle(java.awt.Rectangle) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) URL(java.net.URL) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) OperaOptions(org.openqa.selenium.opera.OperaOptions) 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)

Example 25 with InternetExplorerDriver

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

the class DriverFactory method generateIEDriver.

/**
 * 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);
}
Also used : TechnicalException(com.github.noraui.exception.TechnicalException) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) File(java.io.File) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions)

Aggregations

InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)26 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)14 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)14 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)11 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)9 WebDriver (org.openqa.selenium.WebDriver)7 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)7 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)7 SafariDriver (org.openqa.selenium.safari.SafariDriver)7 URL (java.net.URL)6 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)6 InternetExplorerDriverService (org.openqa.selenium.ie.InternetExplorerDriverService)6 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)6 Test (org.junit.Test)5 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 File (java.io.File)3 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)3 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)3 OperaDriver (org.openqa.selenium.opera.OperaDriver)3