Esempio n. 1
0
  @Test
  public void testStateElement() {
    ElementLocator locator = mock(ElementLocator.class);
    when(locator.findElement()).thenReturn(element1);

    WebElement webElement = LocatorProxies.createWebElement(locator);

    assertThat(LocatorProxies.present(webElement)).isTrue();
    webElement.isEnabled();

    when(element1.isEnabled()).thenThrow(StaleElementReferenceException.class);

    assertThat(LocatorProxies.present(webElement)).isFalse();

    reset(element1);
    when(element1.isEnabled()).thenThrow(StaleElementReferenceException.class);

    assertThatThrownBy(
            new ThrowableAssert.ThrowingCallable() {
              @Override
              public void call() throws Throwable {
                webElement.isEnabled();
              }
            })
        .isExactlyInstanceOf(StaleElementReferenceException.class);

    verify(element1, times(6)).isEnabled();
  }
Esempio n. 2
0
  @Test
  public void testIsPresent() {
    ElementLocator locator = mock(ElementLocator.class);
    when(locator.findElement()).thenReturn(element1);
    when(locator.findElements()).thenReturn(Arrays.asList(element1, element2, element3));

    WebElement webElement = LocatorProxies.createWebElement(locator);

    ElementLocator otherLocator = mock(ElementLocator.class);
    WebElement otherWebElement = LocatorProxies.createWebElement(otherLocator);

    assertThat(LocatorProxies.loaded(webElement)).isFalse();
    assertThat(LocatorProxies.present(webElement)).isTrue();
    assertThat(LocatorProxies.loaded(webElement)).isTrue();

    assertThat(LocatorProxies.loaded(otherWebElement)).isFalse();
    assertThat(LocatorProxies.present(otherWebElement)).isFalse();
    assertThat(LocatorProxies.loaded(otherWebElement)).isFalse();

    List<WebElement> webElementList = LocatorProxies.createWebElementList(locator);

    assertThat(LocatorProxies.loaded(webElementList)).isFalse();
    assertThat(LocatorProxies.present(webElementList)).isTrue();
    assertThat(LocatorProxies.loaded(webElementList)).isTrue();

    when(locator.findElements()).thenReturn(Collections.<WebElement>emptyList());

    LocatorProxies.reset(webElementList);

    assertThat(LocatorProxies.loaded(webElementList)).isFalse();
    assertThat(LocatorProxies.present(webElementList)).isFalse();
    assertThat(LocatorProxies.loaded(webElementList)).isTrue();
  }