Search in sources :

Example 1 with InternetExplorerOptions

use of org.openqa.selenium.ie.InternetExplorerOptions in project ats-framework by Axway.

the class AbstractRealBrowserDriver method start.

@Override
@PublicAtsApi
public void start() {
    try {
        log.info("Starting selenium browser with " + this.getClass().getSimpleName());
        if (browserType == BrowserType.FireFox) {
            com.axway.ats.uiengine.FirefoxDriver firefoxDriver = new com.axway.ats.uiengine.FirefoxDriver(url, browserPath, remoteSeleniumURL);
            FirefoxProfile profile = null;
            if (firefoxDriver.getProfileName() != null) {
                profile = new ProfilesIni().getProfile(firefoxDriver.getProfileName());
                if (profile == null) {
                    throw new SeleniumOperationException("Firefox profile '" + firefoxDriver.getProfileName() + "' doesn't exist");
                }
            } else if (firefoxDriver.getProfileDirectory() != null) {
                File profileDirectory = new File(firefoxDriver.getProfileDirectory());
                profile = new FirefoxProfile(profileDirectory);
            } else {
                profile = new FirefoxProfile();
                String downloadDir = UiEngineConfigurator.getInstance().getBrowserDownloadDir();
                // for default browser. Now will FIX this behavior
                if (downloadDir.endsWith("/") || downloadDir.endsWith("\\")) {
                    downloadDir = downloadDir.substring(0, downloadDir.length() - 1);
                }
                // Following options are described in http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
                profile.setPreference("browser.download.dir", downloadDir);
                profile.setPreference("browser.download.folderList", 2);
                profile.setPreference("browser.helperApps.neverAsk.saveToDisk", UiEngineConfigurator.getInstance().getBrowserDownloadMimeTypes());
                // set to  "Always Activate"
                profile.setPreference("plugin.state.java", 2);
                // set to  "Always Activate"
                profile.setPreference("plugin.state.flash", 2);
                profile.setAcceptUntrustedCertificates(true);
            }
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            setFirefoxProxyIfAvailable(capabilities);
            if (this.browserPath != null) {
                capabilities.setCapability(FirefoxDriver.BINARY, this.browserPath);
            }
            FirefoxOptions options = UiEngineConfigurator.getInstance().getFirefoxDriverOptions();
            if (options == null) {
                options = new FirefoxOptions();
            }
            capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new FirefoxDriver(capabilities);
            }
        } else if (browserType == BrowserType.InternetExplorer) {
            InternetExplorerOptions options = UiEngineConfigurator.getInstance().getInternetExplorerDriverOptions();
            if (options == null) {
                options = new InternetExplorerOptions(DesiredCapabilities.internetExplorer());
            }
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), options);
            } else {
                webDriver = new org.openqa.selenium.ie.InternetExplorerDriver(options);
            }
        } else if (browserType == BrowserType.Edge) {
            EdgeOptions options = UiEngineConfigurator.getInstance().getEdgeDriverOptions();
            if (options == null) {
                options = new EdgeOptions().merge(DesiredCapabilities.edge());
            }
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), options);
            } else {
                webDriver = new org.openqa.selenium.edge.EdgeDriver(options);
            }
        } else if (browserType == BrowserType.Chrome) {
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            // apply Chrome options
            ChromeOptions options = UiEngineConfigurator.getInstance().getChromeDriverOptions();
            if (options == null) {
                options = new ChromeOptions();
            }
            /* set browser download dir for Chrome Browser */
            String downloadDir = UiEngineConfigurator.getInstance().getBrowserDownloadDir();
            HashMap<String, Object> prefs = new HashMap<String, Object>();
            prefs.put("profile.default_content_settings.popups", 0);
            prefs.put("download.default_directory", downloadDir);
            options.setExperimentalOption("prefs", prefs);
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new org.openqa.selenium.chrome.ChromeDriver(capabilities);
            }
        } else if (browserType == BrowserType.Safari) {
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), DesiredCapabilities.safari());
            } else {
                webDriver = new org.openqa.selenium.safari.SafariDriver();
            }
        } else if (browserType == BrowserType.PhantomJS) {
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setJavascriptEnabled(true);
            capabilities.setCapability("acceptSslCerts", true);
            capabilities.setCapability("browserConnectionEnabled", true);
            capabilities.setCapability("takesScreenshot", true);
            // See: https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#settings-object
            if (System.getProperty(PhantomJsDriver.SETTINGS_PROPERTY) != null) {
                Map<String, String> settings = extractPhantomJSCapabilityValues(System.getProperty(PhantomJsDriver.SETTINGS_PROPERTY));
                for (Entry<String, String> capability : settings.entrySet()) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + capability.getKey(), capability.getValue());
                }
            }
            // See:  https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage#wiki-webpage-customHeaders
            if (System.getProperty(PhantomJsDriver.CUSTOM_HEADERS_PROPERTY) != null) {
                Map<String, String> customHeaders = extractPhantomJSCapabilityValues(System.getProperty(PhantomJsDriver.CUSTOM_HEADERS_PROPERTY));
                for (Entry<String, String> header : customHeaders.entrySet()) {
                    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + header.getKey(), header.getValue());
                }
            }
            if (this.browserPath != null) {
                capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, this.browserPath);
                System.setProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, // required from the create screenshot method
                this.browserPath);
            }
            // See:  https://github.com/ariya/phantomjs/wiki/API-Reference#command-line-options
            List<String> cliArgsCapabilities = new ArrayList<String>();
            cliArgsCapabilities.add("--web-security=false");
            cliArgsCapabilities.add("--ignore-ssl-errors=true");
            if (System.getProperty(PhantomJsDriver.SSL_PROTOCOL_PROPERTY) != null) {
                cliArgsCapabilities.add("--ssl-protocol=" + System.getProperty(PhantomJsDriver.SSL_PROTOCOL_PROPERTY));
            } else {
                cliArgsCapabilities.add("--ssl-protocol=any");
            }
            if (System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY) != null) {
                cliArgsCapabilities.add("--cookies-file=" + PhantomJsDriver.cookiesFile);
            }
            // cliArgsCapabilities.add( "--local-to-remote-url-access=true" );
            setPhantomJSProxyIfAvailable(cliArgsCapabilities);
            capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCapabilities);
            if (this.remoteSeleniumURL != null) {
                webDriver = new RemoteWebDriver(new URL(this.remoteSeleniumURL), capabilities);
            } else {
                webDriver = new org.openqa.selenium.phantomjs.PhantomJSDriver(capabilities);
            }
        }
        log.info("Opening URL: " + url);
        webDriver.get(url);
        if (this instanceof com.axway.ats.uiengine.PhantomJsDriver) {
            webDriver.manage().window().setSize(new Dimension(1280, 1024));
        } else if (!(this instanceof com.axway.ats.uiengine.EdgeDriver)) {
            webDriver.manage().window().maximize();
        }
        int browserActionTimeout = UiEngineConfigurator.getInstance().getBrowserActionTimeout();
        if (browserActionTimeout > 0) {
            webDriver.manage().timeouts().setScriptTimeout(browserActionTimeout, TimeUnit.SECONDS);
        }
        if (!(this instanceof com.axway.ats.uiengine.EdgeDriver)) {
            webDriver.manage().timeouts().pageLoadTimeout(browserActionTimeout, TimeUnit.SECONDS);
        }
        // waiting for the "body" element to be loaded
        waitForPageLoaded(webDriver, UiEngineConfigurator.getInstance().getWaitPageToLoadTimeout());
    } catch (Exception e) {
        throw new SeleniumOperationException("Error starting Selenium", e);
    }
}
Also used : HashMap(java.util.HashMap) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) URL(java.net.URL) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) Entry(java.util.Map.Entry) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Dimension(org.openqa.selenium.Dimension) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) EdgeOptions(org.openqa.selenium.edge.EdgeOptions) ProfilesIni(org.openqa.selenium.firefox.ProfilesIni) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 2 with InternetExplorerOptions

use of org.openqa.selenium.ie.InternetExplorerOptions 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 3 with InternetExplorerOptions

use of org.openqa.selenium.ie.InternetExplorerOptions 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);
                webDriver = new ChromeDriver(chromeOptions);
                break;
            case "edge":
                setDriverExecutable(config.getString("selenium.edgeDriverExePath", null), "edge");
                caps = getCapsForBrowser("edge");
                injectCapsFromConfig(caps);
                webDriver = new EdgeDriver(caps);
                break;
            case "firefox":
                setDriverExecutable(config.getString("selenium.firefoxDriverExePath", null), "firefox");
                caps = getCapsForBrowser("firefox");
                injectCapsFromConfig(caps);
                FirefoxOptions firefoxOptions = new FirefoxOptions();
                firefoxOptions.merge(caps);
                webDriver = new FirefoxDriver(firefoxOptions);
                break;
            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);
                webDriver = new InternetExplorerDriver(ieOptions);
                break;
            case "opera":
                setDriverExecutable(config.getString("selenium.operaDriverExePath", null), "opera");
                caps = getCapsForBrowser("opera");
                injectCapsFromConfig(caps);
                webDriver = new OperaDriver(caps);
                break;
            case "safari":
                setDriverExecutable(config.getString("selenium.safariDriverExePath", null), "safari");
                caps = getCapsForBrowser("safari");
                injectCapsFromConfig(caps);
                webDriver = new SafariDriver();
                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\" 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", true);
    if (maximizeWindow) {
        try {
            webDriver.manage().window().maximize();
        } catch (Exception ex) {
            Logger.warning(String.format("Failed to maximize browser window"), 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) URL(java.net.URL) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Aggregations

ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)3 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)3 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)3 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)3 URL (java.net.URL)2 WebDriver (org.openqa.selenium.WebDriver)2 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)2 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)2 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)2 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)2 OperaDriver (org.openqa.selenium.opera.OperaDriver)2 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)2 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)2 SafariDriver (org.openqa.selenium.safari.SafariDriver)2 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 ElementNotFoundException (com.axway.ats.uiengine.exceptions.ElementNotFoundException)1 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)1 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)1 InvalidBrowserException (com.coveros.selenified.exceptions.InvalidBrowserException)1 File (java.io.File)1