类org.openqa.selenium.WrapsElement源码实例Demo

下面列出了怎么用org.openqa.selenium.WrapsElement的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: vividus   文件: DelegatingWebElement.java
@Override
public boolean equals(Object obj)
{
    if (!(obj instanceof WebElement))
    {
        return false;
    }

    WebElement that = (WebElement) obj;
    if (that instanceof WrapsElement)
    {
        that = ((WrapsElement) that).getWrappedElement();
    }

    return wrappedElement.equals(that);
}
 
源代码2 项目: java-client   文件: WebDriverUnpackUtility.java
/**
 * 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;
}
 
源代码3 项目: selenium   文件: RemoteWebElement.java
@Override
public boolean equals(Object obj) {
  if (!(obj instanceof WebElement)) {
    return false;
  }

  WebElement other = (WebElement) obj;
  while (other instanceof WrapsElement) {
    other = ((WrapsElement) other).getWrappedElement();
  }

  if (!(other instanceof RemoteWebElement)) {
    return false;
  }

  RemoteWebElement otherRemoteWebElement = (RemoteWebElement) other;

  return id.equals(otherRemoteWebElement.id);
}
 
源代码4 项目: selenium   文件: EventFiringWebDriverTest.java
@Test
public void shouldWrapElementFoundWhenCallingScripts() {
  final WebDriver mockedDriver = mock(WebDriver.class,
                                      withSettings().extraInterfaces(JavascriptExecutor.class));
  final WebElement stubbedElement = mock(WebElement.class);

  when(((JavascriptExecutor) mockedDriver).executeScript("foo"))
      .thenReturn(stubbedElement);

  EventFiringWebDriver testedDriver = new EventFiringWebDriver(mockedDriver);

  Object res = testedDriver.executeScript("foo");
  verify((JavascriptExecutor) mockedDriver).executeScript("foo");
  assertThat(res).isInstanceOf(WebElement.class).isInstanceOf(WrapsElement.class);
  assertThat(((WrapsElement) res).getWrappedElement()).isSameAs(stubbedElement);
}
 
源代码5 项目: selenium   文件: EventFiringWebDriverTest.java
@Test
public void testShouldUnpackListOfElementArgsWhenCallingScripts() {
  final WebDriver mockedDriver = mock(WebDriver.class,
                                      withSettings().extraInterfaces(JavascriptExecutor.class));
  final WebElement mockElement = mock(WebElement.class);

  when(mockedDriver.findElement(By.id("foo"))).thenReturn(mockElement);

  EventFiringWebDriver testedDriver = new EventFiringWebDriver(mockedDriver);
  testedDriver.register(new AbstractWebDriverEventListener() {});

  final WebElement foundElement = testedDriver.findElement(By.id("foo"));
  assertThat(foundElement).isInstanceOf(WrapsElement.class);
  assertThat(((WrapsElement) foundElement).getWrappedElement()).isSameAs(mockElement);

  List<Object> args = Arrays.asList("before", foundElement, "after");

  testedDriver.executeScript("foo", args);

  verify((JavascriptExecutor) mockedDriver).executeScript("foo", args);
}
 
源代码6 项目: selenium   文件: EventFiringWebDriverTest.java
@Test
public void shouldWrapMultipleElementsFoundWhenCallingScripts() {
  final WebDriver mockedDriver = mock(WebDriver.class,
                                      withSettings().extraInterfaces(JavascriptExecutor.class));
  final WebElement stubbedElement1 = mock(WebElement.class);
  final WebElement stubbedElement2 = mock(WebElement.class);

  when(((JavascriptExecutor) mockedDriver).executeScript("foo"))
      .thenReturn(Arrays.asList(stubbedElement1, stubbedElement2));

  EventFiringWebDriver testedDriver = new EventFiringWebDriver(mockedDriver);

  Object res = testedDriver.executeScript("foo");
  verify((JavascriptExecutor) mockedDriver).executeScript("foo");
  assertThat(res).isInstanceOf(List.class);
  List<Object> resList = (List<Object>) res;
  resList.forEach(el -> assertThat(el).isInstanceOf(WrapsElement.class));
  assertThat(((WrapsElement) resList.get(0)).getWrappedElement()).isSameAs(stubbedElement1);
  assertThat(((WrapsElement) resList.get(1)).getWrappedElement()).isSameAs(stubbedElement2);
}
 
源代码7 项目: selenium   文件: EventFiringWebDriverTest.java
@Test
public void testShouldUnpackMapOfElementArgsWhenCallingScripts() {
  final WebDriver mockedDriver = mock(WebDriver.class,
                                      withSettings().extraInterfaces(JavascriptExecutor.class));
  final WebElement mockElement = mock(WebElement.class);

  when(mockedDriver.findElement(By.id("foo"))).thenReturn(mockElement);

  EventFiringWebDriver testedDriver = new EventFiringWebDriver(mockedDriver);
  testedDriver.register(mock(WebDriverEventListener.class));

  final WebElement foundElement = testedDriver.findElement(By.id("foo"));
  assertThat(foundElement).isInstanceOf(WrapsElement.class);
  assertThat(((WrapsElement) foundElement).getWrappedElement()).isSameAs(mockElement);

  ImmutableMap<String, Object> args = ImmutableMap.of(
      "foo", "bar",
      "element", foundElement,
      "nested", Arrays.asList("before", foundElement, "after")
  );

  testedDriver.executeScript("foo", args);

  verify((JavascriptExecutor) mockedDriver).executeScript("foo", args);
}
 
源代码8 项目: selenium   文件: ElementEquality.java
@Override
public Boolean call() {

  WebElement one = getElement();
  WebElement two = getKnownElements().get(otherId);

  // Unwrap the elements, if necessary
  if (one instanceof WrapsElement) {
    one = ((WrapsElement) one).getWrappedElement();
  }
  if (two instanceof KnownElements.ProxiedElement) {
    two = ((KnownElements.ProxiedElement) two).getWrappedElement();
  }

  return one.equals(two);
}
 
源代码9 项目: vividus   文件: MouseActions.java
@Override
public ClickResult click(WrapsElement element)
{
    if (element != null)
    {
        return click(element.getWrappedElement());
    }
    return new ClickResult();
}
 
源代码10 项目: vividus   文件: MouseActionsTests.java
@Test
void clickWrapsElement()
{
    WrapsElement wrapsElement = mock(WrapsElement.class);
    WebElement webElement = mock(WebElement.class);
    when(wrapsElement.getWrappedElement()).thenReturn(webElement);
    MouseActions spy = spy(mouseActions);
    ClickResult expectedResult = new ClickResult();
    doReturn(expectedResult).when(spy).click(webElement);
    ClickResult actualResult = spy.click(wrapsElement);
    assertEquals(expectedResult, actualResult);
}
 
源代码11 项目: vividus   文件: MouseActionsTests.java
@Test
void clickWrapsElementNull()
{
    mouseActions.click((WrapsElement) null);
    verifyNoInteractions(webDriverProvider);
    verifyNoInteractions(webUiContext);
}
 
源代码12 项目: vividus   文件: BaseValidationsTests.java
@Test
void testAssertElementStateNullWrapsElement()
{
    State state = mock(State.class);
    boolean result = baseValidations.assertElementState(BUSINESS_DESCRIPTION, state, (WrapsElement) null);
    verifyNoInteractions(state);
    assertFalse(result);
}
 
源代码13 项目: vividus   文件: BaseValidationsTests.java
@Test
void testAssertElementStateNWhenWrapsNullElement()
{
    WrapsElement wrapsElement = mock(WrapsElement.class);
    when(wrapsElement.getWrappedElement()).thenReturn(null);
    State state = mock(State.class);
    boolean result = baseValidations.assertElementState(BUSINESS_DESCRIPTION, state, wrapsElement);
    verifyNoInteractions(state);
    assertFalse(result);
}
 
源代码14 项目: vividus   文件: BaseValidationsTests.java
@Test
void testAssertWrapsElementStateSuccess()
{
    when(mockedWebDriverProvider.get()).thenReturn(mockedWebDriver);
    String mockedExpectedConditionToString = mockedExpectedCondition.toString();
    WrapsElement wrapsElement = mock(WrapsElement.class);
    when(wrapsElement.getWrappedElement()).thenReturn(mockedWebElement);
    State state = mock(State.class);
    doReturn(mockedExpectedCondition).when(state).getExpectedCondition(mockedWebElement);
    when(softAssert.assertThat(eq(BUSINESS_DESCRIPTION), eq(mockedExpectedConditionToString),
            eq(mockedWebDriver), argThat(matcher -> matcher instanceof ExpectedConditionsMatcher)))
                    .thenReturn(Boolean.TRUE);
    assertTrue(baseValidations.assertElementState(BUSINESS_DESCRIPTION, state, wrapsElement));
}
 
源代码15 项目: vividus   文件: DropdownStepsTests.java
@Test
void ifDropDownWithNameFoundState()
{
    WebElement element = findDropDownListWithParameters(false);
    dropdownSteps.isDropDownWithNameFound(DropDownState.ENABLED, DROP_DOWN_LIST_NAME);
    verify(baseValidations).assertElementState(eq("The found drop down is ENABLED"), eq(DropDownState.ENABLED),
            argThat((WrapsElement select) -> select.getWrappedElement().equals(element)));
}
 
源代码16 项目: vividus   文件: CheckboxStepsTests.java
@Test
void testIfCheckboxWithAttributeAndStateExist()
{
    when(baseValidations.assertIfElementExists(
            String.format(CHECKBOX_WITH_ATTR_VALUE, CHECKBOX_ATTRIBUTE_TYPE, CHECKBOX_ATTRIBUTE_VALUE),
            new SearchAttributes(ActionAttributeType.XPATH, CHECKBOX_XPATH))).thenReturn(webElement);
    checkboxSteps.ifCheckboxWithAttributeExists(State.ENABLED, CHECKBOX_ATTRIBUTE_TYPE, CHECKBOX_ATTRIBUTE_VALUE);
    verify(baseValidations).assertElementState(THE_FOUND_CHECKBOX_IS + State.ENABLED, State.ENABLED,
            (WrapsElement) new Checkbox(webElement));
}
 
源代码17 项目: selenium   文件: PointerInput.java
public Object asArg() {
  Object arg = originObject;
  while (arg instanceof WrapsElement) {
    arg = ((WrapsElement) arg).getWrappedElement();
  }
  return arg;
}
 
源代码18 项目: selenium   文件: EventFiringWebDriver.java
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()]);
}
 
源代码19 项目: selenium   文件: EventFiringWebDriver.java
@Override
public boolean equals(Object obj) {
  if (!(obj instanceof WebElement)) {
    return false;
  }

  WebElement other = (WebElement) obj;
  if (other instanceof WrapsElement) {
    other = ((WrapsElement) other).getWrappedElement();
  }

  return underlyingElement.equals(other);
}
 
源代码20 项目: vividus   文件: WebDriverUtil.java
public static <T> T unwrap(WebElement webElement, Class<T> clazz)
{
    return unwrap(webElement, WrapsElement.class, WrapsElement::getWrappedElement, clazz);
}
 
源代码21 项目: vividus   文件: BaseValidations.java
@Override
public boolean assertElementState(String businessDescription, IState state, WrapsElement element)
{
    return element != null && assertElementState(businessDescription, state, element.getWrappedElement());
}
 
源代码22 项目: vividus   文件: CheckboxSteps.java
/**
 * Checks if a checkbox with the specified <b>attribute</b> exists in context and it has expected state
 * <p>Actions performed at this step:</p>
 * <ul>
 * <li>Finds a checkbox specified by an <b>attribute type</b> with an <b>attribute value</b>;</li>
 * <li>Compares an actual checkbox 'state' with expected;</li>
 * </ul>
 * @param state A state value of the element (<i>Possible values:</i>
 * <b>ENABLED, DISABLED, SELECTED, NOT_SELECTED, VISIBLE,
 * NOT_VISIBLE</b>)
 * @param attributeType A type of the attribute (for ex. <i>'name', 'id', 'title'</i>)
 * @param attributeValue A value of the attribute
 * @return Web element - a <b>checkbox</b> that meets the requirements,
 * <b> null</b> - if there are no expected elements.
 */
@Then("a [$state] checkbox with the attribute '$attributeType'='$attributeValue' exists")
public WebElement ifCheckboxWithAttributeExists(State state, String attributeType, String attributeValue)
{
    Checkbox checkbox = ifCheckboxWithAttributeExists(attributeType, attributeValue);
    baseValidations.assertElementState(THE_FOUND_CHECKBOX_IS + state, state, (WrapsElement) checkbox);
    return checkbox;
}
 
源代码23 项目: vividus   文件: IMouseActions.java
ClickResult click(WrapsElement element); 
源代码24 项目: vividus   文件: IBaseValidations.java
boolean assertElementState(String businessDescription, IState state, WrapsElement element); 
 类所在包
 类方法
 同包方法