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:ExperimentRunner.java

License:Apache License

protected void createDriver(String browser) throws Exception {
    if (browser.equals("Safari")) {
        driver = new SafariDriver();
    } else if (browser.equals("Firefox")) {
        setupFirefox();//from w w w  .j  a va 2 s .co  m
        //driver = new FirefoxDriver();
    } else if (browser.equals("Chrome")) {
        driver = new ChromeDriver();
    } else {
        System.out.println("unknown browser: " + browser);
        System.exit(0);
    }
}

From source file:GeneralCookieDriver.java

License:Open Source License

public WebDriver getWebDriver(Browser browser, boolean privateBrowsing) {
    if (browser.equals(Browser.CHROME)) {
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();

        if (privateBrowsing) {
            capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
        }/*from   w w  w  .j ava  2  s .c  o  m*/

        System.setProperty("webdriver.chrome.driver", chromeDriverLocation);

        return new ChromeDriver(capabilities);
    } else if (browser.equals(Browser.FIREFOX)) {
        FirefoxProfile ffp = new FirefoxProfile();

        if (privateBrowsing) {
            ffp.setPreference("browser.privatebrowsing.dont_prompt_on_enter", true);
            ffp.setPreference("browser.privatebrowsing.autostart", true);
        }

        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability(FirefoxDriver.PROFILE, ffp);
        return new FirefoxDriver(capabilities);
    } else if (browser.equals(Browser.IE)) {
        System.setProperty("webdriver.ie.driver", ieDriverLocation);

        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();

        if (privateBrowsing) {
            System.err.println("Launching into browsing mode is not supported in IE.");
            return null;
        }

        return new InternetExplorerDriver();
    } else if (browser.equals(Browser.SAFARI)) {
        if (privateBrowsing) {
            System.out
                    .println("WARNING: Selenium does not support launching into Safari private browsing mode.");
            System.out
                    .println("         You will be given 10 seconds to transition into the private browsing ");
            System.out.println("         mode before the tests begin!");
        }

        return new SafariDriver();
    }

    return null;
}

From source file:at.ac.tuwien.big.testsuite.impl.selenium.BaseSeleniumTest.java

License:Apache License

protected final WebDriver createDriver() throws Exception {
    Exception exception = null;//from   w ww . j a  va 2s .  c  o m
    WebDriver webDriver = null;
    int tries = 0;

    while (tries < MAX_DRIVER_GET_RETRY) {
        try {
            if (chromeService != null) {
                webDriver = new RemoteWebDriver(chromeService.getUrl(), DesiredCapabilities.chrome());
            } else {
                webDriver = new ChromeDriver();
            }
        } catch (Exception ex) {
            exception = ex;

            try {
                webDriver = new FirefoxDriver();
            } catch (Exception ex1) {
                exception.addSuppressed(ex1);

                try {
                    webDriver = new SafariDriver();
                } catch (Exception ex2) {
                    exception.addSuppressed(ex2);

                    try {
                        if (ieService != null) {
                            webDriver = new RemoteWebDriver(ieService.getUrl(),
                                    DesiredCapabilities.internetExplorer());
                        } else {
                            webDriver = new InternetExplorerDriver();
                        }
                    } catch (Exception ex3) {
                        exception.addSuppressed(ex3);
                    }
                }
            }
        }

        if (webDriver != null) {
            break;
        }
    }

    if (webDriver == null) {
        throw new RuntimeException("Could not find a browser for testing", exception);
    }

    webDrivers.add(webDriver);
    webDriver.get(webappUrl);

    if (login != null) {
        user = login.doLogin(webDriver);

        if (user == null) {
            user = "";
            errorCollector.checkThat("Could not login", true, is(false));
        }
    }

    return webDriver;
}

From source file:com.comcast.magicwand.spells.web.safari.SafariPhoenixDriver.java

License:Apache License

/**
 * Creates an instance of a safari driver
 * @param dc Capabilities to use when creating a driver
 * @return driver//from  ww w.j  a v a2 s .  c o m
 */
protected SafariDriver createDriver(final DesiredCapabilities dc) {
    SafariDriver rv = null;

    if (null == dc) {
        rv = new SafariDriver();
    } else {
        rv = new SafariDriver(dc);
    }

    return rv;
}

From source file:com.consol.citrus.selenium.endpoint.SeleniumBrowser.java

License:Apache License

/**
 * Creates local web driver.//from  w  w w . j a  v a2 s .  c  o  m
 * @param browserType
 * @return
 */
private WebDriver createLocalWebDriver(String browserType) {
    switch (browserType) {
    case BrowserType.FIREFOX:
        FirefoxProfile firefoxProfile = getEndpointConfiguration().getFirefoxProfile();

        /* set custom download folder */
        firefoxProfile.setPreference("browser.download.dir", temporaryStorage.toFile().getAbsolutePath());

        DesiredCapabilities defaults = DesiredCapabilities.firefox();
        defaults.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        return new FirefoxDriver(defaults);
    case BrowserType.IE:
        return new InternetExplorerDriver();
    case BrowserType.EDGE:
        return new EdgeDriver();
    case BrowserType.SAFARI:
        return new SafariDriver();
    case BrowserType.CHROME:
        return new ChromeDriver();
    case BrowserType.GOOGLECHROME:
        return new ChromeDriver();
    case BrowserType.HTMLUNIT:
        BrowserVersion browserVersion = null;
        if (getEndpointConfiguration().getVersion().equals("FIREFOX")) {
            browserVersion = BrowserVersion.FIREFOX_45;
        } else if (getEndpointConfiguration().getVersion().equals("INTERNET_EXPLORER")) {
            browserVersion = BrowserVersion.INTERNET_EXPLORER;
        } else if (getEndpointConfiguration().getVersion().equals("EDGE")) {
            browserVersion = BrowserVersion.EDGE;
        } else if (getEndpointConfiguration().getVersion().equals("CHROME")) {
            browserVersion = BrowserVersion.CHROME;
        }

        HtmlUnitDriver htmlUnitDriver;
        if (browserVersion != null) {
            htmlUnitDriver = new HtmlUnitDriver(browserVersion);
        } else {
            htmlUnitDriver = new HtmlUnitDriver();
        }
        htmlUnitDriver.setJavascriptEnabled(getEndpointConfiguration().isJavaScript());
        return htmlUnitDriver;
    default:
        throw new CitrusRuntimeException("Unsupported local browser type: " + browserType);
    }
}

From source file:com.ecfeed.core.runner.java.SeleniumTestMethodInvoker.java

License:Open Source License

private void setDriverIntr(String browserName, String driverPath, MethodParameterNode methodParameterNode) {

    if (StringHelper.isEqualIgnoreCase(browserName, NodePropertyDefs.browserNameChrome())) {
        System.setProperty("webdriver.chrome.driver", driverPath);
        fDriver = new ChromeDriver();
        return;/*  w  ww.  ja  v  a 2 s.com*/
    }
    if (StringHelper.isEqualIgnoreCase(browserName, NodePropertyDefs.browserNameFirefox())) {
        System.setProperty("webdriver.gecko.driver", driverPath);
        fDriver = new FirefoxDriver();
        return;
    }
    if (StringHelper.isEqualIgnoreCase(browserName, NodePropertyDefs.browserNameIExplorer())) {
        System.setProperty("webdriver.ie.driver", driverPath);
        fDriver = new InternetExplorerDriver();
        return;
    }
    if (StringHelper.isEqualIgnoreCase(browserName, NodePropertyDefs.browserNameOpera())) {
        System.setProperty("webdriver.opera.driver", driverPath);
        fDriver = new OperaDriver();
        return;
    }
    if (StringHelper.isEqualIgnoreCase(browserName, NodePropertyDefs.browserNameSafari())) {
        fDriver = new SafariDriver();
        return;
    }

    reportException("WebDriver is not supported: " + browserName + ".", methodParameterNode);
}

From source file:com.electricsheeplabs.electricsheep.SelenPrompt.java

public static void main(String[] args) throws IOException {
    System.out.println("Selenium Shell 1.0.0");

    // System.out.println("Selenium Shell 1.0.0");
    System.out.println("Type 'help', 'copyright', 'credits' or 'license' for more information. ");

    int loop = 0;

    do {/*from  w  w  w.j  av a2s . c o m*/
        System.out.print("Selenium:>");

        // String input=System.console().readLine().trim();
        //WebDriver browsers = null;
        WebDriver browsers = new SafariDriver();
        //groovy.util.Eval.me("WebDriver browsers = null");

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String sInput = br.readLine().trim();

        System.out.println("Your entered: " + sInput);

        if (sInput.equalsIgnoreCase("ff")) {
            groovy.util.Eval.me("browsers = new FirefoxDriver()");
        } else if (sInput.equalsIgnoreCase("sa")) {
            groovy.util.Eval.me("browsers = new SafariDriver()");
        } else if (sInput.equalsIgnoreCase("q")) {
            groovy.util.Eval.me("browsers.close()");
            System.out.println("Quitting...");
        } else {
            groovy.util.Eval.me(sInput);
        }
    } while (loop < 20);

    //    try{
    //        int i = Integer.parseInt(br.readLine());
    //    }catch(NumberFormatException nfe){
    //        System.err.println("Invalid Format!");
    //    }
    //          
    //          
    //          
    //             do{
    //                   System.out.print("value of x : " + x );
    //                   x++;
    //                   System.out.print("\n");
    //                }while( x < 20 );
    // dr.get("http://google.com");
}

From source file:com.fmb.common.BrowserEmulator.java

License:Apache License

private void setupBrowserCoreType(int type) {
    if (type == 1) {
        browserCore = new FirefoxDriver();
        logger.info("Using Firefox");
        return;/* www  .j  a  v a 2s .  c o  m*/
    }
    if (type == 2) {
        chromeServer = new ChromeDriverService.Builder()
                .usingDriverExecutable(new File(GlobalSettings.chromeDriverPath)).usingAnyFreePort().build();
        try {
            chromeServer.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
        browserCore = new RemoteWebDriver(chromeServer.getUrl(), capabilities);
        logger.info("Using Chrome");
        return;
    }
    if (type == 3) {
        System.setProperty("webdriver.ie.driver", GlobalSettings.ieDriverPath);
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                true);
        browserCore = new InternetExplorerDriver(capabilities);
        logger.info("Using IE");
        return;
    }
    if (type == 4) {
        browserCore = new SafariDriver();
        logger.info("Using Safari");
        return;
    }

    Assert.fail("Incorrect browser type");
}

From source file:com.galenframework.browser.SeleniumBrowserFactory.java

License:Apache License

public static WebDriver getDriver(String browserType) {

    if (StringUtils.isEmpty(browserType) || FIREFOX.equals(browserType)) {
        return new FirefoxDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType));
    } else if (CHROME.equals(browserType)) {
        return new ChromeDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType));
    } else if (IE.equals(browserType)) {
        return new InternetExplorerDriver(SeleniumBrowserFactory.getBrowserCapabilities(browserType));
    } else if (PHANTOMJS.equals(browserType)) {
        return new PhantomJSDriver();
    } else if (SAFARI.equals(browserType)) {
        return new SafariDriver();
    } else if (EDGE.equals(browserType)) {
        return new EdgeDriver();
    } else {/*from w ww.jav  a  2  s  .co  m*/
        throw new RuntimeException(String.format("Unknown browser type: \"%s\"", browserType));
    }
}

From source file:com.galenframework.util.DriverTestFactory.java

License:Apache License

/**
 * Instantiate a new WebDriver instance, respects GalenConfig
 * /*  www .  ja v  a 2  s  .c  o m*/
 * @see GalenConfig
 * @return a new instance of the desired WebDriver
 */
public static WebDriver getDriver() {
    WebDriver driver = null;
    if (StringUtils.equalsIgnoreCase(GalenConfig.getConfig().getDefaultBrowser(), "chrome")) {
        driver = new ChromeDriver();
    } else {
        if (StringUtils.equalsIgnoreCase(GalenConfig.getConfig().getDefaultBrowser(), "safari")) {
            driver = new SafariDriver();
        } else {
            if (StringUtils.equalsIgnoreCase(GalenConfig.getConfig().getDefaultBrowser(), "iexplore")) {
                driver = new InternetExplorerDriver();
            } else {
                // default to firefox
                driver = new FirefoxDriver();
            }
        }
    }
    return driver;
}