org.openqa.selenium.safari.SafariDriver Java Examples
The following examples show how to use
org.openqa.selenium.safari.SafariDriver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractConsoleTest.java From keycloak with Apache License 2.0 | 6 votes |
@Before public void beforeConsoleTest() { // Safari driver seemingly doesn't comply with WebDriver specs. // driver.manage().deleteAllCookies() seems to delete all cookies regardless the path, i.e. when we delete cookies // in the 'test' realm, they're deleted in 'master' as well resulting in admin user to be logged out. if (driver instanceof SafariDriver) { testContext.setAdminLoggedIn(false); } adminUser = createAdminUserRepresentation(); createTestUserWithAdminClient(); if (!testContext.isAdminLoggedIn()) { loginToMasterRealmAdminConsoleAs(adminUser); testContext.setAdminLoggedIn(true); } }
Example #2
Source File: SafariDriverHandler.java From selenium-jupiter with Apache License 2.0 | 6 votes |
@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 #3
Source File: SafariDriverFactory.java From seleniumtestsframework with Apache License 2.0 | 6 votes |
@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 #4
Source File: ForcedAnnotationReaderTest.java From selenium-jupiter with Apache License 2.0 | 6 votes |
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(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 #5
Source File: SafariTest.java From selenium-example with MIT License | 5 votes |
@Before public void prepare() { testUrl = "https://leftstick.github.io/"; driver = new SafariDriver(); driver.manage().window().maximize(); driver.get(testUrl); }
Example #6
Source File: UIUtils.java From keycloak with Apache License 2.0 | 5 votes |
/** * Contains some browser-specific tweaks for getting an element text. * * @param element * @return */ public static String getTextFromElement(WebElement element) { String text = element.getText(); if (getCurrentDriver() instanceof SafariDriver) { try { // Safari on macOS doesn't comply with WebDriver specs yet again - getText() retrieves hidden text by CSS. text = element.findElement(By.xpath("./span[not(contains(@class,'ng-hide'))]")).getText(); } catch (NoSuchElementException e) { // no op } return text.trim(); // Safari on macOS sometimes for no obvious reason surrounds the text with spaces } return text; }
Example #7
Source File: UIUtils.java From keycloak with Apache License 2.0 | 5 votes |
public static void clickLink(WebElement element) { WebDriver driver = getCurrentDriver(); waitUntilElement(element).is().clickable(); if (driver instanceof SafariDriver && !element.isDisplayed()) { // Safari sometimes thinks an element is not visible // even though it is. In this case we just move the cursor and click. performOperationWithPageReload(() -> new Actions(driver).click(element).perform()); } else { performOperationWithPageReload(element::click); } }
Example #8
Source File: WisdomFluentLeniumTest.java From wisdom with Apache License 2.0 | 5 votes |
@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 #9
Source File: HTMLLauncher.java From selenium with Apache License 2.0 | 5 votes |
private WebDriver createDriver(String browser) { String[] parts = browser.split(" ", 2); browser = parts[0]; switch (browser) { case "*chrome": case "*firefox": case "*firefoxproxy": case "*firefoxchrome": case "*pifirefox": FirefoxOptions options = new FirefoxOptions().setLegacy(false); if (parts.length > 1) { options.setBinary(parts[1]); } return new FirefoxDriver(options); case "*iehta": case "*iexplore": case "*iexploreproxy": case "*piiexplore": return new InternetExplorerDriver(); case "*googlechrome": return new ChromeDriver(); case "*MicrosoftEdge": return new EdgeDriver(); case "*opera": case "*operablink": return new OperaDriver(); case "*safari": case "*safariproxy": return new SafariDriver(); default: throw new RuntimeException("Unrecognized browser: " + browser); } }
Example #10
Source File: SafariBrowserFactoryTest.java From darcy-webdriver with GNU General Public License v3.0 | 5 votes |
@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 #11
Source File: WebDriverUtils.java From rice with Educational Community License v2.0 | 5 votes |
/** * <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 #12
Source File: SeleniumHelper.java From hsac-fitnesse-fixtures with Apache License 2.0 | 5 votes |
/** * @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 #13
Source File: SafariImpl.java From frameworkium-core with Apache License 2.0 | 5 votes |
@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 #14
Source File: OtherWebDriverTest.java From webdrivermanager with Apache License 2.0 | 5 votes |
@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 #15
Source File: DefaultLocalDriverProviderTest.java From webdriver-factory with Apache License 2.0 | 5 votes |
@Test @EnabledOnOs(OS.MAC) @DisabledIfEnvironmentVariable(named = "CI", matches = "true") void canInstantiateSafariDriverWithSafariOptions() { driver = provider.createDriver(new SafariOptions()); assertTrue(driver instanceof SafariDriver); }
Example #16
Source File: WebDriverTypeTests.java From vividus with Apache License 2.0 | 5 votes |
@Test @PrepareForTest(fullyQualifiedNames = "org.vividus.selenium.WebDriverType$4") public void testGetSafariWebDriver() throws Exception { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); SafariDriver expected = mock(SafariDriver.class); whenNew(SafariDriver.class).withParameterTypes(SafariOptions.class) .withArguments(SafariOptions.fromCapabilities(desiredCapabilities)).thenReturn(expected); WebDriver actual = WebDriverType.SAFARI.getWebDriver(desiredCapabilities, new WebDriverConfiguration()); assertEquals(expected, actual); }
Example #17
Source File: LocalBrowserFactory.java From aquality-selenium-java with Apache License 2.0 | 5 votes |
@Override public Browser getBrowser() { BrowserName browserName = browserProfile.getBrowserName(); RemoteWebDriver driver; IDriverSettings driverSettings = browserProfile.getDriverSettings(); String webDriverVersion = driverSettings.getWebDriverVersion(); Architecture systemArchitecture = driverSettings.getSystemArchitecture(); switch (browserName) { case CHROME: WebDriverManager.chromedriver().version(webDriverVersion).setup(); driver = getDriver(ChromeDriver.class, driverSettings.getCapabilities()); break; case FIREFOX: WebDriverManager.firefoxdriver().version(webDriverVersion).setup(); driver = getDriver(FirefoxDriver.class, driverSettings.getCapabilities()); break; case IEXPLORER: WebDriverManager.iedriver().architecture(systemArchitecture).version(webDriverVersion).setup(); driver = getDriver(InternetExplorerDriver.class, driverSettings.getCapabilities()); break; case EDGE: WebDriverManager.edgedriver().version(webDriverVersion).setup(); driver = getDriver(EdgeDriver.class, driverSettings.getCapabilities()); break; case SAFARI: driver = getDriver(SafariDriver.class, driverSettings.getCapabilities()); break; default: throw getLoggedWrongBrowserNameException(); } logBrowserIsReady(browserName); return new Browser(driver); }
Example #18
Source File: Browser.java From coteafs-selenium with Apache License 2.0 | 5 votes |
private static WebDriver setupSafariDriver() { LOG.i("Setting up Safari driver..."); if (!OS.isMac()) { Assert.fail("Safari is not supported."); } if (appSetting().isHeadlessMode()) { LOG.w("Safari does not support Headless mode. Hence, ignoring the same..."); } final SafariOptions options = new SafariOptions(); return new SafariDriver(options); }
Example #19
Source File: SafariDriverFactory.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@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 #20
Source File: SafariAnnotationReaderTest.java From selenium-jupiter with Apache License 2.0 | 5 votes |
@ParameterizedTest @MethodSource("testClassProvider") 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); assertFalse(safariOptions.getUseTechnologyPreview()); }
Example #21
Source File: WebDriverAutoConfigurationTests.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 5 votes |
@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 #22
Source File: DefaultLocalDriverProvider.java From webdriver-factory with Apache License 2.0 | 4 votes |
public WebDriver createDriver(SafariOptions options) { return new SafariDriver(options); }
Example #23
Source File: WebDriverAutoConfigurationTests.java From Learning-Spring-Boot-2.0-Second-Edition with MIT License | 4 votes |
@Bean SafariDriverFactory safariDriverFactory() { SafariDriverFactory factory = mock(SafariDriverFactory.class); given(factory.getObject()).willReturn(mock(SafariDriver.class)); return factory; }
Example #24
Source File: SeleniumExtension.java From selenium-jupiter with Apache License 2.0 | 4 votes |
public SeleniumExtension() { addEntry(handlerMap, "org.openqa.selenium.chrome.ChromeDriver", ChromeDriverHandler.class); addEntry(handlerMap, "org.openqa.selenium.firefox.FirefoxDriver", FirefoxDriverHandler.class); addEntry(handlerMap, "org.openqa.selenium.edge.EdgeDriver", EdgeDriverHandler.class); addEntry(handlerMap, "org.openqa.selenium.opera.OperaDriver", OperaDriverHandler.class); addEntry(handlerMap, "org.openqa.selenium.safari.SafariDriver", SafariDriverHandler.class); addEntry(handlerMap, "org.openqa.selenium.remote.RemoteWebDriver", RemoteDriverHandler.class); addEntry(handlerMap, "org.openqa.selenium.WebDriver", RemoteDriverHandler.class); addEntry(handlerMap, "io.appium.java_client.AppiumDriver", AppiumDriverHandler.class); addEntry(handlerMap, "java.util.List", ListDriverHandler.class); addEntry(handlerMap, "org.openqa.selenium.phantomjs.PhantomJSDriver", OtherDriverHandler.class); addEntry(handlerMap, "org.openqa.selenium.ie.InternetExplorerDriver", InternetExplorerDriverHandler.class); addEntry(handlerMap, "com.codeborne.selenide.SelenideDriver", SelenideDriverHandler.class); addEntry(templateHandlerMap, "chrome", ChromeDriver.class); addEntry(templateHandlerMap, "firefox", FirefoxDriver.class); addEntry(templateHandlerMap, "edge", EdgeDriver.class); addEntry(templateHandlerMap, "opera", OperaDriver.class); addEntry(templateHandlerMap, "safari", SafariDriver.class); addEntry(templateHandlerMap, "appium", AppiumDriver.class); addEntry(templateHandlerMap, "phantomjs", PhantomJSDriver.class); addEntry(templateHandlerMap, "iexplorer", InternetExplorerDriver.class); addEntry(templateHandlerMap, "internet explorer", InternetExplorerDriver.class); addEntry(templateHandlerMap, "chrome-in-docker", RemoteWebDriver.class); addEntry(templateHandlerMap, "firefox-in-docker", RemoteWebDriver.class); addEntry(templateHandlerMap, "opera-in-docker", RemoteWebDriver.class); addEntry(templateHandlerMap, "edge-in-docker", RemoteWebDriver.class); addEntry(templateHandlerMap, "iexplorer-in-docker", RemoteWebDriver.class); addEntry(templateHandlerMap, "android", RemoteWebDriver.class); addEntry(templateHandlerMap, "selenide", SelenideDriverHandler.class); }
Example #25
Source File: ForcedSafariJupiterTest.java From selenium-jupiter with Apache License 2.0 | 4 votes |
@Test public void safariTest(SafariDriver driver) { assumeFalse(IS_OS_MAC); assertThat(driver, nullValue()); }
Example #26
Source File: WebDriverHandle.java From caja with Apache License 2.0 | 4 votes |
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); } 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 + "'"); } }
Example #27
Source File: SafariWithGlobalOptionsJupiterTest.java From selenium-jupiter with Apache License 2.0 | 4 votes |
@Test public void safariTest(SafariDriver driver) { driver.get("https://bonigarcia.github.io/selenium-jupiter/"); assertThat(driver.getTitle(), containsString("JUnit 5 extension for Selenium")); }
Example #28
Source File: SafariJupiterTest.java From selenium-jupiter with Apache License 2.0 | 4 votes |
@Test public void test(SafariDriver driver) { driver.get("http://www.seleniumhq.org/"); assertThat(driver.getTitle(), containsString("JUnit 5 extension for Selenium")); }
Example #29
Source File: SafariTest.java From webdrivermanager with Apache License 2.0 | 4 votes |
@Before public void setupTest() { driver = new SafariDriver(); }
Example #30
Source File: SafariDriverCreator.java From bobcat with Apache License 2.0 | 4 votes |
@Override public WebDriver create(Capabilities capabilities) { LOG.info("Starting the initialization of '{}' WebDriver instance", ID); LOG.debug("Initializing WebDriver with following capabilities: {}", capabilities); return new SafariDriver(new SafariOptions(capabilities)); }