How to use configureComponentWithHooks method of org.fluentlenium.core.domain.FluentListImpl class

Best FluentLenium code snippet using org.fluentlenium.core.domain.FluentListImpl.configureComponentWithHooks

Source:FluentListImpl.java Github

copy

Full Screen

...92 public E first() {93 if (!LocatorProxies.loaded(proxy)) {94 E component = instantiator.newComponent(componentClass, LocatorProxies.first(proxy));95 configureComponentWithLabel(component);96 configureComponentWithHooks(component);97 return component;98 }99 validateListIsNotEmpty();100 return get(0);101 }102 @Override103 public E single() {104 if (size() > 1) {105 throw new AssertionError(106 String.format("%s list should contain one element only but there are [ %s ] elements instead",107 LocatorProxies.getMessageContext(proxy), size()));108 }109 return first();110 }111 @Override112 public E last() {113 if (!LocatorProxies.loaded(proxy)) {114 E component = instantiator.newComponent(componentClass, LocatorProxies.last(proxy));115 configureComponentWithLabel(component);116 configureComponentWithHooks(component);117 return component;118 }119 validateListIsNotEmpty();120 return get(size() - 1);121 }122 @Override123 public E get(int index) {124 return index(index);125 }126 @Override127 public E index(int index) {128 if (!LocatorProxies.loaded(proxy) && !componentClass.equals(FluentWebElement.class)) {129 E component = instantiator.newComponent(componentClass, LocatorProxies.index(proxy, index));130 configureComponentWithLabel(component);131 configureComponentWithHooks(component);132 if (component instanceof FluentWebElement) {133 component.setHookRestoreStack(hookControl.getHookRestoreStack());134 }135 return component.reset().as(componentClass);136 }137 if (size() <= index) {138 throw LocatorProxies.noSuchElement(proxy);139 }140 return super.get(index);141 }142 @Override143 public int count() {144 if (proxy != null) {145 LocatorHandler locatorHandler = LocatorProxies.getLocatorHandler(proxy);146 if (locatorHandler != null) {147 return locatorHandler.getLocator().findElements().size();148 }149 }150 return super.size();151 }152 @Override153 public boolean present() {154 if (LocatorProxies.getLocatorHandler(proxy) != null) {155 return LocatorProxies.present(this);156 }157 return size() > 0;158 }159 @Override160 public FluentList<E> now() {161 LocatorProxies.now(this);162 validateListIsNotEmpty();163 return this;164 }165 @Override166 public FluentList<E> now(boolean force) {167 if (force) {168 reset();169 }170 return now();171 }172 @Override173 public FluentList<E> reset() {174 LocatorProxies.reset(this);175 return this;176 }177 @Override178 public boolean loaded() {179 return LocatorProxies.loaded(this);180 }181 @Override182 public FluentList<E> click() {183 return doClick(FluentWebElement::click, "click");184 }185 @Override186 public FluentList<E> doubleClick() {187 return doClick(FluentWebElement::doubleClick, "double click");188 }189 @Override190 public FluentList<E> contextClick() {191 return doClick(FluentWebElement::contextClick, "context click");192 }193 @Override194 public FluentList<E> waitAndClick() {195 return waitAndClick(Duration.ofSeconds(5));196 }197 @Override198 public FluentList<E> waitAndClick(Duration duration) {199 validateListIsNotEmpty();200 await().atMost(duration).until(this).clickable();201 this.scrollToCenter();202 this.click();203 return this;204 }205 @Override206 public FluentList<E> write(String... with) {207 validateListIsNotEmpty();208 boolean atLeastOne = false;209 if (with.length > 0) {210 int id = 0;211 String value;212 for (E fluentWebElement : this) {213 if (fluentWebElement.displayed()) {214 if (with.length > id) {215 value = with[id++];216 } else {217 value = with[with.length - 1];218 }219 if (fluentWebElement.enabled()) {220 atLeastOne = true;221 fluentWebElement.write(value);222 }223 }224 }225 if (!atLeastOne) {226 throw new NoSuchElementException(227 LocatorProxies.getMessageContext(proxy) + " has no element displayed and enabled."228 + " At least one element should be displayed and enabled to define values.");229 }230 }231 return this;232 }233 @Override234 public FluentList<E> clearAll() {235 validateListIsNotEmpty();236 boolean atLeastOne = false;237 for (E fluentWebElement : this) {238 if (fluentWebElement.enabled()) {239 atLeastOne = true;240 fluentWebElement.clear();241 }242 }243 if (!atLeastOne) {244 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy) + " has no element enabled."245 + " At least one element should be enabled to clear values.");246 }247 return this;248 }249 @Override250 public FluentList<E> clearAllReactInputs() {251 validateListIsNotEmpty();252 boolean atLeastOne = false;253 for (E fluentWebElement : this) {254 if (fluentWebElement.enabled()) {255 atLeastOne = true;256 fluentWebElement.clearReactInput();257 }258 }259 if (!atLeastOne) {260 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy) + " has no element enabled."261 + " At least one element should be enabled to clear values.");262 }263 return this;264 }265 @Override266 public void clearList() {267 list.clear();268 }269 @Override270 public FluentListConditions each() {271 return new EachElementConditions(this);272 }273 @Override274 public FluentListConditions one() {275 return new AtLeastOneElementConditions(this);276 }277 @Override278 public FluentListConditions awaitUntilEach() {279 return WaitConditionProxy280 .each(control.await(), toString(), new SupplierOfInstance<List<? extends FluentWebElement>>(this));281 }282 @Override283 public FluentListConditions awaitUntilOne() {284 return WaitConditionProxy285 .one(control.await(), toString(), new SupplierOfInstance<List<? extends FluentWebElement>>(this));286 }287 @Override288 public FluentList<E> submit() {289 validateListIsNotEmpty();290 boolean atLeastOne = false;291 for (E fluentWebElement : this) {292 if (fluentWebElement.enabled()) {293 atLeastOne = true;294 fluentWebElement.submit();295 }296 }297 if (!atLeastOne) {298 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy) + " has no element enabled."299 + " At least one element should be enabled to perform a submit.");300 }301 return this;302 }303 @Override304 public List<String> values() {305 return stream().map(FluentWebElement::value).collect(toList());306 }307 @Override308 public List<String> ids() {309 return stream().map(FluentWebElement::id).collect(toList());310 }311 @Override312 public List<String> attributes(String attribute) {313 return stream().map(webElement -> webElement.attribute(attribute)).collect(toList());314 }315 @Override316 public List<String> names() {317 return stream().map(FluentWebElement::name).collect(toList());318 }319 @Override320 public List<Dimension> dimensions() {321 return stream().map(FluentWebElement::size).collect(toList());322 }323 @Override324 public List<String> tagNames() {325 return stream().map(FluentWebElement::tagName).collect(toList());326 }327 @Override328 public List<String> textContents() {329 return stream().map(FluentWebElement::textContent).collect(toList());330 }331 @Override332 public List<String> texts() {333 return stream().map(FluentWebElement::text).collect(toList());334 }335 @Override336 public FluentList<E> find(List<WebElement> rawElements) {337 return (FluentList<E>) control.find(rawElements);338 }339 @Override340 public FluentList<E> $(List<WebElement> rawElements) {341 return (FluentList<E>) control.$(rawElements);342 }343 @Override344 public E el(WebElement rawElement) {345 return (E) control.el(rawElement);346 }347 @Override348 public FluentList<E> find(String selector, SearchFilter... filters) {349 return findBy(e -> (Collection<E>) e.find(selector, filters));350 }351 @Override352 public FluentList<E> find(By locator, SearchFilter... filters) {353 return findBy(e -> (Collection<E>) e.find(locator, filters));354 }355 @Override356 public FluentList<E> find(SearchFilter... filters) {357 return findBy(e -> (Collection<E>) e.find(filters));358 }359 @Override360 public Fill fill() {361 return new Fill(this);362 }363 @Override364 public FillSelect fillSelect() {365 return new FillSelect(this);366 }367 @Override368 public FluentList<E> frame() {369 control.window().switchTo().frame(first());370 return this;371 }372 @Override373 public Optional<FluentList<E>> optional() {374 if (present()) {375 return Optional.of(this);376 } else {377 return Optional.empty();378 }379 }380 @Override381 public <T extends FluentWebElement> FluentList<T> as(Class<T> componentClass) {382 return instantiator383 .newComponentList(getClass(), componentClass,384 this385 .stream()386 .map(e -> e.as(componentClass))387 .collect(toList()));388 }389 @Override390 public void clear() {391 clearAll();392 }393 @Override394 public String toString() {395 return label.toString();396 }397 private void configureComponentWithHooks(E component) {398 if (component instanceof HookControl) {399 for (HookDefinition definition : hookControl.getHookDefinitions()) {400 component.withHook(definition.getHookClass(), definition.getOptions());401 }402 }403 }404 private void configureComponentWithLabel(E component) {405 if (component instanceof FluentLabel) {406 component.withLabel(label.getLabel());407 component.withLabelHint(label.getLabelHints());408 }409 }410 private FluentList<E> doClick(Consumer<FluentWebElement> clickAction, String clickType) {411 validateListIsNotEmpty();...

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful