Search in sources :

Example 46 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project ca3sCore by kuehne-trustable-de.

the class LocomotiveBase method startWebDriver.

public void startWebDriver() {
    Capabilities capabilities;
    baseUrl = configuration.url();
    LOGGER.info(String.format("\n=== Configuration ===\n" + "\tURL:     %s\n" + "\tBrowser: %s\n" + "\tHub:     %s\n", configuration.url(), configuration.browser().name(), configuration.hub()));
    boolean isLocal = StringUtils.isEmpty(configuration.hub());
    switch(configuration.browser()) {
        case CHROME:
            capabilities = new ChromeOptions();
            String driverName = "chromedriver";
            if (SystemUtils.IS_OS_WINDOWS) {
                driverName = "chromedriver.exe";
            }
            try {
                URL resourceURL = ResourceUtils.getURL("classpath:drivers/" + driverName);
                File tmpFile = File.createTempFile("ca3sTest", driverName);
                Files.copy(resourceURL.openStream(), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                if (SystemUtils.IS_OS_LINUX) {
                    Set<PosixFilePermission> perms = new HashSet<>();
                    perms.add(PosixFilePermission.OWNER_READ);
                    perms.add(PosixFilePermission.OWNER_WRITE);
                    perms.add(PosixFilePermission.OWNER_EXECUTE);
                    Files.setPosixFilePermissions(tmpFile.toPath(), perms);
                }
                System.setProperty("webdriver.chrome.driver", tmpFile.getAbsolutePath());
                System.err.println("starting local Chrome using driver at : " + System.getProperty("webdriver.chrome.driver"));
                if (isLocal) {
                    try {
                        WebDriverManager.chromedriver().setup();
                        ChromeOptions options = new ChromeOptions();
                        options.addArguments("--no-sandbox");
                        options.addArguments("--disable-dev-shm-usage");
                        driver = new ChromeDriver(options);
                    } catch (Exception x) {
                        x.printStackTrace();
                        LOGGER.error("starting chrome driver, exiting ...", x);
                        logFatal("chromedriver not found. See https://github.com/ddavison/conductor/wiki/WebDriver-Executables for more information.");
                        System.exit(1);
                    }
                }
            } catch (IOException ioe) {
                ioe.printStackTrace();
                System.err.println("problem installing chrome driver, exiting ...");
                System.exit(1);
            }
            break;
        case FIREFOX:
            capabilities = DesiredCapabilities.firefox();
            if (isLocal)
                driver = new FirefoxDriver(capabilities);
            break;
        case INTERNET_EXPLORER:
            logFatal("iedriver not found. See https://github.com/ddavison/conductor/wiki/WebDriver-Executables for more information.");
            System.exit(1);
            capabilities = DesiredCapabilities.internetExplorer();
            if (isLocal)
                driver = new InternetExplorerDriver(capabilities);
            break;
        case SAFARI:
            logFatal("safaridriver not found. See https://github.com/ddavison/conductor/wiki/WebDriver-Executables for more information.");
            System.exit(1);
            capabilities = DesiredCapabilities.safari();
            if (isLocal)
                driver = new SafariDriver(capabilities);
            break;
        case PHANTOMJS:
            capabilities = DesiredCapabilities.phantomjs();
            if (isLocal)
                try {
                    driver = new PhantomJSDriver(capabilities);
                } catch (Exception x) {
                    logFatal("phantomjs not found. Download them from https://bitbucket.org/ariya/phantomjs/downloads/ and extract the binary as phantomjs.exe, phantomjs.linux, or phantomjs.mac at project root for Windows, Linux, or MacOS.");
                    System.exit(1);
                }
            break;
        default:
            System.err.println("Unknown browser: " + configuration.browser());
            return;
    }
    if (!isLocal)
        // they are using a hub.
        try {
            // just override the driver.
            driver = new RemoteWebDriver(new URL(configuration.hub()), capabilities);
        } catch (Exception x) {
            logFatal("Couldn't connect to hub: " + configuration.hub());
            x.printStackTrace();
            return;
        }
    actions = new Actions(driver);
    if (StringUtils.isNotEmpty(baseUrl))
        driver.navigate().to(baseUrl);
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) Actions(org.openqa.selenium.interactions.Actions) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) IOException(java.io.IOException) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) WebDriverException(org.openqa.selenium.WebDriverException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ElementNotInteractableException(org.openqa.selenium.ElementNotInteractableException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NoSuchWindowException(org.openqa.selenium.NoSuchWindowException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 47 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project ASK by SQAPractical.

the class TestContext method initialize.

public static void initialize(String browser, boolean isHeadless) {
    String osName = System.getProperty("os.name");
    switch(browser) {
        case "chrome":
            String chromeDriverName = "chromedriver.exe";
            if (osName != null && (osName.contains("Mac") || osName.contains("Linux"))) {
                chromeDriverName = "chromedriver";
            }
            System.setProperty("webdriver.chrome.driver", getDriversDirPath() + chromeDriverName);
            Map<String, Object> chromePreferences = new HashMap<>();
            chromePreferences.put("profile.default_content_settings.geolocation", 2);
            chromePreferences.put("download.prompt_for_download", false);
            chromePreferences.put("download.directory_upgrade", true);
            chromePreferences.put("download.default_directory", getDownloadsPath());
            chromePreferences.put("credentials_enable_service", false);
            chromePreferences.put("password_manager_enabled", false);
            chromePreferences.put("safebrowsing.enabled", "true");
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--start-maximized");
            chromeOptions.setExperimentalOption("prefs", chromePreferences);
            if (isHeadless) {
                chromeOptions.setHeadless(true);
                chromeOptions.addArguments("--window-size=1920,1080");
                chromeOptions.addArguments("--disable-gpu");
            }
            driver = new ChromeDriver(chromeOptions);
            break;
        case "firefox":
            String geckoDriverName = "geckodriver.exe";
            if (osName != null && (osName.contains("Mac") || osName.contains("Linux"))) {
                geckoDriverName = "geckodriver";
            }
            System.setProperty("webdriver.gecko.driver", getDriversDirPath() + geckoDriverName);
            System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
            System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
            FirefoxProfile firefoxProfile = new FirefoxProfile();
            firefoxProfile.setPreference("xpinstall.signatures.required", false);
            firefoxProfile.setPreference("app.update.enabled", false);
            firefoxProfile.setPreference("browser.download.folderList", 2);
            firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
            firefoxProfile.setPreference("browser.download.dir", getDownloadsPath());
            firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip;application/octet-stream;application/x-zip;application/x-zip-compressed;text/css;text/html;text/plain;text/xml;text/comma-separated-values");
            firefoxProfile.setPreference("browser.helperApps.neverAsk.openFile", "application/zip;application/octet-stream;application/x-zip;application/x-zip-compressed;text/css;text/html;text/plain;text/xml;text/comma-separated-values");
            firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
            firefoxProfile.setPreference("plugin.disable_full_page_plugi‌​n_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.‌​fdf,application/vnd.‌​adobe.xdp+xml");
            firefoxProfile.setPreference("webdriver.log.driver", "OFF");
            FirefoxOptions firefoxOptions = new FirefoxOptions().setProfile(firefoxProfile).setLogLevel(FirefoxDriverLogLevel.INFO);
            if (isHeadless) {
                FirefoxBinary firefoxBinary = new FirefoxBinary();
                firefoxBinary.addCommandLineOptions("--headless");
                firefoxOptions.setBinary(firefoxBinary);
            }
            driver = new FirefoxDriver(firefoxOptions);
            break;
        case "edge":
            System.setProperty("webdriver.edge.driver", getDriversDirPath() + "MicrosoftWebDriver.exe");
            driver = new EdgeDriver();
            break;
        case "ie":
            System.setProperty("webdriver.ie.driver", getDriversDirPath() + "IEDriverServer.exe");
            DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
            ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
            ieCapabilities.setCapability("requireWindowFocus", true);
            InternetExplorerOptions ieOptions = new InternetExplorerOptions(ieCapabilities);
            driver = new InternetExplorerDriver(ieOptions);
            break;
        case "grid":
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setBrowserName(BrowserType.CHROME);
            capabilities.setPlatform(Platform.ANY);
            URL hubUrl = null;
            try {
                hubUrl = new URL("http://localhost:4444/wd/hub");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            driver = new RemoteWebDriver(hubUrl, capabilities);
            break;
        default:
            throw new RuntimeException("Driver is not implemented for: " + browser);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) HashMap(java.util.HashMap) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL) InternetExplorerOptions(org.openqa.selenium.ie.InternetExplorerOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 48 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project manifoldcf by apache.

the class SeleniumTester method start.

public void start(final BrowserType browserType, final String language, final String startURL) {
    // Download Chrome Driver for Linux from here (https://chromedriver.storage.googleapis.com/index.html?path=2.28/)
    switch(browserType) {
        case CHROME:
            if (System.getProperty("webdriver.chrome.driver") == null || System.getProperty("webdriver.chrome.driver").length() == 0)
                throw new IllegalStateException("Please configure your SL_CHROME_DRIVER environment variable to point to the Selenium Google Chrome Driver");
            // Create a new instance of Chrome driver
            ChromeOptions options = new ChromeOptions();
            options.addArguments("--start-maximized", "--lang=" + language);
            driver = new ChromeDriver(options);
            break;
        case FIREFOX:
            if (System.getProperty("webdriver.gecko.driver") == null || System.getProperty("webdriver.gecko.driver").length() == 0)
                throw new IllegalStateException("Please configure your SL_FIREFOX_DRIVER environment variable to point to the Mozilla Firefox Driver");
            // Create a new instance of Firefox driver
            driver = new FirefoxDriver();
            break;
        case IE:
            if (System.getProperty("webdriver.ie.driver") == null || System.getProperty("webdriver.ie.driver").length() == 0)
                throw new IllegalStateException("Please configure your SL_IE_DRIVER environment variable to point to the Internet Explorer Driver");
            // For more info, on how to configure IE driver, plese read https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
            driver = new InternetExplorerDriver();
            break;
        default:
            throw new IllegalArgumentException("Unknown browser type");
    }
    wait = new WebDriverWait(driver, defaultTimeOutInSeconds);
    driver.get(startURL);
}
Also used : FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 49 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project test-automation-wrapper by gjorezaharchev.

the class IE method browser.

public WebDriver browser() {
    if (System.getProperty("os.arch").equals("x86")) {
        System.setProperty("webdriver.ie.driver", drivers + "IEDriverServer32.exe");
    } else {
        System.setProperty("webdriver.ie.driver", System.getProperty("webdriver.ie.driver", drivers + "IEDriverServer64.exe"));
    }
    driver = new InternetExplorerDriver(ieo());
    driver.manage().deleteAllCookies();
    return null;
}
Also used : InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver)

Example 50 with InternetExplorerDriver

use of org.openqa.selenium.ie.InternetExplorerDriver in project batch3-selenium-testng by euroTech-sdet.

the class Driver method get.

public static WebDriver get() {
    if (driver == null) {
        String browser = ConfigurationReader.get("browser");
        switch(browser) {
            case "chrome":
                WebDriverManager.chromedriver().setup();
                driver = new ChromeDriver();
                break;
            case "chrome-headless":
                WebDriverManager.chromedriver().setup();
                driver = new ChromeDriver(new ChromeOptions().setHeadless(true));
                break;
            case "firefox":
                WebDriverManager.firefoxdriver().setup();
                driver = new FirefoxDriver();
                break;
            case "firefox-headless":
                WebDriverManager.firefoxdriver().setup();
                driver = new FirefoxDriver(new FirefoxOptions().setHeadless(true));
                break;
            case "ie":
                if (!System.getProperty("os.name").toLowerCase().contains("windows"))
                    throw new WebDriverException("Your OS doesn't support Internet Explorer");
                WebDriverManager.iedriver().setup();
                driver = new InternetExplorerDriver();
                break;
            case "edge":
                if (!System.getProperty("os.name").toLowerCase().contains("windows"))
                    throw new WebDriverException("Your OS doesn't support Edge");
                WebDriverManager.edgedriver().setup();
                driver = new EdgeDriver();
                break;
            case "safari":
                if (!System.getProperty("os.name").toLowerCase().contains("mac"))
                    throw new WebDriverException("Your OS doesn't support Safari");
                WebDriverManager.getInstance(SafariDriver.class).setup();
                driver = new SafariDriver();
                break;
        }
    }
    return driver;
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) 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) WebDriverException(org.openqa.selenium.WebDriverException) SafariDriver(org.openqa.selenium.safari.SafariDriver)

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