How to use LocatorProxies method of org.fluentlenium.core.proxy.LocatorProxies class

Best FluentLenium code snippet using org.fluentlenium.core.proxy.LocatorProxies.LocatorProxies

Source:FluentListImpl.java Github

copy

Full Screen

...18import org.fluentlenium.core.hook.HookDefinition;19import org.fluentlenium.core.label.FluentLabel;20import org.fluentlenium.core.label.FluentLabelImpl;21import org.fluentlenium.core.proxy.LocatorHandler;22import org.fluentlenium.core.proxy.LocatorProxies;23import org.fluentlenium.core.search.SearchFilter;24import org.fluentlenium.core.wait.FluentWaitElementList;25import org.fluentlenium.utils.SupplierOfInstance;26import org.openqa.selenium.By;27import org.openqa.selenium.NoSuchElementException;28import org.openqa.selenium.WebElement;29import org.openqa.selenium.support.pagefactory.ElementLocator;30import java.util.ArrayList;31import java.util.Collection;32import java.util.List;33/**34 * Map the list to a FluentList in order to offers some events like click(), submit(), value() ...35 *36 * @param <E> type of fluent element37 */38@SuppressWarnings({"PMD.GodClass", "PMD.ExcessivePublicCount"})39public class FluentListImpl<E extends FluentWebElement> extends ComponentList<E> implements FluentList<E> {40 private final FluentLabelImpl<FluentList<E>> label;41 private final HookControlImpl<FluentList<E>> hookControl;42 private final FluentJavascriptActionsImpl<FluentList<E>> javascriptActions;43 /**44 * Creates a new fluent list.45 *46 * @param componentClass component class47 * @param list list of fluent element48 * @param control control interface49 * @param instantiator component instantiator50 */51 public FluentListImpl(Class<E> componentClass, List<E> list, FluentControl control,52 ComponentInstantiator instantiator) {53 super(componentClass, list, control, instantiator);54 hookControl = new HookControlImpl<>(this, proxy, control, instantiator, (Supplier<FluentList<E>>) () -> {55 LocatorHandler locatorHandler = LocatorProxies.getLocatorHandler(proxy);56 ElementLocator locator = locatorHandler.getLocator();57 List<WebElement> webElementList = LocatorProxies.createWebElementList(locator);58 return instantiator.asComponentList(this.getClass(), componentClass, webElementList);59 });60 label = new FluentLabelImpl<>(this, list::toString);61 javascriptActions = new FluentJavascriptActionsImpl<>(this, this.control, new Supplier<FluentWebElement>() {62 @Override63 public FluentList<E> get() {64 LocatorHandler locatorHandler = LocatorProxies.getLocatorHandler(proxy);65 ElementLocator locator = locatorHandler.getLocator();66 List<WebElement> webElementList = LocatorProxies.createWebElementList(locator);67 return instantiator.asComponentList(FluentListImpl.this.getClass(), componentClass, webElementList);68 }69 });70 label = new FluentLabelImpl<FluentList<E>>(this, new Supplier<String>() {71 @Override72 public String get() {73 return list.toString();74 }75 });76 javascriptActions = new FluentJavascriptActionsImpl<FluentList<E>>(this, this.control,77 new Supplier<FluentWebElement>() {78 @Override79 public FluentWebElement get() {80 return first();81 }82 @Override83 public String toString() {84 return String.valueOf(first());85 }86 });87 }88 @Delegate89 private FluentLabel<FluentList<E>> getLabel() {90 return label;91 }92 @Delegate93 private HookControl<FluentList<E>> getHookControl() { //NOPMD UnusedPrivateMethod94 return hookControl;95 }96 @Delegate97 private FluentJavascriptActionsImpl<FluentList<E>> getJavascriptActions() { //NOPMD UnusedPrivateMethod98 return javascriptActions;99 }100 @Override101 public List<WebElement> toElements() {102 ArrayList<WebElement> elements = new ArrayList<>();103 for (FluentWebElement fluentElement : this) {104 elements.add(fluentElement.getElement());105 }106 return elements;107 }108 @Override109 public FluentWaitElementList await() {110 return new FluentWaitElementList(control.await(), this);111 }112 @Override113 public E first() {114 if (!LocatorProxies.loaded(proxy)) {115 E component = instantiator.newComponent(componentClass, LocatorProxies.first(proxy));116 if (component instanceof FluentLabel) {117 component.withLabel(label.getLabel());118 component.withLabelHint(label.getLabelHints());119 }120 if (component instanceof HookControl) {121 for (HookDefinition definition : hookControl.getHookDefinitions()) {122 component.withHook(definition.getHookClass(), definition.getOptions());123 }124 }125 return component;126 }127 if (size() == 0) {128 throw LocatorProxies.noSuchElement(proxy);129 }130 return get(0);131 }132 @Override133 public E last() {134 if (!LocatorProxies.loaded(proxy)) {135 E component = instantiator.newComponent(componentClass, LocatorProxies.last(proxy));136 if (component instanceof FluentLabel) {137 component.withLabel(label.getLabel());138 component.withLabelHint(label.getLabelHints());139 }140 if (component instanceof HookControl) {141 for (HookDefinition definition : hookControl.getHookDefinitions()) {142 component.withHook(definition.getHookClass(), definition.getOptions());143 }144 }145 return component;146 }147 if (size() == 0) {148 throw LocatorProxies.noSuchElement(proxy);149 }150 return get(size() - 1);151 }152 @Override153 public E index(int index) {154 if (!LocatorProxies.loaded(proxy)) {155 E component = instantiator.newComponent(componentClass, LocatorProxies.index(proxy, index));156 if (component instanceof FluentLabel) {157 component.withLabel(label.getLabel());158 component.withLabelHint(label.getLabelHints());159 }160 if (component instanceof HookControl) {161 for (HookDefinition definition : hookControl.getHookDefinitions()) {162 component.withHook(definition.getHookClass(), definition.getOptions());163 }164 }165 if (component instanceof FluentWebElement) {166 component.setHookRestoreStack(hookControl.getHookRestoreStack());167 }168 return component;169 }170 if (size() <= index) {171 throw LocatorProxies.noSuchElement(proxy);172 }173 return get(index);174 }175 @Override176 public int count() {177 if (loaded()) {178 return super.size();179 } else {180 return LocatorProxies.getLocatorHandler(proxy).getLocator().findElements().size();181 }182 }183 @Override184 public boolean present() {185 if (LocatorProxies.getLocatorHandler(proxy) != null) {186 return LocatorProxies.present(this);187 }188 return size() > 0;189 }190 @Override191 public FluentList<E> now() {192 LocatorProxies.now(this);193 if (size() == 0) {194 throw LocatorProxies.noSuchElement(proxy);195 }196 return this;197 }198 @Override199 public FluentList<E> now(boolean force) {200 if (force) {201 reset();202 }203 return now();204 }205 @Override206 public FluentList<E> reset() {207 LocatorProxies.reset(this);208 return this;209 }210 @Override211 public boolean loaded() {212 return LocatorProxies.loaded(this);213 }214 @Override215 public FluentList click() {216 if (size() == 0) {217 throw LocatorProxies.noSuchElement(proxy);218 }219 boolean atLeastOne = false;220 for (E fluentWebElement : this) {221 if (fluentWebElement.conditions().clickable()) {222 atLeastOne = true;223 fluentWebElement.click();224 }225 }226 if (!atLeastOne) {227 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy) + " has no element clickable."228 + " At least one element should be clickable to perform a click.");229 }230 return this;231 }232 @Override233 public FluentList doubleClick() {234 if (size() == 0) {235 throw LocatorProxies.noSuchElement(proxy);236 }237 boolean atLeastOne = false;238 for (E fluentWebElement : this) {239 if (fluentWebElement.conditions().clickable()) {240 atLeastOne = true;241 fluentWebElement.doubleClick();242 }243 }244 if (!atLeastOne) {245 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy) + " has no element clickable."246 + " At least one element should be clickable to perform a double click.");247 }248 return this;249 }250 @Override251 public FluentList<E> contextClick() {252 if (size() == 0) {253 throw LocatorProxies.noSuchElement(proxy);254 }255 boolean atLeastOne = false;256 for (E fluentWebElement : this) {257 if (fluentWebElement.conditions().clickable()) {258 atLeastOne = true;259 fluentWebElement.contextClick();260 }261 }262 if (!atLeastOne) {263 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy) + " has no element clickable."264 + " At least one element should be clickable to perform a context click.");265 }266 return this;267 }268 @Override269 public FluentList write(String... with) {270 if (size() == 0) {271 throw LocatorProxies.noSuchElement(proxy);272 }273 boolean atLeastOne = false;274 if (with.length > 0) {275 int id = 0;276 String value;277 for (E fluentWebElement : this) {278 if (fluentWebElement.displayed()) {279 if (with.length > id) {280 value = with[id++];281 } else {282 value = with[with.length - 1];283 }284 if (fluentWebElement.enabled()) {285 atLeastOne = true;286 fluentWebElement.write(value);287 }288 }289 }290 if (!atLeastOne) {291 throw new NoSuchElementException(292 LocatorProxies.getMessageContext(proxy) + " has no element displayed and enabled."293 + " At least one element should be displayed and enabled to define values.");294 }295 }296 return this;297 }298 @Override299 public FluentList<E> clearAll() {300 if (size() == 0) {301 throw LocatorProxies.noSuchElement(proxy);302 }303 boolean atLeastOne = false;304 for (E fluentWebElement : this) {305 if (fluentWebElement.enabled()) {306 atLeastOne = true;307 fluentWebElement.clear();308 }309 }310 if (!atLeastOne) {311 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy) + " has no element enabled."312 + " At least one element should be enabled to clear values.");313 }314 return this;315 }316 @Override317 public void clearList() {318 list.clear();319 }320 @Override321 public FluentListConditions each() {322 return new EachElementConditions(this);323 }324 @Override325 public FluentListConditions one() {326 return new AtLeastOneElementConditions(this);327 }328 @Override329 public FluentListConditions awaitUntilEach() {330 return WaitConditionProxy331 .each(control.await(), toString(), new SupplierOfInstance<List<? extends FluentWebElement>>(this));332 }333 @Override334 public FluentListConditions awaitUntilOne() {335 return WaitConditionProxy336 .one(control.await(), toString(), new SupplierOfInstance<List<? extends FluentWebElement>>(this));337 }338 @Override339 public FluentList<E> submit() {340 if (size() == 0) {341 throw LocatorProxies.noSuchElement(proxy);342 }343 boolean atLeastOne = false;344 for (E fluentWebElement : this) {345 if (fluentWebElement.enabled()) {346 atLeastOne = true;347 fluentWebElement.submit();348 }349 }350 if (!atLeastOne) {351 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy) + " has no element enabled."352 + " At least one element should be enabled to perform a submit.");353 }354 return this;355 }356 @Override357 public List<String> values() {358 return stream().map(FluentWebElement::value).collect(Collectors.toList());359 }360 @Override361 public List<String> ids() {362 return stream().map(FluentWebElement::id).collect(Collectors.toList());363 }364 @Override365 public List<String> attributes(final String attribute) {...

Full Screen

Full Screen

LocatorProxies

Using AI Code Generation

copy

Full Screen

1LocatorProxies proxyLocator = new LocatorProxies();2proxyLocator.getLocator();3LocatorProxies proxyLocator = new LocatorProxies();4proxyLocator.getLocator();5LocatorProxies proxyLocator = new LocatorProxies();6proxyLocator.getLocator();7LocatorProxies proxyLocator = new LocatorProxies();8proxyLocator.getLocator();9LocatorProxies proxyLocator = new LocatorProxies();10proxyLocator.getLocator();11LocatorProxies proxyLocator = new LocatorProxies();12proxyLocator.getLocator();13LocatorProxies proxyLocator = new LocatorProxies();14proxyLocator.getLocator();15LocatorProxies proxyLocator = new LocatorProxies();16proxyLocator.getLocator();17LocatorProxies proxyLocator = new LocatorProxies();18proxyLocator.getLocator();19LocatorProxies proxyLocator = new LocatorProxies();20proxyLocator.getLocator();21LocatorProxies proxyLocator = new LocatorProxies();22proxyLocator.getLocator();23LocatorProxies proxyLocator = new LocatorProxies();24proxyLocator.getLocator();25LocatorProxies proxyLocator = new LocatorProxies();26proxyLocator.getLocator();

Full Screen

Full Screen

LocatorProxies

Using AI Code Generation

copy

Full Screen

1public class FluentLeniumTest extends FluentTest {2 public WebDriver newWebDriver() {3 return new HtmlUnitDriver();4 }5 public String getBaseUrl() {6 }7 public void testFluentLenium() {8 goTo(getBaseUrl());9 WebElement element = find("#lst-ib").getElement();10 By locator = LocatorProxies.getLocator(element);11 System.out.println(locator);12 }13}

Full Screen

Full Screen

LocatorProxies

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.core.proxy.LocatorProxies;2import org.fluentlenium.core.proxy.WebElementLocatorProxy;3import org.openqa.selenium.WebElement;4WebElementLocatorProxy proxy = LocatorProxies.getLocatorProxy(WebElement.class);5WebElement element = proxy.getLocator();6System.out.println("proxy = " + proxy);7System.out.println("element = " + element);

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful