@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(); }
@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); }