Esempio n. 1
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();
  }
Esempio n. 2
0
  @Test
  public void testAlreadyLoadedElementListShouldBeLoaded() {
    List<WebElement> webElementList =
        LocatorProxies.createWebElementList(Arrays.asList(element1, element2, element3));

    assertThat(LocatorProxies.loaded(webElementList)).isTrue();
    assertThat(((WrapsElements) webElementList).getWrappedElements())
        .containsExactly(element1, element2, element3);
  }
Esempio n. 3
0
  @Test
  public void testIndex() {
    ElementLocator locator = mock(ElementLocator.class);
    when(locator.findElements()).thenReturn(Arrays.asList(element1, element2, element3));

    List<WebElement> webElementList = LocatorProxies.createWebElementList(locator);
    WebElement atIndex = LocatorProxies.index(webElementList, 1);

    assertThat(LocatorProxies.loaded(atIndex)).isFalse();
    assertThat(atIndex).isEqualTo(element2);
  }
Esempio n. 4
0
  @Test
  public void testNullElementListShouldNotThrowException() {
    List<WebElement> webElementList = LocatorProxies.createWebElementList((List<WebElement>) null);
    assertThat(webElementList).isEmpty();

    List<WebElement> webElementList2 =
        LocatorProxies.createWebElementList(
            new ElementLocator() {
              @Override
              public WebElement findElement() {
                return null;
              }

              @Override
              public List<WebElement> findElements() {
                return null;
              }
            });
    assertThat(webElementList2).isEmpty();
  }