org.openqa.selenium.WrapsDriver Java Examples
The following examples show how to use
org.openqa.selenium.WrapsDriver.
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: WebDriverUnpackUtility.java From java-client with Apache License 2.0 | 6 votes |
/** * This method extract an instance of {@link WebDriver} from the given {@link SearchContext}. * @param searchContext is an instance of {@link SearchContext}. It may be the instance of * {@link WebDriver} or {@link org.openqa.selenium.WebElement} or some other * user's extension/implementation. * Note: if you want to use your own implementation then it should implement * {@link WrapsDriver} or {@link WrapsElement} * @return the instance of {@link WebDriver}. * Note: if the given {@link SearchContext} is not * {@link WebDriver} and it doesn't implement * {@link WrapsDriver} or {@link WrapsElement} then this method returns null. * */ public static WebDriver unpackWebDriverFromSearchContext(SearchContext searchContext) { if (searchContext instanceof WebDriver) { return (WebDriver) searchContext; } if (searchContext instanceof WrapsDriver) { return unpackWebDriverFromSearchContext( ((WrapsDriver) searchContext).getWrappedDriver()); } // Search context it is not only Webdriver. Webelement is search context too. // RemoteWebElement and MobileElement implement WrapsDriver if (searchContext instanceof WrapsElement) { return unpackWebDriverFromSearchContext( ((WrapsElement) searchContext).getWrappedElement()); } return null; }
Example #2
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void testGetWebDriverWithWebDriverType() throws Exception { mockCapabilities((HasCapabilities) driver); WebDriverType webDriverType = mock(WebDriverType.class); webDriverFactory.setWebDriverType(webDriverType); WebDriverConfiguration configuration = mock(WebDriverConfiguration.class); Map<String, Object> capablities = Map.of(KEY1, TRUE, KEY2, FALSE); when(propertyParser.getPropertyValuesTreeByPrefix(SELENIUM_CAPABILITIES)).thenReturn(capablities); configuration.setBinaryPath(Optional.of(PATH)); injectConfigurations(webDriverType, configuration); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(Map.of(KEY2, true)); when(webDriverType.getWebDriver(new DesiredCapabilities(Map.of(KEY1, Boolean.TRUE, KEY2, Boolean.TRUE)), configuration)).thenReturn(driver); mockTimeouts(driver); WebDriver actualDriver = webDriverFactory.getWebDriver(desiredCapabilities); assertThat(actualDriver, instanceOf(TextFormattingWebDriver.class)); assertEquals(driver, ((WrapsDriver) actualDriver).getWrappedDriver()); assertLogger(); verify(propertyParser, never()).getPropertyValuesTreeByPrefix(SELENIUM_GRID_CAPABILITIES); }
Example #3
Source File: InternalSelenseTestBase.java From selenium with Apache License 2.0 | 6 votes |
@Override protected void before() { if (!(selenium instanceof WebDriverBackedSelenium)) { return; } // We need to be a on page where we can execute JS WebDriver driver = ((WrapsDriver) selenium).getWrappedDriver(); driver.get(whereIs("/selenium-server")); try { URL scriptUrl = Resources.getResource(getClass(), "/com/thoughtworks/selenium/testHelpers.js"); String script = Resources.toString(scriptUrl, StandardCharsets.UTF_8); ((JavascriptExecutor) driver).executeScript(script); } catch (IOException e) { fail("Cannot read script: " + Throwables.getStackTraceAsString(e)); } }
Example #4
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void testGetWebDriverWithWebDriverTypeAndBinaryPathConfiguration() { mockCapabilities((HasCapabilities) driver); WebDriverType webDriverType = mock(WebDriverType.class); when(webDriverType.isBinaryPathSupported()).thenReturn(Boolean.TRUE); webDriverFactory.setWebDriverType(webDriverType); lenient().when(propertyParser.getPropertyValue("web.driver." + webDriverType + ".driver-executable-path")) .thenReturn(PATH); lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) .thenReturn(PATH); DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); when(webDriverType.getWebDriver(eq(new DesiredCapabilities()), argThat(config -> Optional.of(PATH).equals(config.getBinaryPath()) && Optional.of(PATH).equals(config.getDriverExecutablePath())))).thenReturn(driver); Timeouts timeouts = mockTimeouts(driver); assertEquals(driver, ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #5
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void testGetWebDriverWithWebDriverTypeAndCommandLineArgumentsConfiguration() { mockCapabilities((HasCapabilities) driver); WebDriverType webDriverType = mock(WebDriverType.class); when(webDriverType.isCommandLineArgumentsSupported()).thenReturn(Boolean.TRUE); webDriverFactory.setWebDriverType(webDriverType); lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) .thenReturn(null); lenient().when( propertyParser.getPropertyValue(String.format(COMMAND_LINE_ARGUMENTS_PROPERTY_FORMAT, webDriverType))) .thenReturn(ARGS); DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); when(webDriverType.getWebDriver(eq(new DesiredCapabilities()), argThat(config -> Arrays.equals(new String[] { ARG_1, ARG_2 }, config.getCommandLineArguments())))) .thenReturn(driver); Timeouts timeouts = mockTimeouts(driver); assertEquals(driver, ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #6
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void testGetWebDriverWithWebDriverTypeAndExperimentalOptionsConfiguration() { mockCapabilities((HasCapabilities) driver); WebDriverType webDriverType = mock(WebDriverType.class); webDriverFactory.setWebDriverType(webDriverType); lenient().when(propertyParser.getPropertyValue(String.format(BINARY_PATH_PROPERTY_FORMAT, webDriverType))) .thenReturn(null); lenient().when( propertyParser.getPropertyValue(String.format(EXPERIMENTAL_OPTIONS_PROPERTY_FORMAT, webDriverType))) .thenReturn("{\"mobileEmulation\": {\"deviceName\": \"iPhone 8\"}}"); DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); when(webDriverType.getWebDriver(eq(new DesiredCapabilities()), argThat(config -> Map.of("mobileEmulation", Map.of("deviceName", "iPhone 8")) .equals(config.getExperimentalOptions())))).thenReturn(driver); Timeouts timeouts = mockTimeouts(driver); assertEquals(driver, ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #7
Source File: WebDriverWaitTest.java From selenium with Apache License 2.0 | 6 votes |
@Test public void shouldIncludeRemoteInfoForWrappedDriverTimeout() throws IOException { Capabilities caps = new MutableCapabilities(); Response response = new Response(new SessionId("foo")); response.setValue(caps.asMap()); CommandExecutor executor = mock(CommandExecutor.class); when(executor.execute(any(Command.class))).thenReturn(response); RemoteWebDriver driver = new RemoteWebDriver(executor, caps); WebDriver testDriver = mock(WebDriver.class, withSettings().extraInterfaces(WrapsDriver.class)); when(((WrapsDriver) testDriver).getWrappedDriver()).thenReturn(driver); TickingClock clock = new TickingClock(); WebDriverWait wait = new WebDriverWait(testDriver, Duration.ofSeconds(1), Duration.ofMillis(200), clock, clock); assertThatExceptionOfType(TimeoutException.class) .isThrownBy(() -> wait.until(d -> false)) .withMessageContaining("Capabilities {javascriptEnabled: true, platform: ANY, platformName: ANY}") .withMessageContaining("Session ID: foo"); }
Example #8
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") void testGetRemoteWebDriverFirefoxDriver() throws MalformedURLException { mockCapabilities(remoteWebDriver); setRemoteDriverUrl(); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(new FirefoxOptions()); when(remoteWebDriverFactory.getRemoteWebDriver(eq(URL.toURL()), argThat(caps -> { Map<String, Object> options = (Map<String, Object>) caps.getCapability(FirefoxOptions.FIREFOX_OPTIONS); Map<String, Object> prefs = (Map<String, Object>) options.get("prefs"); return "about:blank".equals(prefs.get("startup.homepage_welcome_url.additional")) && "firefox".equals(caps.getBrowserName()); }))).thenReturn(remoteWebDriver); Timeouts timeouts = mockTimeouts(remoteWebDriver); assertEquals(remoteWebDriver, ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #9
Source File: InterceptorOfASingleElement.java From java-client with Apache License 2.0 | 6 votes |
/** * Look at {@link MethodInterceptor#intercept(Object, Method, Object[], MethodProxy)}. */ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { if (method.getName().equals("toString") && args.length == 0) { return locator.toString(); } if (Object.class.equals(method.getDeclaringClass())) { return proxy.invokeSuper(obj, args); } if (WrapsDriver.class.isAssignableFrom(method.getDeclaringClass()) && method.getName() .equals("getWrappedDriver")) { return driver; } WebElement realElement = locator.findElement(); return getObject(realElement, method, args); }
Example #10
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void testGetRemoteWebDriverIEDriver() throws Exception { mockCapabilities(remoteWebDriver); setRemoteDriverUrl(); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setBrowserName(BrowserType.IEXPLORE); when(remoteWebDriverFactory.getRemoteWebDriver(any(URL.class), any(DesiredCapabilities.class))) .thenReturn(remoteWebDriver); Timeouts timeouts = mockTimeouts(remoteWebDriver); desiredCapabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false); assertEquals(remoteWebDriver, ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #11
Source File: ElementStepsTests.java From vividus with Apache License 2.0 | 6 votes |
@Test public void testLoadFileFromFilesystem() throws IOException { Resource resource = mockResource(ABSOLUTE_PATH, mockFileForUpload(), false); ResourceLoader resourceLoader = mockResourceLoader(resource); when(resourceLoader.getResource(ResourceUtils.FILE_URL_PREFIX + FILE_PATH)).thenReturn(resource); mockRemoteWebDriver(); WebDriver webDriver = mock(WebDriver.class, withSettings().extraInterfaces(WrapsDriver.class)); when(webDriverProvider.get()).thenReturn(webDriver); when(softAssert.assertTrue(FILE_FILE_PATH_EXISTS, true)).thenReturn(true); when(webDriverProvider.isRemoteExecution()).thenReturn(true); SearchAttributes searchAttributes = new SearchAttributes(ActionAttributeType.XPATH, new SearchParameters(XPATH).setVisibility(Visibility.ALL)); when(baseValidations.assertIfElementExists(AN_ELEMENT, searchAttributes)).thenReturn(webElement); elementSteps.uploadFile(searchAttributes, FILE_PATH); verify(webElement).sendKeys(ABSOLUTE_PATH); }
Example #12
Source File: ElementStepsTests.java From vividus with Apache License 2.0 | 6 votes |
@Test public void testLoadFileRemote() throws IOException { File file = mockFileForUpload(); mockResourceLoader(mockResource(ABSOLUTE_PATH, file, true)); mockRemoteWebDriver(); WebDriver webDriver = mock(WebDriver.class, withSettings().extraInterfaces(WrapsDriver.class)); when(webDriverProvider.get()).thenReturn(webDriver); when(softAssert.assertTrue(FILE_FILE_PATH_EXISTS, true)).thenReturn(true); when(webDriverProvider.isRemoteExecution()).thenReturn(true); SearchAttributes searchAttributes = new SearchAttributes(ActionAttributeType.XPATH, new SearchParameters(XPATH).setVisibility(Visibility.ALL)); when(baseValidations.assertIfElementExists(AN_ELEMENT, searchAttributes)).thenReturn(webElement); elementSteps.uploadFile(searchAttributes, FILE_PATH); verify(webElement).sendKeys(ABSOLUTE_PATH); }
Example #13
Source File: WebDriverWait.java From selenium with Apache License 2.0 | 6 votes |
@Override protected RuntimeException timeoutException(String message, Throwable lastException) { WebDriver exceptionDriver = driver; TimeoutException ex = new TimeoutException(message, lastException); ex.addInfo(WebDriverException.DRIVER_INFO, exceptionDriver.getClass().getName()); while (exceptionDriver instanceof WrapsDriver) { exceptionDriver = ((WrapsDriver) exceptionDriver).getWrappedDriver(); } if (exceptionDriver instanceof RemoteWebDriver) { RemoteWebDriver remote = (RemoteWebDriver) exceptionDriver; if (remote.getSessionId() != null) { ex.addInfo(WebDriverException.SESSION_ID, remote.getSessionId().toString()); } if (remote.getCapabilities() != null) { ex.addInfo("Capabilities", remote.getCapabilities().toString()); } } throw ex; }
Example #14
Source File: RelativeLocator.java From selenium with Apache License 2.0 | 6 votes |
private JavascriptExecutor extractJsExecutor(SearchContext context) { if (context instanceof JavascriptExecutor) { return (JavascriptExecutor) context; } Object current = context; while (current instanceof WrapsDriver) { WebDriver driver = ((WrapsDriver) context).getWrappedDriver(); if (driver instanceof JavascriptExecutor) { return (JavascriptExecutor) driver; } current = driver; } throw new IllegalArgumentException("Cannot find elements, since the context cannot execute JS: " + context); }
Example #15
Source File: Augmenter.java From selenium with Apache License 2.0 | 5 votes |
private RemoteWebDriver extractRemoteWebDriver(WebDriver driver) { Require.nonNull("WebDriver", driver); if (driver instanceof RemoteWebDriver) { return (RemoteWebDriver) driver; } if (driver instanceof WrapsDriver) { return extractRemoteWebDriver(((WrapsDriver) driver).getWrappedDriver()); } return null; }
Example #16
Source File: EventFiringWebDriver.java From selenium with Apache License 2.0 | 5 votes |
private Class<?>[] extractInterfaces(Object object) { Set<Class<?>> allInterfaces = new HashSet<>(); allInterfaces.add(WrapsDriver.class); if (object instanceof WebElement) { allInterfaces.add(WrapsElement.class); } extractInterfaces(allInterfaces, object.getClass()); return allInterfaces.toArray(new Class<?>[allInterfaces.size()]); }
Example #17
Source File: EventFiringWebDriver.java From selenium with Apache License 2.0 | 5 votes |
@Override public WebDriver getWrappedDriver() { if (driver instanceof WrapsDriver) { return ((WrapsDriver) driver).getWrappedDriver(); } return driver; }
Example #18
Source File: WebDriverHandler.java From selenium with Apache License 2.0 | 5 votes |
protected WebDriver getUnwrappedDriver() { WebDriver toReturn = getDriver(); while (toReturn instanceof WrapsDriver) { toReturn = ((WrapsDriver) toReturn).getWrappedDriver(); } return Require.state("Unwrapped driver", toReturn).nonNull(); }
Example #19
Source File: TestClickAt.java From selenium with Apache License 2.0 | 5 votes |
private boolean isUsingNativeEvents() { if (!(selenium instanceof WrapsDriver)) { return false; } WebDriver driver = ((WrapsDriver) selenium).getWrappedDriver(); if (!(driver instanceof HasCapabilities)) { return false; } Capabilities capabilities = ((HasCapabilities) driver).getCapabilities(); return capabilities.is(CapabilityType.HAS_NATIVE_EVENTS); }
Example #20
Source File: AppiumTemplateMatcher.java From justtestlah with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void setDriver(WebDriver driver) { if (driver instanceof WrapsDriver) { this.driver = (AppiumDriver) ((WrapsDriver) driver).getWrappedDriver(); } else { this.driver = (AppiumDriver) driver; } }
Example #21
Source File: WebDriverUtilTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testNonWrappedWebElementUnwrap() { RemoteWebElement remoteWebElement = mock(RemoteWebElement.class); WrapsDriver actual = WebDriverUtil.unwrap(remoteWebElement, WrapsDriver.class); assertEquals(remoteWebElement, actual); }
Example #22
Source File: WebDriverUtilTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testWrappedWebElementUnwrap() { RemoteWebElement remoteWebElement = mock(RemoteWebElement.class); WrapsDriver actual = WebDriverUtil.unwrap(new TextFormattingWebElement(remoteWebElement), WrapsDriver.class); assertEquals(remoteWebElement, actual); }
Example #23
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 5 votes |
private void testGetRemoteWebDriverIsChrome(ChromeOptions chromeOptions) throws Exception { mockCapabilities(remoteWebDriver); setRemoteDriverUrl(); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setBrowserName(BrowserType.CHROME); desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); when(remoteWebDriverFactory.getRemoteWebDriver(URL.toURL(), desiredCapabilities)).thenReturn(remoteWebDriver); Timeouts timeouts = mockTimeouts(remoteWebDriver); assertEquals(remoteWebDriver, ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #24
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testGetRemoteWebDriverMarionetteDriver() throws Exception { mockCapabilities(remoteWebDriver); setRemoteDriverUrl(); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setBrowserName("marionette"); when(remoteWebDriverFactory.getRemoteWebDriver(URL.toURL(), desiredCapabilities)) .thenReturn(remoteWebDriver); Timeouts timeouts = mockTimeouts(remoteWebDriver); assertEquals(remoteWebDriver, ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #25
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testGetRemoteWebDriver() throws Exception { mockCapabilities(remoteWebDriver); setRemoteDriverUrl(); DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); when(remoteWebDriverFactory.getRemoteWebDriver(URL.toURL(), desiredCapabilities)).thenReturn(remoteWebDriver); Timeouts timeouts = mockTimeouts(remoteWebDriver); assertEquals(remoteWebDriver, ((WrapsDriver) webDriverFactory.getRemoteWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #26
Source File: WebDriverFactoryTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testGetWebDriverWithWebDriverTypeWOBinary() throws Exception { mockCapabilities((HasCapabilities) driver); WebDriverConfiguration configuration = new WebDriverConfiguration(); WebDriverType webDriverType = mock(WebDriverType.class); webDriverFactory.setWebDriverType(webDriverType); injectConfigurations(webDriverType, configuration); DesiredCapabilities desiredCapabilities = mock(DesiredCapabilities.class); when(webDriverType.getWebDriver(new DesiredCapabilities(), configuration)).thenReturn(driver); Timeouts timeouts = mockTimeouts(driver); assertEquals(driver, ((WrapsDriver) webDriverFactory.getWebDriver(desiredCapabilities)).getWrappedDriver()); verify(timeoutConfigurer).configure(timeouts); assertLogger(); }
Example #27
Source File: WebDriverProviderTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testGetUnwrapped() { testContext.put(VividusWebDriver.class, vividusWebDriver); when(vividusWebDriver.getWrappedDriver()).thenReturn(wrapsDriver); assertThat(webDriverProvider.getUnwrapped(WrapsDriver.class), instanceOf(WrapsDriver.class)); }
Example #28
Source File: AndroidPageObjectTest.java From java-client with Apache License 2.0 | 4 votes |
@Test public void checkThatClassObjectMethodsDoNotInvokeTheSearching() { assertTrue(AndroidElement.class.isAssignableFrom(fakeElement.getClass())); assertNotEquals(AndroidElement.class, fakeElement.getClass()); assertEquals(driver, ((WrapsDriver) fakeElement).getWrappedDriver()); }
Example #29
Source File: WebDriverUtilTests.java From vividus with Apache License 2.0 | 4 votes |
@Test void testWrappedWebElementUnwrapButNoCast() { assertThrows(ClassCastException.class, () -> WebDriverUtil.unwrap(new TextFormattingWebElement(mock(WebElement.class)), WrapsDriver.class)); }
Example #30
Source File: WebDriverBackedSelenium.java From selenium with Apache License 2.0 | 4 votes |
@Override public WebDriver getWrappedDriver() { return ((WrapsDriver) commandProcessor).getWrappedDriver(); }