com.github.hemanthsridhar.pagefactory.FileBasedElementLocator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of custom-page-factory Show documentation
Show all versions of custom-page-factory Show documentation
Custom Page Factory to read web elements or mobile elements from JSON
package com.github.hemanthsridhar.pagefactory;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.pagefactory.AbstractAnnotations;
import org.openqa.selenium.support.pagefactory.ElementLocator;
import java.util.List;
/**
* Created by hemanthsridhar on 1/6/19.
*/
public class FileBasedElementLocator implements ElementLocator {
private final SearchContext searchContext;
private final boolean shouldCache;
private final By by;
private WebElement cachedElement;
private List cachedElementList;
public FileBasedElementLocator(SearchContext searchContext, AbstractAnnotations annotations) {
this.searchContext = searchContext;
this.shouldCache = annotations.isLookupCached();
this.by = annotations.buildBy();
}
@Override
public WebElement findElement() {
if (cachedElement != null && shouldCache) {
return cachedElement;
}
WebElement element = searchContext.findElement(by);
if (shouldCache) {
cachedElement = element;
}
return element;
}
@Override
public List findElements() {
if (cachedElementList != null && shouldCache) {
return cachedElementList;
}
List elements = searchContext.findElements(by);
if (shouldCache) {
cachedElementList = elements;
}
return elements;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " '" + by + "'";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy