Java Code Examples for org.openqa.selenium.safari.SafariDriver

The following are top voted examples for showing how to use org.openqa.selenium.safari.SafariDriver. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: selenium-cucumber-framework   File: BrowserFactory.java   View source code 7 votes vote down vote up
public static WebDriver selectLocalBrowser() {
	switch (browser) {
	case Chrome:
		return new ChromeDriver();
	case Firefox:
		return new FirefoxDriver();
	case IE:
		return new InternetExplorerDriver();
	case Opera:
		return new OperaDriver();
	case Safari:
		return new SafariDriver();
	default:
		throw new WebDriverException("No browser specified");
	}
}
 
Example 2
Project: selenium-jupiter   File: SeleniumExtension.java   View source code 6 votes vote down vote up
public SeleniumExtension() {
    handlerMap.put(ChromeDriver.class, ChromeDriverHandler.class);
    handlerMap.put(FirefoxDriver.class, FirefoxDriverHandler.class);
    handlerMap.put(EdgeDriver.class, EdgeDriverHandler.class);
    handlerMap.put(OperaDriver.class, OperaDriverHandler.class);
    handlerMap.put(SafariDriver.class, SafariDriverHandler.class);
    handlerMap.put(RemoteWebDriver.class, RemoteDriverHandler.class);
    handlerMap.put(AppiumDriver.class, AppiumDriverHandler.class);
    handlerMap.put(List.class, ListDriverHandler.class);
    handlerMap.put(PhantomJSDriver.class, OtherDriverHandler.class);

    templateHandlerMap.put("chrome", ChromeDriver.class);
    templateHandlerMap.put("firefox", FirefoxDriver.class);
    templateHandlerMap.put("edge", EdgeDriver.class);
    templateHandlerMap.put("opera", OperaDriver.class);
    templateHandlerMap.put("safari", SafariDriver.class);
    templateHandlerMap.put("appium", AppiumDriver.class);
    templateHandlerMap.put("phantomjs", PhantomJSDriver.class);
    templateHandlerMap.put("chrome-in-docker", RemoteWebDriver.class);
    templateHandlerMap.put("firefox-in-docker", RemoteWebDriver.class);
    templateHandlerMap.put("opera-in-docker", RemoteWebDriver.class);
}
 
Example 3
Project: selenium-jupiter   File: SafariDriverHandler.java   View source code 6 votes vote down vote up
@Override
public void resolve() {
    try {
        Optional<Object> testInstance = context.getTestInstance();
        Optional<Capabilities> capabilities = annotationsReader
                .getCapabilities(parameter, testInstance);
        SafariOptions safariOptions = (SafariOptions) getOptions(parameter,
                testInstance);
        if (capabilities.isPresent()) {
            safariOptions.merge(capabilities.get());
        }
        object = new SafariDriver(safariOptions);
    } catch (Exception e) {
        handleException(e);
    }
}
 
Example 4
Project: apache-archiva   File: WebDriverBrowseTest.java   View source code 6 votes vote down vote up
@Override
public WebDriver getDefaultDriver()
{
    String seleniumBrowser = System.getProperty( "selenium.browser" );

    if ( StringUtils.contains( seleniumBrowser, "chrome" ) )
    {
        return new ChromeDriver();
    }

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

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

}
 
Example 5
Project: apache-archiva   File: WebDriverTest.java   View source code 6 votes vote down vote up
@Override
public WebDriver getDefaultDriver()
{
    String seleniumBrowser = System.getProperty( "selenium.browser" );

    if ( StringUtils.contains( seleniumBrowser, "chrome" ) )
    {
        return new ChromeDriver();
    }

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

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

    return new FirefoxDriver();

}
 
Example 6
Project: chr-krenn-fhj-ws2016-sd14-pse   File: BaseUITest.java   View source code 6 votes vote down vote up
WebDriver start(Capabilities capabilities) {
    switch (this) {
        case FIREFOX:
            return new FirefoxDriver(capabilities);
        case HTML_UNIT:
            return new HtmlUnitDriver(capabilities);
        case CHROME:
            return new ChromeDriver(capabilities);
        case EDGE:
            return new EdgeDriver(capabilities);
        case INTERNET_EXPLORER:
            return new InternetExplorerDriver(capabilities);
        case SAFARI:
            return new SafariDriver(capabilities);
        default:
            throw new AssertionError();
    }
}
 
Example 7
Project: seleniumtestsframework   File: SafariDriverFactory.java   View source code 6 votes vote down vote up
@Override
public WebDriver createWebDriver() {
    DesiredCapabilities cap = new SafariCapabilitiesFactory().createCapabilities(webDriverConfig);
    System.out.println("Begin Safari");
    synchronized (this.getClass()) {
        driver = new SafariDriver(cap);
    }

    System.out.println("safari started");

    this.setWebDriver(driver);

    // Implicit Waits handles dynamic element.
    setImplicitWaitTimeout(webDriverConfig.getImplicitWaitTimeout());
    if (webDriverConfig.getPageLoadTimeout() >= 0) {
        TestLogging.log("Safari doesn't support pageLoadTimeout");
    }

    return driver;
}
 
Example 8
Project: seleniumcapsules   File: DragAndDropTest.java   View source code 6 votes vote down vote up
@Test
public void dragAndDropSafari() throws InterruptedException {
    WebDriver driver = new SafariDriver();
    driver.get("http://www.w3schools.com/html/html5_draganddrop.asp");
    WebElement source = driver.findElement(id("drag1"));
    System.out.println(source.getAttribute("src"));
    WebElement target = driver.findElement(id("div2"));
    System.out.println(target.getTagName() + "=" + target.toString());

    Actions builder = new Actions(driver);

    Action dragAndDrop = builder.clickAndHold(source)
            .moveToElement(target)
            .release(source)
            .build();
    dragAndDrop.perform();
}
 
Example 9
Project: galen   File: SeleniumBrowserFactory.java   View source code 6 votes vote down vote up
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 {
        throw new RuntimeException(String.format("Unknown browser type: \"%s\"", browserType));
    }
}
 
Example 10
Project: SeleniumFramework   File: Browser.java   View source code 6 votes vote down vote up
/**
 * This method initialises the ThreadLocal WebDriver object according to the
 * supplied parameters to enable tests to run on a users local machine.
 */
private void setLocalWebdriver() {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("handlesAlerts", true);
    switch (getBrowserId(browser)) {
        case 0:
            capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                    Boolean.valueOf(System.getProperty("IGNORE_SECURITY_DOMAINS", "false")));
            driver.set(new InternetExplorerDriver(capabilities));
            break;
        case 1:
            driver.set(new FirefoxDriver(capabilities));
            break;
        case 2:
            driver.set(new SafariDriver(capabilities));
            break;
        case 3:
            driver.set(new ChromeDriver(capabilities));
            break;
        default:
            throw new WebDriverException("Browser not found: " + browser);
    }
}
 
Example 11
Project: SeleniumFramework   File: BaseTest.java   View source code 6 votes vote down vote up
/**
 * This method initialises the ThreadLocal WebDriver object according to the
 * supplied parameters to enable tests to run on a users local machine.
 *
 * @param browser  This can be set to "chrome", "internet explorer" or "firefox"
 * @param version  This should be set to reflect the browser required. It is only
 *                 used when matching capabilities for a RemoteWebDriver object
 *                 however.
 * @param platform This should be set to whatever platform the test is required
 *                 to run on e.g. "WINDOWS", "MAC", "LINUX". It is only used when
 *                 matching capabilities for a RemoteWebDriver object however.
 */
public void setLocalWebdriver(String browser, String version,
                              String platform) {

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("handlesAlerts", true);
    switch (getBrowserId(browser)) {
        case 0:
            capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                    Boolean.valueOf(System.getProperty("IGNORE_SECURITY_DOMAINS", "false")));
            driver.set(new InternetExplorerDriver(capabilities));
            break;
        case 1:
            driver.set(new FirefoxDriver(capabilities));
            break;
        case 2:
            driver.set(new SafariDriver(capabilities));
            break;
        case 3:
            driver.set(new ChromeDriver(capabilities));
            break;
        default:
            throw new WebDriverException("Browser not found: " + browser);
    }
}
 
Example 12
Project: Learning-Spring-Boot-2.0-Second-Edition   File: SafariDriverFactory.java   View source code 5 votes vote down vote up
@Override
public SafariDriver getObject() throws BeansException {
	if (properties.getSafari().isEnabled()) {
		try {
			return new SafariDriver();
		} catch (WebDriverException e) {
			e.printStackTrace();
			// swallow the exception
		}
	}
	return null;
}
 
Example 13
Project: Learning-Spring-Boot-2.0-Second-Edition   File: WebDriverAutoConfigurationTests.java   View source code 5 votes vote down vote up
@Test
public void testWithMockedSafari() {
	load(new Class[]{MockSafariConfiguration.class},
		"com.greglturnquist.webdriver.firefox.enabled:false",
		"com.greglturnquist.webdriver.chrome.enabled:false");
	WebDriver driver = context.getBean(WebDriver.class);
	assertThat(ClassUtils.isAssignable(TakesScreenshot.class,
		driver.getClass())).isTrue();
	assertThat(ClassUtils.isAssignable(SafariDriver.class,
		driver.getClass())).isTrue();
}
 
Example 14
Project: selenium-jupiter   File: ForcedAnnotationReaderTest.java   View source code 5 votes vote down vote up
static Stream<Arguments> forcedTestProvider() {
    return Stream.of(
            Arguments.of(AppiumDriverHandler.class,
                    ForcedAppiumJupiterTest.class, AppiumDriver.class,
                    "appiumNoCapabilitiesTest"),
            Arguments.of(AppiumDriverHandler.class,
                    ForcedAppiumJupiterTest.class, AppiumDriver.class,
                    "appiumWithCapabilitiesTest"),
            Arguments.of(ChromeDriverHandler.class,
                    ForcedBadChromeJupiterTest.class, ChromeDriver.class,
                    "chromeTest"),
            Arguments.of(FirefoxDriverHandler.class,
                    ForcedBadFirefoxJupiterTest.class, FirefoxDriver.class,
                    "firefoxTest"),
            Arguments.of(RemoteDriverHandler.class,
                    ForcedBadRemoteJupiterTest.class, RemoteWebDriver.class,
                    "remoteTest"),
            Arguments.of(EdgeDriverHandler.class,
                    ForcedEdgeJupiterTest.class, EdgeDriver.class,
                    "edgeTest"),
            Arguments.of(OperaDriverHandler.class,
                    ForcedOperaJupiterTest.class, OperaDriver.class,
                    "operaTest"),
            Arguments.of(SafariDriverHandler.class,
                    ForcedSafariJupiterTest.class, SafariDriver.class,
                    "safariTest"));
}
 
Example 15
Project: selenium-jupiter   File: SafariAnnotationReaderTest.java   View source code 5 votes vote down vote up
@ParameterizedTest
@MethodSource("testClassProvider")
@SuppressWarnings("deprecation")
void testSafariOptions(Class<?> testClass) throws Exception {
    Parameter parameter = testClass
            .getMethod("safariTest", SafariDriver.class).getParameters()[0];
    Optional<Object> testInstance = Optional.of(testClass.newInstance());
    SafariOptions safariOptions = (SafariOptions) annotationsReader
            .getOptions(parameter, testInstance);

    assertTrue(safariOptions.getUseCleanSession());
    assertFalse(safariOptions.getUseTechnologyPreview());
}
 
Example 16
Project: Java-Testing-Toolbox   File: SafariConfiguration.java   View source code 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SafariDriver start(Capabilities other) {
    Capabilities capabilities = this.mergeCapabilities(other);

    if (capabilities == null) {
        return new SafariDriver();
    }

    return new SafariDriver(capabilities);
}
 
Example 17
Project: Java-Testing-Toolbox   File: SeleniumConfiguration.java   View source code 5 votes vote down vote up
/**
 * Load the default configuration. It will not erase previous non-default configurations.
 * 
 * @return Itself.
 */
public SeleniumConfiguration loadDefaultConfiguration() {
    this.getConfiguration().put(ChromeDriver.class, new ChromeConfiguration());
    this.getConfiguration().put(EdgeDriver.class, new EdgeConfiguration());
    this.getConfiguration().put(FirefoxDriver.class, new FirefoxConfiguration());
    this.getConfiguration().put(HtmlUnitConfiguration.class, new HtmlUnitConfiguration());
    this.getConfiguration().put(InternetExplorerConfiguration.class, new InternetExplorerConfiguration());
    this.getConfiguration().put(OperaConfiguration.class, new OperaConfiguration());
    this.getConfiguration().put(PhantomJSConfiguration.class, new PhantomJSConfiguration());
    this.getConfiguration().put(SafariDriver.class, new SafariConfiguration());

    return this;
}
 
Example 18
Project: AutomationFrameworkTPG   File: DriverProperties.java   View source code 5 votes vote down vote up
private WebDriver initSafariDriver(String appURL) {
	System.out.println("Launching Safari browser..");
	WebDriver driver = new SafariDriver();
	driver.manage().window().maximize();
	driver.navigate().to(appURL);
	return new WebDriverProxy().protect(driver);
}
 
Example 19
Project: selenium-example   File: SafariTest.java   View source code 5 votes vote down vote up
@Before
public void prepare() {

    testUrl = "https://leftstick.github.io/";

    driver = new SafariDriver();
    driver.manage().window().maximize();
    driver.get(testUrl);
}
 
Example 20
Project: webdrivermanager   File: OtherWebDriverTest.java   View source code 5 votes vote down vote up
@Parameters(name = "{index}: {0} {1}")
public static Collection<Object[]> data() {
    return asList(new Object[][] {
            { SafariDriver.class, WebDriverException.class },
            { EventFiringWebDriver.class, InstantiationException.class },
            { HtmlUnitDriver.class, null },
            { RemoteWebDriver.class, IllegalAccessException.class } });
}
 
Example 21
Project: kc-rice   File: WebDriverUtils.java   View source code 5 votes vote down vote up
/**
 * <p>
 * remote.public.driver set to chrome or firefox (null assumes firefox).
 * </p><p>
 * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid)
 * if proxy.host is set, the web driver is setup to use a proxy
 * </p>
 *
 * @return WebDriver or null if unable to create
 */
public static WebDriver getWebDriver() {
    String driverParam = System.getProperty(HUB_DRIVER_PROPERTY);
    String hubParam = System.getProperty(HUB_PROPERTY);
    String proxyParam = System.getProperty(PROXY_HOST_PROPERTY);

    // setup proxy if specified as VM Arg
    DesiredCapabilities capabilities = new DesiredCapabilities();
    WebDriver webDriver = null;
    if (StringUtils.isNotEmpty(proxyParam)) {
        capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam));
    }

    if (hubParam == null) {
        if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
            FirefoxProfile profile = new FirefoxProfile();
            profile.setEnableNativeEvents(false);
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            return new FirefoxDriver(capabilities);
        } else if ("chrome".equalsIgnoreCase(driverParam)) {
            return new ChromeDriver(capabilities);
        } else if ("safari".equals(driverParam)) {
            System.out.println("SafariDriver probably won't work, if it does please contact Erik M.");
            return new SafariDriver(capabilities);
        }
    } else {
        try {
            if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.firefox());
            } else if ("chrome".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.chrome());
            }
        } catch (MalformedURLException mue) {
            System.out.println(getHubUrlString() + " " + mue.getMessage());
            mue.printStackTrace();
        }
    }
    return null;
}
 
Example 22
Project: frameworkium-core   File: SafariImpl.java   View source code 5 votes vote down vote up
@Override
public WebDriver getWebDriver(Capabilities capabilities) {
    if (Driver.isMobile()) {
        throw new IllegalArgumentException(
                "seleniumGridURL or sauceUser and sauceKey must be specified when running on iOS");
    } else {
        return new SafariDriver(new SafariOptions(capabilities));
    }
}
 
Example 23
Project: hsac-fitnesse-fixtures   File: SeleniumHelper.java   View source code 5 votes vote down vote up
/**
 * @return true when current driver is connected to either a local or remote Safari.
 */
public boolean connectedToSafari() {
    boolean result = false;
    WebDriver driver = driver();
    if (driver instanceof SafariDriver) {
        result = true;
    } else if (driver instanceof RemoteWebDriver) {
        result = checkRemoteBrowserName(driver, "safari");
    }
    return result;
}
 
Example 24
Project: desert   File: WebDriverFactory.java   View source code 5 votes vote down vote up
private static WebDriver createLocalDriver(Capabilities capabilities) {
	String browserType = capabilities.getBrowserName();
	if (browserType.equals(BrowserType.FIREFOX))
		return new FirefoxDriver(capabilities);
	if (browserType.equals(BrowserType.IE))
		return new InternetExplorerDriver(capabilities);
	if (browserType.equals(BrowserType.CHROME))
		return new ChromeDriver(capabilities);
	if (browserType.equals(BrowserType.SAFARI))
		return new SafariDriver(capabilities);

	throw new Error("Unsupported browser type: " + browserType);
}
 
Example 25
Project: rice   File: WebDriverUtils.java   View source code 5 votes vote down vote up
/**
 * <p>
 * remote.public.driver set to chrome or firefox (null assumes firefox).
 * </p><p>
 * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid)
 * if proxy.host is set, the web driver is setup to use a proxy
 * </p>
 *
 * @return WebDriver or null if unable to create
 */
public static WebDriver getWebDriver() {
    String driverParam = System.getProperty(HUB_DRIVER_PROPERTY);
    String hubParam = System.getProperty(HUB_PROPERTY);
    String proxyParam = System.getProperty(PROXY_HOST_PROPERTY);

    // setup proxy if specified as VM Arg
    DesiredCapabilities capabilities = new DesiredCapabilities();
    WebDriver webDriver = null;
    if (StringUtils.isNotEmpty(proxyParam)) {
        capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam));
    }

    if (hubParam == null) {
        if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
            FirefoxProfile profile = new FirefoxProfile();
            profile.setEnableNativeEvents(false);
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            return new FirefoxDriver(capabilities);
        } else if ("chrome".equalsIgnoreCase(driverParam)) {
            return new ChromeDriver(capabilities);
        } else if ("safari".equals(driverParam)) {
            System.out.println("SafariDriver probably won't work, if it does please contact Erik M.");
            return new SafariDriver(capabilities);
        }
    } else {
        try {
            if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.firefox());
            } else if ("chrome".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.chrome());
            }
        } catch (MalformedURLException mue) {
            System.out.println(getHubUrlString() + " " + mue.getMessage());
            mue.printStackTrace();
        }
    }
    return null;
}
 
Example 26
Project: selenium-java-robot   File: LocalRobotizedBrowserFactory.java   View source code 5 votes vote down vote up
@Override
public RemoteWebDriver createWebDriver() {
    SafariDriver safari = new SafariDriver();
    if (OS.isFamilyMac()) {
        try {
            // put the browser in the foreground:
            String cmdline = "open -a safari";
            SeleniumJavaRobot.log("Executing: " + cmdline);
            Runtime.getRuntime().exec(cmdline);
        } catch (Exception e) {
        }
    }
    return safari;
}
 
Example 27
Project: darcy-webdriver   File: SafariBrowserFactoryTest.java   View source code 5 votes vote down vote up
@Test
public void shouldBeInstanceOfUntargetedSafariDriver() {
    WebDriverBrowserFactory browserFactory = new SafariBrowserFactory();

    browser = (WebDriverBrowser) browserFactory.newBrowser();
    ForwardingTargetedWebDriver webDriver = (ForwardingTargetedWebDriver) browser.getWrappedDriver();
    CachingTargetLocator targetLocator = (CachingTargetLocator) webDriver.getTargetLocator();

    assertThat(targetLocator.getUntargetedDriver(), instanceOf(SafariDriver.class));
}
 
Example 28
Project: seleniumcapsules   File: BrowserTest.java   View source code 5 votes vote down vote up
@Test
public void findHowItWorksLinkUsingPartialLinkText() {
    WebDriver driver = new SafariDriver();
    driver.get("http://ticketfly.com/careers");
    WebElement element = driver.findElement(By.linkText("How It Works"));
    System.out.println("element=" + element);
    System.out.println("element.getTagName()=" + element.getTagName());
    System.out.println("element.getText()=" + element.getText());
}
 
Example 29
Project: gga-selenium-framework   File: WebDriverWrapper.java   View source code 5 votes vote down vote up
/**
 * initialization SafariDriver
 *
 * @param capabilities - desired capabilities
 */
public static void initSafariDriver(Capabilities capabilities) {
    ReporterNGExt.logTechnical("Initialization Safari Driver");
    setWebDriver(new SafariDriver(capabilities));
    setTimeout(TIMEOUT);
    getDriver().manage().window().maximize();
}
 
Example 30
Project: gga-selenium-framework   File: WebDriverWrapper.java   View source code 5 votes vote down vote up
/**
 * initialization SafariDriver
 */
public static void initSafariDriver() {
    ReporterNGExt.logTechnical("Initialization Safari Driver");
    setWebDriver(new SafariDriver());
    setTimeout(TIMEOUT);
    getDriver().manage().window().maximize();
}
 
Example 31
Project: wisdom   File: WisdomFluentLeniumTest.java   View source code 5 votes vote down vote up
@Override
public WebDriver getDefaultDriver() {
    String browser = System.getProperty("fluentlenium.browser");
    LOGGER.debug("Selecting Selenium Browser using " + browser);
    if (browser == null) {
        LOGGER.debug("Using default HTML Unit Driver");
        return new HtmlUnitDriver();
    }

    if ("chrome".equalsIgnoreCase(browser)) {
        LOGGER.debug("Using Chrome");
        return new ChromeDriver();
    }

    if ("firefox".equalsIgnoreCase(browser)) {
        LOGGER.debug("Using Firefox");
        return new FirefoxDriver();
    }

    if ("ie".equalsIgnoreCase(browser) || "internetexplorer".equalsIgnoreCase(browser)) {
        LOGGER.debug("Using Internet Explorer");
        return new InternetExplorerDriver();
    }

    if ("safari".equalsIgnoreCase(browser)) {
        LOGGER.debug("Using Safari");
        return new SafariDriver();
    }

    throw new IllegalArgumentException("Unknown browser : " + browser);
}
 
Example 32
Project: Testy   File: WebDriverConfig.java   View source code 5 votes vote down vote up
public static void init(WebDriver driver) {
    if (driver != null) {
        LOGGER.info("===============================================================");
        LOGGER.info("|          Open Selenium Web Driver ");
        LOGGER.info("===============================================================\n");
        WebDriverConfig.driver = driver;
        WebLocator.setDriverExecutor(driver);
        if (driver instanceof InternetExplorerDriver) {
            isIE = true;
        } else if (driver instanceof ChromeDriver) {
            isChrome = true;
        } else if (driver instanceof FirefoxDriver) {
            isFireFox = true;
        } else if (driver instanceof SafariDriver) {
            isSafari = true;
        } else if (driver instanceof OperaDesktopDriver) {
            isOpera = true;
        }

        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(WebLocatorConfig.getInt("driver.implicitlyWait"), TimeUnit.MILLISECONDS);

        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                if (WebLocatorConfig.getBoolean("driver.autoClose")) {
                    initSeleniumEnd();
                }
            }
        });
    }
}
 
Example 33
Project: kuali_rice   File: WebDriverUtil.java   View source code 5 votes vote down vote up
/**
 * remote.public.driver set to chrome or firefox (null assumes firefox)
 * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid)
 * if proxy.host is set, the web driver is setup to use a proxy
 * @return WebDriver or null if unable to create
 */
public static WebDriver getWebDriver() {
    String driverParam = System.getProperty(ITUtil.HUB_DRIVER_PROPERTY);
    String hubParam = System.getProperty(ITUtil.HUB_PROPERTY);
    String proxyParam = System.getProperty(PROXY_HOST_PROPERTY);

    // setup proxy if specified as VM Arg
    DesiredCapabilities capabilities = new DesiredCapabilities();
    WebDriver webDriver = null;
    if (StringUtils.isNotEmpty(proxyParam)) {
        capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam));
    }

    if (hubParam == null) {
        if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
            FirefoxProfile profile = new FirefoxProfile();
            profile.setEnableNativeEvents(false);
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            return new FirefoxDriver(capabilities);
        } else if ("chrome".equalsIgnoreCase(driverParam)) {
            return new ChromeDriver(capabilities);
        } else if ("safari".equals(driverParam)) {
            System.out.println("SafariDriver probably won't work, if it does please contact Erik M.");
            return new SafariDriver(capabilities);
        }
    } else {
        try {
            if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(ITUtil.getHubUrlString()), DesiredCapabilities.firefox());
            } else if ("chrome".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(ITUtil.getHubUrlString()), DesiredCapabilities.chrome());
            }
        } catch (MalformedURLException mue) {
            System.out.println(ITUtil.getHubUrlString() + " " + mue.getMessage());
            mue.printStackTrace();
        }
    }
    return null;
}
 
Example 34
Project: Learning-Spring-Boot-2.0-Second-Edition   File: WebDriverAutoConfigurationTests.java   View source code 4 votes vote down vote up
@Bean
SafariDriverFactory safariDriverFactory() {
	SafariDriverFactory factory = mock(SafariDriverFactory.class);
	given(factory.getObject()).willReturn(mock(SafariDriver.class));
	return factory;
}
 
Example 35
Project: functional-programming-selenium-examples   File: Safari.java   View source code 4 votes vote down vote up
@Override
public WebDriver getWebDriver()
{
    WebDriver driver = new SafariDriver();
       return driver;
}
 
Example 36
Project: givemeadriver   File: SafariDriverFactory.java   View source code 4 votes vote down vote up
@Override
public WebDriver createDriver(Capabilities capabilities) {
    return new SafariDriver((SafariOptions) capabilities);
}
 
Example 37
Project: selenium-jupiter   File: ForcedSafariJupiterTest.java   View source code 4 votes vote down vote up
@Test
public void safariTest(SafariDriver driver) {
    assumeFalse(IS_OS_MAC);
    assertThat(driver, nullValue());
}
 
Example 38
Project: selenium-jupiter   File: SafariWithGlobalOptionsJupiterTest.java   View source code 4 votes vote down vote up
@Test
public void safariTest(SafariDriver driver) {
    driver.get("https://bonigarcia.github.io/selenium-jupiter/");
    assertThat(driver.getTitle(),
            containsString("A JUnit 5 extension for Selenium WebDriver"));
}
 
Example 39
Project: selenium-jupiter   File: SafariJupiterTest.java   View source code 4 votes vote down vote up
@Test
public void test(SafariDriver driver) {
    driver.get("http://www.seleniumhq.org/");
    assertThat(driver.getTitle(),
            containsString("A JUnit 5 extension for Selenium WebDriver"));
}
 
Example 40
Project: pageobjects   File: DriversTest.java   View source code 4 votes vote down vote up
@Test
@Ignore
public void testSafariDriver() throws Exception {
    assumeTrue(System.getenv("Path").contains("Safari"));
    assertTrue(Drivers.SAFARI.get() instanceof SafariDriver);
}