How to use ElementLocatorSearchContext method of org.fluentlenium.core.inject.ElementLocatorSearchContext class

Best FluentLenium code snippet using org.fluentlenium.core.inject.ElementLocatorSearchContext.ElementLocatorSearchContext

Source:ElementLocatorSearchContextTest.java Github

copy

Full Screen

...9import org.openqa.selenium.By;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.support.pagefactory.ElementLocator;12/**13 * Unit test for {@link ElementLocatorSearchContext}.14 */15@RunWith(MockitoJUnitRunner.class)16public class ElementLocatorSearchContextTest {17 @Mock18 private By by;19 @Mock20 private ElementLocator elementLocator;21 @Mock22 private WebElement element1;23 @Mock24 private WebElement element2;25 @Mock26 private WebElement webElement1;27 @Mock28 private WebElement webElement2;29 @Mock30 private WebElement webElement3;31 @Mock32 private WebElement webElement4;33 private ElementLocatorSearchContext locatorSearchContext;34 @Test35 public void shouldFindElements() {36 locatorSearchContext = new ElementLocatorSearchContext(elementLocator);37 when(elementLocator.findElements()).thenReturn(ImmutableList.of(element1, element2));38 when(element1.findElements(by)).thenReturn(ImmutableList.of(webElement1, webElement2));39 when(element2.findElements(by)).thenReturn(ImmutableList.of(webElement3, webElement4));40 assertThat(locatorSearchContext.findElements(by)).containsExactly(webElement1, webElement2, webElement3, webElement4);41 }42 @Test43 public void shouldFindElement() {44 locatorSearchContext = new ElementLocatorSearchContext(elementLocator);45 when(elementLocator.findElement()).thenReturn(element1);46 when(element1.findElement(by)).thenReturn(element2);47 assertThat(locatorSearchContext.findElement(by)).isSameAs(element2);48 }49}

Full Screen

Full Screen

Source:ElementLocatorSearchContext.java Github

copy

Full Screen

...7import java.util.List;8/**9 * Search context backed by an ElementLocator.10 */11public class ElementLocatorSearchContext implements SearchContext {12 private final ElementLocator locator;13 /**14 * Creates a new element locator search context.15 *16 * @param locator element locator17 */18 public ElementLocatorSearchContext(ElementLocator locator) {19 this.locator = locator;20 }21 @Override22 public List<WebElement> findElements(By by) {23 List<WebElement> elements = new ArrayList<>();24 List<WebElement> baseElements = locator.findElements();25 for (WebElement element : baseElements) {26 elements.addAll(element.findElements(by));27 }28 return elements;29 }30 @Override31 public WebElement findElement(By by) {32 return locator.findElement().findElement(by);...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run FluentLenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in ElementLocatorSearchContext

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful