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:com.ggasoftware.uitest.utils.WebDriverWrapper.java

License:Open Source License

/**
 * initialization SafariDriver/*from   w ww. j  a va 2  s  .  co m*/
 */
public static void initSafariDriver() {
    ReporterNGExt.logTechnical("Initialization Safari Driver");
    setWebDriver(new SafariDriver());
    setTimeout(TIMEOUT);
    getDriver().manage().window().maximize();
}

From source file:com.github.ccaspanello.selenium.example.integration.framework.WebDriverFactory.java

License:Apache License

public static WebDriver create(String browser) {
    if (browser.equalsIgnoreCase("firefox")) {
        return new FirefoxDriver();
    } else if (browser.equalsIgnoreCase("chrome")) {
        return new ChromeDriver();
    } else if (browser.equalsIgnoreCase("ie")) {
        return new InternetExplorerDriver();
    } else if (browser.equalsIgnoreCase("safari")) {
        return new SafariDriver();
    } else if (browser.equalsIgnoreCase("html")) {
        HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_38);
        htmlUnitDriver.setJavascriptEnabled(true);
        return htmlUnitDriver;
    } else {//w w w.  j ava2s.co m
        throw new IllegalArgumentException("The Browser Type is Undefined");
    }
}

From source file:com.google.caja.plugin.WebDriverHandle.java

License:Apache License

private static RemoteWebDriver makeDriver() {
    DesiredCapabilities dc = new DesiredCapabilities();

    String browserType = TestFlag.BROWSER.getString("firefox");

    if ("chrome".equals(browserType)) {
        // Chrome driver is odd in that the path to Chrome is specified
        // by a desiredCapability when you start a session. The other
        // browser drivers will read a java system property on start.
        // This applies to both remote Chrome and local Chrome.
        ChromeOptions chromeOpts = new ChromeOptions();
        String chromeBin = TestFlag.CHROME_BINARY.getString(null);
        if (chromeBin != null) {
            chromeOpts.setBinary(chromeBin);
        }// ww  w  .  j  av  a  2  s  . c  om
        String chromeArgs = TestFlag.CHROME_ARGS.getString(null);
        if (chromeArgs != null) {
            String[] args = chromeArgs.split(";");
            chromeOpts.addArguments(args);
        }
        dc.setCapability(ChromeOptions.CAPABILITY, chromeOpts);
    }

    String url = TestFlag.WEBDRIVER_URL.getString("");

    if (!"".equals(url)) {
        dc.setBrowserName(browserType);
        dc.setJavascriptEnabled(true);
        try {
            return new RemoteWebDriver(new URL(url), dc);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    } else if ("chrome".equals(browserType)) {
        return new ChromeDriver(dc);
    } else if ("firefox".equals(browserType)) {
        return new FirefoxDriver();
    } else if ("safari".equals(browserType)) {
        // TODO(felix8a): local safari doesn't work yet
        return new SafariDriver();
    } else {
        throw new RuntimeException("No local driver for browser type '" + browserType + "'");
    }
}

From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java

License:Open Source License

/**
 * Return the WebDriver/*from  w ww  .  j  a  v a 2  s  .c  o m*/
 * 
 * @return {WebDriver}
 */
public WebDriver getWebDriver() {
    // browser to test with
    assertTrue("Requesting webdriver while using the mock transport: " + System.getProperty("testMode"),
            System.getProperty("testMode") == null);
    String browserName = System.getProperty(PROP_BROWSER);
    if (webDriver == null) {
        logger.info("Creating WebDriver instance");
        if (StringUtil.isEmpty(System.getProperty(SELENIUM_HUB))) {

            if ("ie".equals(browserName)) {
                initInternetExplorerDriver();
            } else if ("chrome".equals(browserName)) {
                initChromeDriver();
            } else if ("safari".equals(browserName)) {
                webDriver = new SafariDriver();
            } else if ("headless".equals(browserName)) {
                HtmlUnitDriver driver = new HtmlUnitDriver(true);
                webDriver = driver;
            } else {
                webDriver = new FirefoxDriver();
            }
        } else {
            DesiredCapabilities cap = null;
            if ("ie".equals(browserName)) {
                cap = DesiredCapabilities.internetExplorer();
            } else if ("chrome".equals(browserName)) {
                cap = DesiredCapabilities.chrome();
            } else if ("safari".equals(browserName)) {
                cap = DesiredCapabilities.safari();
            } else if ("headless".equals(browserName)) {
                cap = DesiredCapabilities.htmlUnit();

            } else {
                cap = DesiredCapabilities.firefox();
            }
            cap.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
            cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            try {
                webDriver = new RemoteWebDriver(new URL(System.getProperty(SELENIUM_HUB)), cap);
                webDriver = new Augmenter().augment(webDriver);
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }

        }

    }
    return webDriver;
}

From source file:com.jaeksoft.searchlib.crawler.web.browser.SafariBrowserDriver.java

License:Open Source License

@Override
public SafariDriver initialize() {
    return new SafariDriver();
}

From source file:com.molo.dagger.BrowserEmulator.java

License:Apache License

private void setupBrowserCoreType(int type) {
    if (type == 1) {
        browserCore = new FirefoxDriver();
        logger.info("Using Firefox");
        return;//  w w w  .ja  v a  2  s .  co 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);
        browserCore = new ChromeDriver(chromeServer, 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.mycompany.firstmavenproject.DriverFactory.java

public static WebDriver create(String type) {
    WebDriver driver = null;/*w  ww .j  av a2  s .c o m*/

    if (type.contains("FirefoxDriver")) {
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    } else if (type.contains("ChromeDriver")) {
        driver = new ChromeDriver();
    } else if (type.contains("InternetExplorerDriver")) {
        driver = new InternetExplorerDriver();
    } else if (type.contains("OperaDriver")) {
        driver = new OperaDriver();
    } else if (type.contains("SafariDriver")) {
        driver = new SafariDriver();
    }
    return driver;
}

From source file:com.thoughtworks.selenium.corerunner.Main.java

License:Apache License

public static void main(String[] args) {
    //    java -jar selenium-server-standalone-<version-number>.jar -htmlSuite "*firefox"
    //    "http://www.google.com" "c:\absolute\path\to\my\HTMLSuite.html"
    //    "c:\absolute\path\to\my\results.html"
    if (args.length < 5) {
        throw new RuntimeException("Not enough arguments");
    }//from   ww w  .  j av  a  2 s .  c  om
    if (!"-htmlSuite".equals(args[0])) {
        throw new RuntimeException("Apparently not running a test suite");
    }

    WebDriver driver;
    switch (args[1]) {
    case "*chrome":
    case "*firefox":
    case "*firefoxproxy":
    case "*firefoxchrome":
    case "*pifirefox":
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(MARIONETTE, false);
        driver = new FirefoxDriver(caps);
        break;

    case "*iehta":
    case "*iexplore":
    case "*iexploreproxy":
    case "*piiexplore":
        driver = new InternetExplorerDriver();
        break;

    case "*googlechrome":
        driver = new ChromeDriver();
        break;

    case "*MicrosoftEdge":
        driver = new EdgeDriver();
        break;

    case "*opera":
    case "*operablink":
        driver = new OperaDriver();
        break;

    case "*safari":
    case "*safariproxy":
        driver = new SafariDriver();
        break;

    default:
        throw new RuntimeException("Unrecognized browser: " + args[1]);
    }

    try {
        Results results = new Results();
        CoreTest test = new CoreTest(args[3]);
        test.run(results, driver, new WebDriverBackedSelenium(driver, args[2]));
    } finally {
        driver.quit();
    }
}

From source file:com.vaadin.testbench.parallel.setup.LocalDriver.java

/**
 * Creates a {@link WebDriver} instance used for running the test locally
 * for debug purposes.//from  w ww .jav a  2 s  . c om
 */
static public WebDriver createDriver(DesiredCapabilities desiredCapabilities) {
    WebDriver driver;
    if (BrowserUtil.isFirefox(desiredCapabilities)) {
        String firefoxPath = System.getProperty("firefox.path");
        String profilePath = System.getProperty("firefox.profile.path");

        if (firefoxPath != null) {
            if (profilePath != null) {
                File profileDir = new File(profilePath);
                FirefoxProfile profile = new FirefoxProfile(profileDir);
                driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxPath)), profile);
            } else {
                driver = new FirefoxDriver(new FirefoxBinary(new File(firefoxPath)), null);
            }

        } else {
            driver = new FirefoxDriver();
        }
    } else if (BrowserUtil.isChrome(desiredCapabilities)) {
        // Tells chrome not to show warning
        // "You are using an unsupported command-line flag: --ignore-certifcate-errors".
        // #14319
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--test-type ");
        driver = new ChromeDriver(options);
    } else if (BrowserUtil.isSafari(desiredCapabilities)) {
        driver = new SafariDriver();
    } else if (BrowserUtil.isPhantomJS(desiredCapabilities)) {
        driver = new PhantomJSDriver();
    } else {
        throw new RuntimeException(
                "Not implemented support for running locally on " + desiredCapabilities.getBrowserName());
    }

    return TestBench.createDriver(driver);
}

From source file:com.winhong.dagger.BrowserEmulator.java

License:Apache License

private void setupBrowserCoreType(int type) {
    if (type == 1) {
        browserCore = new FirefoxDriver();
        logger.info("Using Firefox");
        return;/*from   w  w w  .  j  a  v a2 s.  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();
        String prox = GlobalSettings.prop.getProperty("http_proxy");
        if (prox != null) {
            capabilities.setCapability("chrome.switches",
                    Arrays.asList("--start-maximized", "--proxy-server=" + prox));
        } else {
            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");
}