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:SeleniumDriver.DriverFactory.java

/***
 * Fbrica de browser/*from  ww  w.j  a  v a2s . c o m*/
 * @psram browser CHROME
 * @return Webdriver directo para hacer uso
 */
public static WebDriver getDriver(int browser) {
    final int CHROME = 1;
    final int OPERA = 2;
    final int IEXPLORER = 3;
    final int SAFARI = 4;
    final int EDGE = 5;

    WebDriver driver = null;
    switch (browser) {
    case CHROME:
        driver = new ChromeDriver();
        break;
    case OPERA:
        driver = new OperaDriver();
        break;
    case IEXPLORER:
        driver = new InternetExplorerDriver();
        break;
    case SAFARI:
        driver = new SafariDriver();
        break;
    case EDGE:
        driver = new EdgeDriver();
        break;
    default:
        return new FirefoxDriver();

    }
    return driver;
}

From source file:shiver.me.timbers.security.test.CucumberConfiguration.java

License:Apache License

@Bean(destroyMethod = "quit")
public WebDriver webDriver(@Value("${web.driver:htmlunit}") String webDriver) {

    if ("htmlunit".equals(webDriver)) {
        return new HtmlUnitDriver();
    }// w  w w .j a va  2s .c om

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

    if ("firefox".equals(webDriver)) {
        return new FirefoxDriver();
    }

    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:steps.hooks.SharedDriver.java

License:Apache License

private static WebDriver getCurrentDriver() {
    // We allow different drivers to be used in the same test run.
    String webDriverType = System.getProperty("WebDriverType");
    if (webDriverType.equals("Chrome")) {
        if (REAL_FIREFOX_DRIVER != null) {
            REAL_FIREFOX_DRIVER.close();
            REAL_FIREFOX_DRIVER = null;//from   w ww .  jav a  2 s. c  o m
        }
        if (REAL_HTMLUNIT_DRIVER != null) {
            REAL_HTMLUNIT_DRIVER.close();
            REAL_HTMLUNIT_DRIVER = null;
        }
        if (REAL_SAFARI_DRIVER != null) {
            REAL_SAFARI_DRIVER.close();
            REAL_SAFARI_DRIVER = null;
        }
        if (REAL_IPAD_DRIVER != null) {
            REAL_IPAD_DRIVER.close();
            REAL_IPAD_DRIVER = null;
        }
        if (REAL_CHROME_DRIVER == null) {
            REAL_CHROME_DRIVER = new ChromeDriver();
        }
        return REAL_CHROME_DRIVER;
    } else if (webDriverType.equals("Firefox")) {
        if (REAL_CHROME_DRIVER != null) {
            REAL_CHROME_DRIVER.close();
            REAL_CHROME_DRIVER = null;
        }
        if (REAL_HTMLUNIT_DRIVER != null) {
            REAL_HTMLUNIT_DRIVER.close();
            REAL_HTMLUNIT_DRIVER = null;
        }
        if (REAL_SAFARI_DRIVER != null) {
            REAL_SAFARI_DRIVER.close();
            REAL_SAFARI_DRIVER = null;
        }
        if (REAL_IPAD_DRIVER != null) {
            REAL_IPAD_DRIVER.close();
            REAL_IPAD_DRIVER = null;
        }
        if (REAL_FIREFOX_DRIVER == null) {
            REAL_FIREFOX_DRIVER = new FirefoxDriver();
        }
        return REAL_FIREFOX_DRIVER;
    } else if (webDriverType.equals("HtmlUnit")) {
        if (REAL_CHROME_DRIVER != null) {
            REAL_CHROME_DRIVER.close();
            REAL_CHROME_DRIVER = null;
        }
        if (REAL_FIREFOX_DRIVER != null) {
            REAL_FIREFOX_DRIVER.close();
            REAL_FIREFOX_DRIVER = null;
        }
        if (REAL_SAFARI_DRIVER != null) {
            REAL_SAFARI_DRIVER.close();
            REAL_SAFARI_DRIVER = null;
        }
        if (REAL_IPAD_DRIVER != null) {
            REAL_IPAD_DRIVER.close();
            REAL_IPAD_DRIVER = null;
        }
        if (REAL_HTMLUNIT_DRIVER == null) {
            String javascriptEnabled = System.getProperty("WebDriverJavascriptEnabled");
            REAL_HTMLUNIT_DRIVER = new HtmlUnitDriver(javascriptEnabled.equals("true") ? true : false);
        }
        return REAL_HTMLUNIT_DRIVER;
    } else if (webDriverType.equals("Safari")) {
        if (REAL_CHROME_DRIVER != null) {
            REAL_CHROME_DRIVER.close();
            REAL_CHROME_DRIVER = null;
        }
        if (REAL_FIREFOX_DRIVER != null) {
            REAL_FIREFOX_DRIVER.close();
            REAL_FIREFOX_DRIVER = null;
        }
        if (REAL_HTMLUNIT_DRIVER != null) {
            REAL_HTMLUNIT_DRIVER.close();
            REAL_HTMLUNIT_DRIVER = null;
        }
        if (REAL_IPAD_DRIVER != null) {
            REAL_IPAD_DRIVER.close();
            REAL_IPAD_DRIVER = null;
        }
        if (REAL_SAFARI_DRIVER == null) {
            REAL_SAFARI_DRIVER = new SafariDriver();
        }
        return REAL_SAFARI_DRIVER;
    } else if (webDriverType.equals("Ipad")) {
        if (REAL_CHROME_DRIVER != null) {
            REAL_CHROME_DRIVER.close();
            REAL_CHROME_DRIVER = null;
        }
        if (REAL_HTMLUNIT_DRIVER != null) {
            REAL_HTMLUNIT_DRIVER.close();
            REAL_HTMLUNIT_DRIVER = null;
        }
        if (REAL_SAFARI_DRIVER != null) {
            REAL_SAFARI_DRIVER.close();
            REAL_SAFARI_DRIVER = null;
        }
        if (REAL_FIREFOX_DRIVER != null) {
            REAL_FIREFOX_DRIVER.close();
            REAL_FIREFOX_DRIVER = null;
        }
        if (REAL_IPAD_DRIVER == null) {
            // This uses Appium as a remote webdriver
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.setCapability("deviceName", "iPad 2");
            // Or can use, e.g., iPhone via:
            // desiredCapabilities.setCapability("deviceName", "iPhone 6");
            desiredCapabilities.setCapability("platformName", "iOS");
            desiredCapabilities.setCapability("platformVersion", "9.2");
            desiredCapabilities.setCapability("browserName", "safari");
            URL url = null;
            try {
                // Url of the Appium server
                url = new URL("http://127.0.0.1:4723/wd/hub");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            REAL_IPAD_DRIVER = new IOSDriver<>(url, desiredCapabilities);
        }
        return REAL_IPAD_DRIVER;
    } else {
        fail("Invalid WebDriverType: " + webDriverType);
    }

    // Should not get here
    return null;
}

From source file:Utility.General.java

License:Open Source License

public static WebDriver GetBrowser(String driverName) {

    WebDriver driver = null;//  w  w  w  .  j  a v  a2s  . c om

    switch (driverName) {
    case "IE":
        System.setProperty("webdriver.ie.driver", new General().LoadProperties().getProperty("ieDriver"));
        driver = new InternetExplorerDriver();
        break;
    case "Firefox":
        driver = new FirefoxDriver();
        break;
    case "Chrome":
        System.setProperty("webdriver.chrome.driver",
                new General().LoadProperties().getProperty("chromeDriver"));
        ChromeOptions options = new ChromeOptions();
        options.addArguments("test-type");
        driver = new ChromeDriver(options);
        break;
    case "Safari":
        driver = new SafariDriver();
        break;
    }
    Log.info("Connnection opened using " + driverName + " browser.");

    return driver;
}

From source file:utils.SelectBrowser.java

public static WebDriver getBrowser() throws IOException {
    WebDriver driver = null;//from  ww  w  . j av a  2s .  c  o  m

    FileReader reader = new FileReader("../seleniumWebdriverProjectTemplate/config.properties"); //Reading configuration file
    Properties prop = new Properties();
    prop.load(reader);
    String browser = prop.getProperty("driverName"); // Assigning String value form configuraion file
    //String ver = prop.getProperty("version");        // Assigning String value form configuraion file

    if (browser.equalsIgnoreCase("ieWinx32")) {
        //String path=System.getProperty("user.dir") +File.separator + "Browsers"+ File.separator +"IEDriverServer.exe";
        System.setProperty("webdriver.ie.driver",
                "../seleniumWebdriverProjectTemplate/webdrivers/IEDriverServer_x32_v2.43.0.exe"); // setting path of the IEDriver
        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                true);
        driver = new InternetExplorerDriver(ieCapabilities);
        //         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        //         Alert alert = driver.switchTo().alert();
        //         String alertText = alert.getText().trim(); 
        //          alert.accept(); 
        //         alert.dismiss()
    } else if (browser.equalsIgnoreCase("ieWinx64")) {
        //String path=System.getProperty("user.dir") +File.separator + "Browsers"+ File.separator +"IEDriverServer.exe";
        System.setProperty("webdriver.ie.driver",
                "../seleniumWebdriverProjectTemplate/webdrivers/IEDriverServer_x64_v2.43.0.exe"); // setting path of the IEDriver
        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                true);
        driver = new InternetExplorerDriver(ieCapabilities);
    } else if (browser.equalsIgnoreCase("firefox")) {
        driver = new FirefoxDriver();
    } else if (browser.equalsIgnoreCase("safari")) {
        driver = new SafariDriver();
    } else if (browser.equalsIgnoreCase("chromeWinx32")) {
        //String path=System.getProperty("user.dir") +File.separator + "Browsers"+ File.separator +"chromedriver.exe";
        //System.out.println(path);
        System.setProperty("webdriver.chrome.driver",
                "../seleniumWebdriverProjectTemplate/webdrivers/chromedriver_x32_v2.10.exe"); // setting path of the ChromeDriver
        driver = new ChromeDriver();
    } else if (browser.equalsIgnoreCase("chromeMac32")) {
        //String path=System.getProperty("user.dir") +File.separator + "Browsers"+ File.separator +"chromedriver.exe";
        //System.out.println(path);
        System.setProperty("webdriver.chrome.driver",
                "../seleniumWebdriverProjectTemplate/webdrivers/chromedriver_mac32_v2.10"); // setting path of the ChromeDriver
        driver = new ChromeDriver();
    } else if (browser.equalsIgnoreCase("chromeLinux64")) {
        //String path=System.getProperty("user.dir") +File.separator + "Browsers"+ File.separator +"chromedriver.exe";
        //System.out.println(path);
        System.setProperty("webdriver.chrome.driver",
                "../seleniumWebdriverProjectTemplate/webdrivers/chromedriver_linux64_v2.10"); // setting path of the ChromeDriver
        driver = new ChromeDriver();
    }
    return driver;
}

From source file:xmv.solutions.IT2JZ.Jira.Jira.java

/**
 * open Browser/*from  www . j a  v a 2  s  .  c o m*/
 *
 * @param toUse select Browser toUse from Enum
 */
private void openBrowser() {

    try {

        switch (browserToUse) {

        case Chrome:
            browserSession = new ChromeDriver();
            break;

        case Edge:
            browserSession = new EdgeDriver();
            break;

        case InternetExplorer:
            browserSession = new InternetExplorerDriver();
            break;

        case Safari:
            browserSession = new SafariDriver();
            break;

        case Firefox:
            browserSession = new FirefoxDriver();
            break;

        case HtmlUnitDriver:
        default:
            browserSession = new HtmlUnitDriver();

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}