Search in sources :

Example 21 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project selenium_java by sergueik.

the class SafariDriverFactory method newInstance.

@Override
public WebDriver newInstance(DriverOptions driverOptions) {
    if (!OS.isFamilyMac())
        throw new UnsupportedOperationException("Unsupported platform: " + Platform.getCurrent());
    SafariDriverService service = setupBuilder(new SafariDriverService.Builder(), driverOptions, null).build();
    SafariOptions options = newSafariOptions(driverOptions);
    options.merge(driverOptions.getCapabilities());
    SafariDriver driver = new SafariDriver(service, options);
    setInitialWindowSize(driver, driverOptions);
    return driver;
}
Also used : SafariDriverService(org.openqa.selenium.safari.SafariDriverService) SafariOptions(org.openqa.selenium.safari.SafariOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 22 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project primefaces by primefaces.

the class DefaultWebDriverAdapter method createWebDriver.

@Override
public WebDriver createWebDriver() {
    ConfigProvider config = ConfigProvider.getInstance();
    if (config.getWebdriverBrowser() == null) {
        throw new RuntimeException("No webdriver.browser configured; Please either configure it or implement WebDriverAdapter#getWebDriver!");
    }
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    switch(config.getWebdriverBrowser()) {
        case "firefox":
            FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
            firefoxOptions.setHeadless(config.isWebdriverHeadless());
            if (!config.isWebdriverHeadless()) {
                firefoxOptions.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
            }
            return new FirefoxDriver(firefoxOptions);
        case "chrome":
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
            chromeOptions.setHeadless(config.isWebdriverHeadless());
            chromeOptions.setCapability(ChromeOptions.LOGGING_PREFS, logPrefs);
            return new ChromeDriver(chromeOptions);
        case "safari":
            SafariOptions safariOptions = new SafariOptions();
            /*
                 * Safari does not support headless as of september 2020
                 * https://github.com/SeleniumHQ/selenium/issues/5985
                 * https://discussions.apple.com/thread/251837694
                 */
            // safariOptions.setHeadless(config.isDriverHeadless());
            safariOptions.setCapability("safari:diagnose", "true");
            return new SafariDriver(safariOptions);
    }
    throw new RuntimeException("Current supported browsers are: safari, firefox, chrome");
}
Also used : FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SafariOptions(org.openqa.selenium.safari.SafariOptions) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 23 with SafariDriver

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

the class WebDriverManager method getWebDriver.

public static WebDriver getWebDriver() {
    WebDriver driver = null;
    try {
        int firefoxVersion = WebDriverManager.getFirefoxVersion();
        LOG.info("Firefox version " + firefoxVersion + " detected");
        downLoadsDir = FileUtils.getTempDirectory().toString();
        String tempPath = downLoadsDir + "/firefox/";
        downloadGeekoDriver(firefoxVersion, tempPath);
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.dir", downLoadsDir);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.download.manager.showAlertOnComplete", false);
        profile.setPreference("browser.download.manager.closeWhenDone", true);
        profile.setPreference("app.update.auto", false);
        profile.setPreference("app.update.enabled", false);
        profile.setPreference("dom.max_script_run_time", 0);
        profile.setPreference("dom.max_chrome_script_run_time", 0);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
        profile.setPreference("network.proxy.type", 0);
        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile);
        ImmutableMap<String, String> displayImmutable = ImmutableMap.<String, String>builder().build();
        if ("true".equals(System.getenv("TRAVIS"))) {
            // Run with DISPLAY 99 for TRAVIS or other build machine
            displayImmutable = ImmutableMap.of("DISPLAY", ":99");
        }
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
        System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
        driver = new FirefoxDriver(new GeckoDriverService.Builder().usingDriverExecutable(new File(tempPath + "geckodriver")).withEnvironment(displayImmutable).build(), firefoxOptions);
    } catch (Exception e) {
        LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
    }
    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
        }
    }
    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while SafariDriver ", e);
        }
    }
    String url;
    if (System.getenv("url") != null) {
        url = System.getenv("url");
    } else {
        url = "http://localhost:8080";
    }
    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.get(url);
    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {

                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
            driver.navigate().to(url);
        }
    }
    if (loaded == false) {
        fail();
    }
    driver.manage().window().maximize();
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) IOException(java.io.IOException) TimeoutException(org.openqa.selenium.TimeoutException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) GeckoDriverService(org.openqa.selenium.firefox.GeckoDriverService) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) TimeoutException(org.openqa.selenium.TimeoutException)

Example 24 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project keycloak by keycloak.

the class UIUtils method clickLink.

public static void clickLink(WebElement element) {
    WebDriver driver = getCurrentDriver();
    waitUntilElement(element).is().clickable();
    if (driver instanceof SafariDriver && !element.isDisplayed()) {
        // Safari sometimes thinks an element is not visible
        // even though it is. In this case we just move the cursor and click.
        performOperationWithPageReload(() -> new Actions(driver).click(element).perform());
    } else {
        performOperationWithPageReload(element::click);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Actions(org.openqa.selenium.interactions.Actions) SafariDriver(org.openqa.selenium.safari.SafariDriver)

Example 25 with SafariDriver

use of org.openqa.selenium.safari.SafariDriver in project vividus by vividus-framework.

the class WebDriverTypeTests method testGetSafariWebDriver.

@Test
void testGetSafariWebDriver() {
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    try (MockedConstruction<SafariDriver> safariDriverMock = mockConstruction(SafariDriver.class, (mock, context) -> {
        assertEquals(1, context.getCount());
        assertEquals(List.of(SafariOptions.fromCapabilities(desiredCapabilities)), context.arguments());
    })) {
        WebDriver actual = WebDriverType.SAFARI.getWebDriver(desiredCapabilities, new WebDriverConfiguration());
        assertEquals(safariDriverMock.constructed().get(0), actual);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) SafariDriver(org.openqa.selenium.safari.SafariDriver) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SafariDriver (org.openqa.selenium.safari.SafariDriver)34 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)20 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)20 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)17 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)15 WebDriver (org.openqa.selenium.WebDriver)10 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)10 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)9 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)9 SafariOptions (org.openqa.selenium.safari.SafariOptions)8 URL (java.net.URL)7 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)7 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)7 WebDriverException (org.openqa.selenium.WebDriverException)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 OperaDriver (org.openqa.selenium.opera.OperaDriver)5 WebElement (org.openqa.selenium.WebElement)4 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)4 File (java.io.File)3 IOException (java.io.IOException)3