Example usage for org.openqa.selenium.safari SafariDriver SafariDriver

List of usage examples for org.openqa.selenium.safari SafariDriver SafariDriver

Introduction

In this page you can find the example usage for org.openqa.selenium.safari SafariDriver SafariDriver.

Prototype

public SafariDriver() 

Source Link

Document

Initializes a new SafariDriver} class with default SafariOptions .

Usage

From source file:jp.co.nssol.h5.test.selenium.base.DriverFactory.java

License:Apache License

/**
 * SafariDriver???/*from w w  w.  j a  v a2 s . com*/
 * 
 * @return SafariDriver
 */
private static WebDriver setupSafariDriver() {
    return new SafariDriver() {
        @Override
        public String toString() {
            return "Safari";
        }
    };
}

From source file:net.atf4j.webdriver.BrowserFactory.java

License:Open Source License

/**
 * Local webDriver INSTANCE.//w  w w .j  av a 2  s . co  m
 *
 * @param targetBrowser the target browser
 * @return the webDriver
 */
protected static WebDriver localWebDriver(final String targetBrowser) {
    WebDriver webDriver = null;

    switch (targetBrowser.toLowerCase()) {
    case "chrome":
        webDriver = new ChromeDriver();
        break;
    case "ff":
    case "firefox":
        webDriver = new FirefoxDriver();
        break;
    case "ie":
    case "internetexplorer":
        webDriver = new InternetExplorerDriver();
        break;
    case "edge":
        webDriver = new EdgeDriver();
        break;
    case "opera":
        webDriver = new OperaDriver();
        break;
    case "safari":
        System.setProperty("webdriver.safari.noinstall", "true");
        webDriver = new SafariDriver();
        break;
    // case "htmlunit":
    // webDriver = new HtmlUnitDriver();
    // break;
    // case "phantomjs":
    // case "headless":
    // default:
    // final DesiredCapabilities desiredCapabilities = new
    // DesiredCapabilities();
    // desiredCapabilities.setJavascriptEnabled(true);
    // desiredCapabilities.setCapability(
    // PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
    // "../web-driver-bin/phantomjs.exe");
    // webDriver = new PhantomJSDriver(desiredCapabilities);
    // break;
    }

    return webDriver;
}

From source file:net.mindengine.galen.browser.SeleniumBrowserFactory.java

License:Apache License

private Browser createLocalBrowser() {
    if (FIREFOX.equals(browserType)) {
        return new SeleniumBrowser(new FirefoxDriver());
    } else if (CHROME.equals(browserType)) {
        return new SeleniumBrowser(new ChromeDriver());
    } else if (IE.equals(browserType)) {
        return new SeleniumBrowser(new InternetExplorerDriver());
    } else if (PHANTOMJS.equals(browserType)) {
        return new SeleniumBrowser(new PhantomJSDriver());
    } else if (SAFARI.equals(browserType)) {
        return new SeleniumBrowser(new SafariDriver());
    } else/*from   w w w. ja v a 2 s  .c  o m*/
        throw new RuntimeException(String.format("Unknown browser type: \"%s\"", browserType));
}

From source file:nz.co.testamation.core.WebIntegrationTestAutoConfiguration.java

License:Apache License

@Bean
@Autowired//from   www  .j  av  a 2 s.  c o m
public WebDriver webDriver(@Value("${web.driver:firefox}") String webDriver,
        @Value("${web.driver.autoDownload.mimeTypes:application/pdf}") String autoDownloadMimeTypes,
        @Qualifier("webDriverDownloadDir") File downloadDir) {

    if ("htmlunit".equals(webDriver)) {
        return new HtmlUnitDriver();
    }

    if ("chrome".equals(webDriver)) {
        return new ChromeDriver();
    }

    if ("firefox".equals(webDriver)) {
        FirefoxBinary firefoxBinary = new FirefoxBinary();
        if (System.getenv("DISPLAY") == null) {
            firefoxBinary.setEnvironmentProperty("DISPLAY", ":99");
        }

        FirefoxProfile profile = new FirefoxProfile();

        profile.setPreference("browser.download.folderList", 2); // Download to: 0 desktop, 1 default download location, 2 custom folder
        profile.setPreference("browser.download.dir", downloadDir.getAbsolutePath());
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.helperApps.neverAsk.saveToDisk", autoDownloadMimeTypes);
        profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf");
        profile.setPreference("pdfjs.disabled", true);

        return new FirefoxDriver(firefoxBinary, profile);
    }

    if ("ie".equals(webDriver)) {
        return new InternetExplorerDriver();
    }

    if ("safari".equals(webDriver)) {
        return new SafariDriver();
    }

    if ("opera".equals(webDriver)) {
        return new OperaDriver();
    }

    throw new IllegalArgumentException(format("Web driver %s not supported.", webDriver));
}

