Search in sources :

Example 1 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project antlr4 by antlr.

the class SharedWebDriver method init.

public static WebDriver init() {
    if (driver == null) {
        System.setProperty("webdriver.safari.noinstall", "true");
        driver = new SafariDriver();
    } else if (timer != null) {
        timer.cancel();
        timer = null;
    }
    return driver;
}
Also used : SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 2 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project page-factory-2 by sbtqa.

the class TagWebDriver method createDriver.

private static void createDriver() throws UnsupportedBrowserException, MalformedURLException {
    DesiredCapabilities capabilities = new WebDriverCapabilitiesParser().parse();
    if (!PROPERTIES.getProxy().isEmpty()) {
        Proxy seleniumProxy = ProxyConfigurator.configureProxy();
        capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    }
    String browserName = getBrowserName();
    capabilities.setBrowserName(browserName);
    String webDriverUrl = PROPERTIES.getWebDriverUrl();
    if (!webDriverUrl.isEmpty()) {
        setWebDriver(createRemoteWebDriver(webDriverUrl, capabilities));
    } else {
        if (browserName.equalsIgnoreCase(FIREFOX)) {
            setWebDriver(new FirefoxDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(SAFARI)) {
            setWebDriver(new SafariDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(CHROME)) {
            WebDriverManagerConfigurator.configureDriver(ChromeDriverManager.getInstance(), CHROME);
            setWebDriver(new ChromeDriver(capabilities));
        } else if (browserName.equalsIgnoreCase(IE)) {
            WebDriverManagerConfigurator.configureDriver(InternetExplorerDriverManager.getInstance(), IE);
            setWebDriver(new InternetExplorerDriver(capabilities));
        } else {
            throw new UnsupportedBrowserException("'" + browserName + "' is not supported yet");
        }
    }
    webDriver.manage().timeouts().pageLoadTimeout(PageFactory.getTimeOutInSeconds(), TimeUnit.SECONDS);
    setBrowserSize();
    webDriver.get(PROPERTIES.getStartingUrl());
}
Also used : UnsupportedBrowserException(ru.sbtqa.tag.pagefactory.exceptions.UnsupportedBrowserException) Proxy(org.openqa.selenium.Proxy) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebDriverCapabilitiesParser(ru.sbtqa.tag.pagefactory.support.capabilities.WebDriverCapabilitiesParser) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 3 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project archiva by apache.

the class WebdriverUtility method newWebDriver.

public static WebDriver newWebDriver(String seleniumBrowser, String seleniumHost, int seleniumPort, boolean seleniumRemote) {
    log.info("WebDriver {}, {}, {}, {}", seleniumBrowser, seleniumHost, seleniumPort, seleniumRemote);
    if (seleniumRemote && StringUtils.isEmpty(seleniumHost)) {
        throw new IllegalArgumentException("seleniumHost must be set, when seleniumRemote=true");
    }
    try {
        if (StringUtils.contains(seleniumBrowser, "chrome")) {
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            if (seleniumRemote) {
                DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities);
            } else {
                return new ChromeDriver(options);
            }
        }
        if (StringUtils.contains(seleniumBrowser, "safari")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.safari());
            } else {
                return new SafariDriver();
            }
        }
        if (StringUtils.contains(seleniumBrowser, "iexplore")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.internetExplorer());
            } else {
                new InternetExplorerDriver();
            }
        }
        if (StringUtils.contains(seleniumBrowser, "firefox")) {
            if (seleniumRemote) {
                return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), DesiredCapabilities.firefox());
            } else {
                return new FirefoxDriver();
            }
        }
        DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
        capabilities.setJavascriptEnabled(true);
        capabilities.setVersion("firefox-52");
        WebDriver driver;
        if (seleniumRemote) {
            driver = new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"), capabilities);
        } else {
            driver = new HtmlUnitDriver(capabilities) {

                @Override
                protected WebClient modifyWebClient(WebClient client) {
                    client.getOptions().setThrowExceptionOnFailingStatusCode(false);
                    client.getOptions().setThrowExceptionOnScriptError(false);
                    client.getOptions().setCssEnabled(true);
                    return client;
                }
            };
        }
        return driver;
    } catch (MalformedURLException e) {
        throw new RuntimeException("Initializion of remote driver failed");
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) MalformedURLException(java.net.MalformedURLException) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) SafariDriver(org.openqa.selenium.safari.SafariDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 4 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project divolte-collector by divolte.

the class SeleniumTestBase method doSetUp.

private void doSetUp(final Optional<String> configFileName) throws Exception {
    final String driverName = System.getenv().getOrDefault(DRIVER_ENV_VAR, PHANTOMJS_DRIVER);
    switch(driverName) {
        case CHROME_DRIVER:
            setupLocalChrome();
            break;
        case SAFARI_DRIVER:
            driver = new SafariDriver();
            break;
        case SAUCE_DRIVER:
            setupSauceLabs();
            break;
        case BS_DRIVER:
            setupBrowserStack();
            break;
        case PHANTOMJS_DRIVER:
        default:
            driver = new PhantomJSDriver();
            break;
    }
    final WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(WINDOW_AVAILABLE);
    server = configFileName.map(TestServer::new).orElseGet(TestServer::new);
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) SafariDriver(org.openqa.selenium.safari.SafariDriver) TestServer(io.divolte.server.ServerTestUtils.TestServer)

Example 5 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project nutch by apache.

the class HttpWebClient method getDriverForPage.

public static WebDriver getDriverForPage(String url, Configuration conf) {
    WebDriver driver = null;
    DesiredCapabilities capabilities = null;
    long pageLoadWait = conf.getLong("page.load.delay", 3);
    try {
        String driverType = conf.get("selenium.driver", "firefox");
        switch(driverType) {
            case "firefox":
                String allowedHost = conf.get("selenium.firefox.allowed.hosts", "localhost");
                long firefoxBinaryTimeout = conf.getLong("selenium.firefox.binary.timeout", 45);
                boolean enableFlashPlayer = conf.getBoolean("selenium.firefox.enable.flash", false);
                int loadImage = conf.getInt("selenium.firefox.load.image", 1);
                int loadStylesheet = conf.getInt("selenium.firefox.load.stylesheet", 1);
                FirefoxProfile profile = new FirefoxProfile();
                FirefoxBinary binary = new FirefoxBinary();
                profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, allowedHost);
                profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", enableFlashPlayer);
                profile.setPreference("permissions.default.stylesheet", loadStylesheet);
                profile.setPreference("permissions.default.image", loadImage);
                binary.setTimeout(TimeUnit.SECONDS.toMillis(firefoxBinaryTimeout));
                driver = new FirefoxDriver(binary, profile);
                break;
            case "chrome":
                driver = new ChromeDriver();
                break;
            case "safari":
                driver = new SafariDriver();
                break;
            case "opera":
                driver = new OperaDriver();
                break;
            case "phantomjs":
                driver = new PhantomJSDriver();
                break;
            case "remote":
                String seleniumHubHost = conf.get("selenium.hub.host", "localhost");
                int seleniumHubPort = Integer.parseInt(conf.get("selenium.hub.port", "4444"));
                String seleniumHubPath = conf.get("selenium.hub.path", "/wd/hub");
                String seleniumHubProtocol = conf.get("selenium.hub.protocol", "http");
                String seleniumGridDriver = conf.get("selenium.grid.driver", "firefox");
                String seleniumGridBinary = conf.get("selenium.grid.binary");
                switch(seleniumGridDriver) {
                    case "firefox":
                        capabilities = DesiredCapabilities.firefox();
                        capabilities.setBrowserName("firefox");
                        capabilities.setJavascriptEnabled(true);
                        capabilities.setCapability("firefox_binary", seleniumGridBinary);
                        System.setProperty("webdriver.reap_profile", "false");
                        driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), capabilities);
                        break;
                    case "phantomjs":
                        capabilities = DesiredCapabilities.phantomjs();
                        capabilities.setBrowserName("phantomjs");
                        capabilities.setJavascriptEnabled(true);
                        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, seleniumGridBinary);
                        driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), capabilities);
                        break;
                    default:
                        LOG.error("The Selenium Grid WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType);
                        driver = new RemoteWebDriver(new URL(seleniumHubProtocol, seleniumHubHost, seleniumHubPort, seleniumHubPath), DesiredCapabilities.firefox());
                        break;
                }
                break;
            default:
                LOG.error("The Selenium WebDriver choice {} is not available... defaulting to FirefoxDriver().", driverType);
                driver = new FirefoxDriver();
                break;
        }
        LOG.debug("Selenium {} WebDriver selected.", driverType);
        driver.manage().timeouts().pageLoadTimeout(pageLoadWait, TimeUnit.SECONDS);
        driver.get(url);
    } catch (Exception e) {
        if (e instanceof TimeoutException) {
            LOG.debug("Selenium WebDriver: Timeout Exception: Capturing whatever loaded so far...");
            return driver;
        }
        cleanUpDriver(driver);
        throw new RuntimeException(e);
    }
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) OperaDriver(com.opera.core.systems.OperaDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) URL(java.net.URL) TimeoutException(org.openqa.selenium.TimeoutException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) TimeoutException(org.openqa.selenium.TimeoutException)

Aggregations

SafariDriver (org.openqa.selenium.safari.SafariDriver)9 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)7 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)7 WebDriver (org.openqa.selenium.WebDriver)5 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)5 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)5 URL (java.net.URL)4 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)4 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)4 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)4 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)3 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)3 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)3 TimeoutException (org.openqa.selenium.TimeoutException)2 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)2 FirefoxBinary (org.openqa.selenium.firefox.FirefoxBinary)2 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)2 OperaDriver (org.openqa.selenium.opera.OperaDriver)2 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)2 InvalidBrowserException (com.coveros.selenified.exceptions.InvalidBrowserException)1