Java 类org.openqa.selenium.internal.WrapsDriver 实例源码

项目:Selenium-Foundation    文件:ComponentContainerTest.java   
/**
 * Create mocked {@link WebElement} object.
 * 
 * @param type element type
 * @param value element value
 * @param isCheckbox 'true' is checkbox is desired; otherwise 'false'
 * @return mocked WebElement object
 */
private static WebElement mockElement(String type, String value, boolean isCheckbox) {
    WebElement element = mock(WebElement.class, withSettings().extraInterfaces(WrapsDriver.class));
    when(element.getTagName()).thenReturn(type);
    if (isCheckbox) {
        when(element.getAttribute("type")).thenReturn("checkbox");
        when(element.getAttribute("value")).thenReturn("isSelected: " + value);
        when(element.isSelected()).thenReturn(Boolean.parseBoolean(value));
    } else {
        when(element.getAttribute("type")).thenReturn("text");
        when(element.getAttribute("value")).thenReturn(value);
        when(element.isSelected()).thenReturn(false);
    }

    WebDriver driver = mockDriver();
    when(((WrapsDriver) element).getWrappedDriver()).thenReturn(driver);
    return element;
}
项目:Java-Testing-Toolbox    文件:ManagedWebDriverContextTest.java   
@Test
public void constructor_WrapsDriver_Test() {
    // null
    ManagedWebDriverContext managedWebDriverContext = new ManagedWebDriverContext((WrapsDriver) null);

    assertEquals(WebDriverManager.getDriverContext(), managedWebDriverContext.getDriverContext());
    assertEquals(WebDriverManager.getDriverContext().getWrappedDriver(), managedWebDriverContext.getDriverContext().getWrappedDriver());

    // non-null
    WebDriver webDriver = Mock.getWebDriver();
    WrapsDriver wrapsDriver = Mock.wrapsDriver(webDriver);
    managedWebDriverContext = new ManagedWebDriverContext(wrapsDriver);

    assertEquals(wrapsDriver, managedWebDriverContext.getDriverContext());
    assertEquals(webDriver, managedWebDriverContext.getDriverContext().getWrappedDriver());
}
项目:Java-Testing-Toolbox    文件:ManagedWebDriverContextTest.java   
@Test
public void setAndGetDriverContextTest() {
    ManagedWebDriverContext managedWebDriverContext = new ManagedWebDriverContext();

    managedWebDriverContext.setDriverContext(null);
    assertNull(managedWebDriverContext.getDriverContext());

    WebDriver webDriver = Mock.getWebDriver();
    WrapsDriver wrapsDriver = Mock.wrapsDriver(webDriver);

    managedWebDriverContext.setDriverContext(wrapsDriver);

    assertEquals(wrapsDriver, managedWebDriverContext.getDriverContext());
    assertEquals(webDriver, managedWebDriverContext.getDriverContext().getWrappedDriver());
    assertEquals(webDriver, managedWebDriverContext.getWrappedDriver());
}
项目:Java-Testing-Toolbox    文件:ManagedWebDriverContextTest.java   
@Test
public void toStringTest() {
    ManagedWebDriverContext managedWebDriverContext = new ManagedWebDriverContext(Mock.wrapsDriver(Mock.getWebDriver()));
    assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());

    managedWebDriverContext = new ManagedWebDriverContext((WrapsDriver) null);
    assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());

    managedWebDriverContext = new ManagedWebDriverContext(Mock.getWebDriver());
    assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());

    managedWebDriverContext = new ManagedWebDriverContext((WebDriver) null);
    assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());

    managedWebDriverContext = new ManagedWebDriverContext();
    assertEquals("ManagedWebDriverContext [driverContext=" + managedWebDriverContext.getDriverContext() + "]", managedWebDriverContext.toString());
}
项目:menggeqa    文件:WebDriverUnpackUtility.java   
/**
 * This method extract an instance of {@link org.openqa.selenium.WebDriver} from the given
 * {@link org.openqa.selenium.SearchContext}.
 * @param searchContext is an instance of {@link org.openqa.selenium.SearchContext}
 *                It may be the instance of {@link org.openqa.selenium.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 org.openqa.selenium.internal.WrapsDriver} or
 *                      {@link org.openqa.selenium.internal.WrapsElement}
 * @return the instance of {@link org.openqa.selenium.WebDriver}.
 *         Note: if the given {@link org.openqa.selenium.SearchContext} is not
 *         {@link org.openqa.selenium.WebDriver} and it doesn't implement
 *         {@link org.openqa.selenium.internal.WrapsDriver} or
 *         {@link org.openqa.selenium.internal.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;
}
项目:hsac-fitnesse-fixtures    文件:JavascriptHelper.java   
/**
 * Obtains executor based on Selenium context.
 * @param searchContext context in which javascript should be executed.
 * @return JavascriptExecutor based on search context.
 * @throws IllegalArgumentException when no executor could be obtained from context.
 */
public static JavascriptExecutor getJavascriptExecutor(SearchContext searchContext) {
    JavascriptExecutor executor = null;
    if (searchContext instanceof JavascriptExecutor) {
        executor = (JavascriptExecutor) searchContext;
    } else {
        if (searchContext instanceof WrapsDriver) {
            WrapsDriver wraps = (WrapsDriver) searchContext;
            WebDriver wrapped = wraps.getWrappedDriver();
            if (wrapped instanceof JavascriptExecutor) {
                executor = (JavascriptExecutor) wrapped;
            }
        }
    }
    if (executor == null) {
        throw new IllegalArgumentException("Unable to get: " + JavascriptExecutor.class.getName()
                + " from: " + searchContext.getClass().getName());
    }
    return executor;
}
项目:cinnamon    文件:EventListenerRegisteredCondition.java   
@Override
public boolean apply(final WebElement element) {
    try {
        WebDriver driver = ((WrapsDriver) element).getWrappedDriver();
        JavascriptExecutor js = (JavascriptExecutor) driver;
        Boolean jQuery = (Boolean) js.executeScript("return (typeof jQuery !== 'undefined');");
        if (!jQuery) {
            logger.warn("Unable to apply the EventListenerRegisteredCondition as jQuery is undefined.");
            return true;
        }
        @SuppressWarnings("unchecked")
        Map<String, Object> registeredListeners = (Map<String, Object>) js.executeScript("return $._data($(arguments[0])[0], 'events')", element);
        if (registeredListeners == null)
            return false;
        for (Map.Entry<String, Object> listener : registeredListeners.entrySet()) {
            logger.debug("DomEvent listener [" + listener.getKey() + "] registered.");
            if (listener.getKey().equals(event.getName())) {
                return true;
            }
        }
        return false;
    } catch (NullPointerException | WebDriverException e) {
        return false;
    }
}
项目:Selenium-Foundation    文件:WebDriverUtils.java   
/**
 * Get the driver associated with the specified search context
 * 
 * @param context search context
 * @return search context driver
 */
public static WebDriver getDriver(SearchContext context) {
    if (context instanceof WebDriver) {
        return (WebDriver) context;
    } else if (context instanceof WrapsDriver) {
        return ((WrapsDriver) context).getWrappedDriver();
    } else {
        throw new UnsupportedOperationException("Unable to extract the driver from the specified context");
    }
}
项目:Java-Testing-Toolbox    文件:ManagedWebDriverContext.java   
public ManagedWebDriverContext(WrapsDriver driverContext) {
    if (driverContext == null) {
        this.driverContext = WebDriverManager.getDriverContext();
    } else {
        this.driverContext = driverContext;
    }
}
项目:Java-Testing-Toolbox    文件:ManagedWebDriverContext.java   
public ManagedWebDriverContext(WebDriver webDriver) {
    if (webDriver == null) {
        this.driverContext = WebDriverManager.getDriverContext();
    } else {
        this.driverContext = new WrapsDriver() {

            @Override
            public WebDriver getWrappedDriver() {
                return webDriver;
            }

        };
    }
}
项目:Java-Testing-Toolbox    文件:AbstractPageObjectsTest.java   
@Test
public void constructor_WrapsDriver_String_Test() {
    AbstractPageObjects abstractPageObjects = new AbstractPageObjects((WrapsDriver) null, null);
    assertEquals(null, abstractPageObjects.getUrl());

    abstractPageObjects = new AbstractPageObjects((WrapsDriver) null, "test");
    assertEquals("test", abstractPageObjects.getUrl());
}
项目:Java-Testing-Toolbox    文件:Mock.java   
public static WrapsDriver wrapsDriver(WebDriver webDriver) {
    return new WrapsDriver() {

        @Override
        public WebDriver getWrappedDriver() {
            return webDriver;
        }

    };
}
项目:menggeqa    文件:InterceptorOfASingleElement.java   
/**
 * Look at
 * {@link net.sf.cglib.proxy.MethodInterceptor#intercept(Object, Method, Object[], MethodProxy)}
 */
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
    throws Throwable {
    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);
}
项目:grid-refactor-remote-server    文件:WebDriverHandler.java   
protected WebDriver getUnwrappedDriver() {
  WebDriver toReturn = getDriver();
  while (toReturn instanceof WrapsDriver) {
    toReturn = ((WrapsDriver) toReturn).getWrappedDriver();
  }
  return toReturn;
}
项目:nabla-projects-interview-visma    文件:WebElementExtender.java   
public static void highlightElement(final WebElement element) {
  for (int i = 0; i < 5; i++) {
    final WrapsDriver wrappedElement = (WrapsDriver) element;
    final JavascriptExecutor driver = (JavascriptExecutor) wrappedElement.getWrappedDriver();
    driver.executeScript(
        "arguments[0].setAttribute('style',  arguments[1])", element, "visibility:hidden;");
    // driver.executeScript("arguments[0].setAttribute('style',  arguments[1]);", element, "");
  }
}
项目:cinnamon    文件:InViewPortCondition.java   
@Override
public boolean apply(final WebElement element) {
    try {
        WebDriver driver = ((WrapsDriver) element).getWrappedDriver();
        JavascriptExecutor js = (JavascriptExecutor) driver;
        return (Boolean) js
                .executeScript(
                        "var rect = arguments[0].getBoundingClientRect();"
                                + "return (rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth));",
                        element);
    } catch (NullPointerException | WebDriverException e) {
        return false;
    }
}
项目:crawljax    文件:WebDriverBackedEmbeddedBrowser.java   
private <T> T takeScreenShotOnBrowser(WebDriver driver, OutputType<T> outType)
        throws CrawljaxException {
    if (driver instanceof TakesScreenshot) {
        T screenshot = ((TakesScreenshot) driver).getScreenshotAs(outType);
        removeCanvasGeneratedByFirefoxDriverForScreenshots();
        return screenshot;
    } else if (driver instanceof RemoteWebDriver) {
        WebDriver augmentedWebdriver = new Augmenter().augment(driver);
        return takeScreenShotOnBrowser(augmentedWebdriver, outType);
    } else if (driver instanceof WrapsDriver) {
        return takeScreenShotOnBrowser(((WrapsDriver) driver).getWrappedDriver(), outType);
    } else {
        throw new CrawljaxException("Your current WebDriver doesn't support screenshots.");
    }
}
项目:darcy-webdriver    文件:WebDriverBrowserTest.java   
@Test
public void shouldWrapDriver() {
    Browser browser = new WebDriverBrowser(mock(TargetedWebDriver.class),
            new StubWebDriverParentContext(), new StubWebDriverElementContext());

    assertThat(browser, instanceOf(WrapsDriver.class));
}
项目:webdriver-runner    文件:DelegatingWebDriver.java   
protected Class<?>[] extractInterfaces(Object object) {
    Set<Class<?>> allInterfaces = new HashSet<Class<?>>();
    allInterfaces.add(WrapsDriver.class);
    if (object instanceof WebElement) {
        allInterfaces.add(WrapsElement.class);
    }
    extractInterfaces(allInterfaces, object.getClass());

    return allInterfaces.toArray(new Class<?>[allInterfaces.size()]);
}
项目:Java-Testing-Toolbox    文件:JSApplicationCache.java   
public JSApplicationCache(WrapsDriver driverContext) {
    super(driverContext);
}
项目:Java-Testing-Toolbox    文件:JSLocalStorage.java   
public JSLocalStorage(WrapsDriver driverContext) {
    super(driverContext);
}
项目:Java-Testing-Toolbox    文件:JSSessionStorage.java   
public JSSessionStorage(WrapsDriver driverContext) {
    super(driverContext);
}
项目:Java-Testing-Toolbox    文件:JSWebStorage.java   
public JSWebStorage(WrapsDriver driverContext) {
    super(driverContext);
}
项目:Java-Testing-Toolbox    文件:WebDriverManager.java   
public static WrapsDriver getDriverContext() {
    return driverContext;
}
项目:Java-Testing-Toolbox    文件:ManagedWebDriverContext.java   
protected WrapsDriver getDriverContext() {
    return driverContext;
}
项目:Java-Testing-Toolbox    文件:ManagedWebDriverContext.java   
protected void setDriverContext(WrapsDriver driverContext) {
    this.driverContext = driverContext;
}
项目:Java-Testing-Toolbox    文件:AbstractPageObjects.java   
public AbstractPageObjects(WrapsDriver driverContext, String url) {
    super(driverContext);

    this.url = url;
}
项目:Java-Testing-Toolbox    文件:AbstractLoginPageObjects.java   
public AbstractLoginPageObjects(WrapsDriver driverContext, String url) {
    super(driverContext, url);
}
项目:Java-Testing-Toolbox    文件:AbstractPageObjectsTest.java   
@Test
public void toStringTest() {
    assertEquals("Page(test)", new AbstractPageObjects("test").toString());
    assertEquals("Page(test)", new AbstractPageObjects((WebDriver) null, "test").toString());
    assertEquals("Page(test)", new AbstractPageObjects((WrapsDriver) null, "test").toString());
}
项目:nabla-projects-interview-visma    文件:WebElementExtender.java   
public static File captureElementBitmap(final WebElement element) throws IOException {
  final WrapsDriver wrapsDriver = (WrapsDriver) element;

  final File screen =
      ((TakesScreenshot) wrapsDriver.getWrappedDriver()).getScreenshotAs(OutputType.FILE);

  final BufferedImage img = ImageIO.read(screen);

  final int width = element.getSize().getWidth();
  final int height = element.getSize().getHeight();

  final Rectangle rect = new Rectangle(width, height);

  final Point p = element.getLocation();

  final BufferedImage dest = img.getSubimage(p.getX(), p.getY(), rect.width, rect.height);

  ImageIO.write(dest, "png", screen);
  return screen;
}
项目:cinnamon    文件:WebDriverUtils.java   
public static WebDriver unwrapDriver(final WebElement element) {
    return ((WrapsDriver) element).getWrappedDriver();
}
项目:minium    文件:TouchInteraction.java   
@Override
protected TouchActions newActions(WebElement elem) {
    return new TouchActions(((WrapsDriver) elem).getWrappedDriver());
}
项目:minium    文件:AbstractWebInteraction.java   
/**
 * New actions.
 *
 * @param elem the elem
 * @return the actions
 */
protected Actions newActions(WebElement elem) {
    return new Actions(((WrapsDriver) elem).getWrappedDriver());
}