From source file:org.alfresco.grid.WebDriverFactory.java

License:Open Source License

/**
 * Creates new instance of {@link SafariDriver}.
 * @return {@link WebDriver} instance of {@link SafariDriver}
 *//*from  w  w  w.j  a v a 2 s .co  m*/
private WebDriver getSafariDriver() {
    if (safariServerPath == null || safariServerPath.isEmpty()) {
        throw new RuntimeException("Failed to create SafariDriver, require a valid safariPath");
    }
    Properties props = System.getProperties();
    if (!props.containsKey(SAFARI_SERVER_DRIVER_PATH)) {
        props.put(SAFARI_SERVER_DRIVER_PATH, safariServerPath);
    }
    return new SafariDriver();
}

From source file:org.apache.archiva.web.test.tools.WebdriverUtility.java

License:Apache License

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");
    }/*from w ww  .  jav  a 2s . c om*/
    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");
    }

}

From source file:org.apache.archiva.web.test.WebDriverBrowseTest.java

License:Apache License

@Override
public WebDriver getDefaultDriver() {
    String seleniumBrowser = System.getProperty("selenium.browser");

    if (StringUtils.contains(seleniumBrowser, "chrome")) {
        return new ChromeDriver();
    }//www . j  a v  a  2s  .  c  o  m

    if (StringUtils.contains(seleniumBrowser, "safari")) {
        return new SafariDriver();
    }

    if (StringUtils.contains(seleniumBrowser, "iexplore")) {
        return new InternetExplorerDriver();
    }

    return new FirefoxDriver();

}

From source file:org.apache.portals.pluto.test.utilities.SimpleTestDriver.java

License:Apache License

