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 testAlreadyLoadedElementsShouldBeLoaded() {
    WebElement webElement = LocatorProxies.createWebElement(element1);

    assertThat(LocatorProxies.loaded(webElement)).isTrue();
    assertThat(((WrapsElement) webElement).getWrappedElement()).isSameAs(element1);
  }
Esempio n. 3
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. 4
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. 5
0
  @Test
  public void testHashcode() {
    ElementLocator locator = mock(ElementLocator.class);
    when(locator.findElement()).thenReturn(element1);

    WebElement webElement = LocatorProxies.createWebElement(locator);
    assertThat(webElement.hashCode()).isEqualTo(2048 + locator.hashCode());

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

    LocatorProxies.now(webElement);

    assertThat(webElement.hashCode()).isEqualTo(element1.hashCode());
  }
Esempio n. 6
0
  @Test
  public void testToString() {
    when(element1.toString()).thenReturn("element1");

    ElementLocator locator = mock(ElementLocator.class);
    when(locator.findElement()).thenReturn(element1);
    when(locator.toString()).thenReturn("element1-locator");

    WebElement webElement = LocatorProxies.createWebElement(locator);
    assertThat(webElement.toString()).isEqualTo("element1-locator (Lazy Element)");

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

    LocatorProxies.now(webElement);

    assertThat(webElement.toString()).isEqualTo("element1-locator (" + element1.toString() + ")");
  }
Esempio n. 7
0
  @Test
  public void testEquals() {
    ElementLocator locator = mock(ElementLocator.class);
    when(locator.findElement()).thenReturn(element1);

    WebElement webElement = LocatorProxies.createWebElement(locator);
    WebElement sameWebElement = LocatorProxies.createWebElement(locator);

    assertThat(webElement).isEqualTo(sameWebElement);

    ElementLocator otherLocator = mock(ElementLocator.class);
    when(otherLocator.findElement()).thenReturn(element2);
    WebElement otherWebElement = LocatorProxies.createWebElement(otherLocator);

    assertThat(webElement).isNotEqualTo(otherWebElement);

    assertThat(LocatorProxies.loaded(webElement)).isFalse();
    assertThat(LocatorProxies.loaded(sameWebElement)).isFalse();
    assertThat(LocatorProxies.loaded(otherWebElement)).isFalse();

    LocatorProxies.now(webElement);

    assertThat(webElement).isEqualTo(sameWebElement);

    assertThat(LocatorProxies.loaded(webElement)).isTrue();
    assertThat(LocatorProxies.loaded(sameWebElement)).isTrue();
    assertThat(LocatorProxies.loaded(otherWebElement)).isFalse();

    LocatorProxies.reset(webElement);
    LocatorProxies.reset(sameWebElement);
    LocatorProxies.reset(otherWebElement);

    assertThat(LocatorProxies.loaded(webElement)).isFalse();
    assertThat(LocatorProxies.loaded(sameWebElement)).isFalse();
    assertThat(LocatorProxies.loaded(otherWebElement)).isFalse();

    LocatorProxies.now(webElement);

    assertThat(sameWebElement).isEqualTo(webElement);

    assertThat(LocatorProxies.loaded(webElement)).isTrue();
    assertThat(LocatorProxies.loaded(sameWebElement)).isTrue();
    assertThat(LocatorProxies.loaded(otherWebElement)).isFalse();

    assertThat(webElement).isNotEqualTo(otherWebElement);

    assertThat(LocatorProxies.loaded(otherWebElement)).isTrue();
  }