/**
 * @throws java.lang.Exception/*w w w  .  ja va 2s.c  om*/
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {

    if (driver == null) {
        loginUrl = System.getProperty("test.server.login.url");
        host = System.getProperty("test.server.host");
        port = System.getProperty("test.server.port");
        username = System.getProperty("test.server.username");
        usernameId = System.getProperty("test.server.username.id");
        password = System.getProperty("test.server.password");
        passwordId = System.getProperty("test.server.password.id");
        browser = System.getProperty("test.browser");
        testContextBase = System.getProperty("test.context.base");
        StringBuilder sb = new StringBuilder();
        sb.append("http://");
        sb.append(host);
        if (port != null && !port.isEmpty()) {
            sb.append(":");
            sb.append(port);
        }
        sb.append("/");
        sb.append(testContextBase);
        baseUrl = sb.toString();
        String str = System.getProperty("test.url.strategy");
        useGeneratedUrl = str.equalsIgnoreCase("generateURLs");
        str = System.getProperty("test.debug");
        debug = str.equalsIgnoreCase("true");
        str = System.getProperty("test.timeout");
        dryrun = Boolean.valueOf(System.getProperty("test.dryrun"));
        timeout = ((str != null) && str.matches("\\d+")) ? Integer.parseInt(str) : 3;
        String wd = System.getProperty("test.browser.webDriver");
        String binary = System.getProperty("test.browser.binary");
        String headlessProperty = System.getProperty("test.browser.headless");
        boolean headless = (((headlessProperty == null) || (headlessProperty.length() == 0)
                || Boolean.valueOf(headlessProperty)));
        String maximizedProperty = System.getProperty("test.browser.maximized");
        boolean maximized = Boolean.valueOf(maximizedProperty);

        System.out.println("before class.");
        System.out.println("   Debug        =" + debug);
        System.out.println("   Dryrun       =" + dryrun);
        System.out.println("   Timeout      =" + timeout);
        System.out.println("   Login URL    =" + loginUrl);
        System.out.println("   Host         =" + host);
        System.out.println("   Port         =" + port);
        System.out.println("   Context      =" + testContextBase);
        System.out.println("   Generate URL =" + useGeneratedUrl);
        System.out.println("   Username     =" + username);
        System.out.println("   UsernameId   =" + usernameId);
        System.out.println("   Password     =" + password);
        System.out.println("   PasswordId   =" + passwordId);
        System.out.println("   Browser      =" + browser);
        System.out.println("   Driver       =" + wd);
        System.out.println("   binary       =" + binary);
        System.out.println("   headless     =" + headless);
        System.out.println("   maximized    =" + maximized);

        if (browser.equalsIgnoreCase("firefox")) {

            System.setProperty("webdriver.gecko.driver", wd);
            FirefoxOptions options = new FirefoxOptions();
            options.setLegacy(true);
            options.setAcceptInsecureCerts(true);

            if ((binary != null) && (binary.length() != 0)) {
                options.setBinary(binary);
            }

            if (headless) {
                options.setHeadless(true);
            }

            driver = new FirefoxDriver(options);

        } else if (browser.equalsIgnoreCase("internetExplorer")) {
            System.setProperty("webdriver.ie.driver", wd);
            driver = new InternetExplorerDriver();
        } else if (browser.equalsIgnoreCase("chrome")) {

            System.setProperty("webdriver.chrome.driver", wd);
            ChromeOptions options = new ChromeOptions();

            if ((binary != null) && (binary.length() > 0)) {
                options.setBinary(binary);
            }

            if (headless) {
                options.addArguments("--headless");
            }

            options.addArguments("--disable-infobars");
            options.setAcceptInsecureCerts(true);

            if (maximized) {
                // The webDriver.manage().window().maximize() feature does not work correctly in headless mode, so set the
                // window size to 1920x1200 (resolution of a 15.4 inch screen).
                options.addArguments("--window-size=1920,1200");
            }

            driver = new ChromeDriver(options);

        } else if (browser.equalsIgnoreCase("phantomjs")) {
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setJavascriptEnabled(true);
            capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary);
            driver = new PhantomJSDriver(capabilities);
        } else if (browser.equalsIgnoreCase("htmlUnit")) {
            LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
                    "org.apache.commons.logging.impl.NoOpLog");
            Logger.getLogger("com.gargoylesoftware").setLevel(Level.SEVERE);
            Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.SEVERE);
            driver = new HtmlUnitDriver() {
                @Override
                protected WebClient getWebClient() {
                    WebClient webClient = super.getWebClient();
                    WebClientOptions options = webClient.getOptions();
                    options.setThrowExceptionOnFailingStatusCode(false);
                    options.setThrowExceptionOnScriptError(false);
                    options.setPrintContentOnFailingStatusCode(false);
                    webClient.setCssErrorHandler(new SilentCssErrorHandler());
                    return webClient;
                }
            };
        } else if (browser.equalsIgnoreCase("safari")) {
            driver = new SafariDriver();
        } else {
            throw new Exception("Unsupported browser: " + browser);
        }

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                driver.quit();
            }
        }));

        if (maximized) {
            driver.manage().window().maximize();
        }

        if (!dryrun) {
            login();
        }
    }
}

From source file:org.apache.zeppelin.WebDriverManager.java

License:Apache License

public static WebDriver getWebDriver() {
    WebDriver driver = null;//  w  ww . j ava 2  s.co m

    if (driver == null) {
        try {
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to
                // run with DISPLAY 99
            }
            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);

            System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, tempPath + "geckodriver");
            System.setProperty(SystemProperty.DRIVER_USE_MARIONETTE, "false");

            FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setBinary(ffox);
            firefoxOptions.setProfile(profile);
            driver = new FirefoxDriver(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;
}

From source file:org.apache.zeppelin.ZeppelinIT.java

License:Apache License

private WebDriver getWebDriver() {
    WebDriver driver = null;/*from   www  .  ja  va2 s  .  c  o m*/

    if (driver == null) {
        try {
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to
                                                               // run with DISPLAY 99
            }
            FirefoxProfile profile = new FirefoxProfile();
            driver = new FirefoxDriver(ffox, profile);
        } catch (Exception e) {
        }
    }

    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
        }
    }

    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
        }
    }

    String url;
    if (System.getProperty("url") != null) {
        url = System.getProperty("url");
    } else {
        url = "http://localhost:8080";
    }

    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.get(url);

    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.partialLinkText("Create new note")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            driver.navigate().to(url);
        }
    }

    if (loaded == false) {
        fail();
    }

    return driver;
}