Best FluentLenium code snippet using org.fluentlenium.core.domain.FluentWebElement.getHookControl
Source:FluentWebElement.java
...101 conditions = new WebElementConditions(this);102 label = new FluentLabelImpl<>(this, () -> getElement().toString());103 javascriptActions = new FluentJavascriptActionsImpl<>(this, this.control, new SupplierOfInstance<>(this));104 }105 private HookControl<FluentWebElement> getHookControl() { // NOPMD UnusedPrivateMethod106 return hookControl;107 }108 private FluentJavascriptActionsImpl<FluentWebElement> getJavascriptActions() { //NOPMD UnusedPrivateMethod109 return javascriptActions;110 }111 public FluentLabel<FluentWebElement> getLabel() {112 return label;113 }114 @Override115 public FluentJavascript executeScript(String script, Object... args) {116 return control.executeScript(script, args);117 }118 @Override119 public FluentJavascript executeAsyncScript(String script, Object... args) {120 return control.executeAsyncScript(script, args);121 }122 @Override123 public Alert alert() {124 return control.alert();125 }126 @Override127 public void takeHtmlDump() {128 control.takeHtmlDump();129 }130 @Override131 public void takeHtmlDump(String fileName) {132 control.takeHtmlDump(fileName);133 }134 @Override135 public boolean canTakeScreenShot() {136 return control.canTakeScreenShot();137 }138 @Override139 public void takeScreenshot() {140 control.takeScreenshot();141 }142 @Override143 public void takeScreenshot(String fileName) {144 control.takeScreenshot(fileName);145 }146 @Override147 public EventsRegistry events() {148 return control.events();149 }150 @Override151 public <P extends FluentPage> P goTo(P page) {152 return control.goTo(page);153 }154 @Override155 public void goTo(String url) {156 control.goTo(url);157 }158 @Override159 public void goToInNewTab(String url) {160 control.goToInNewTab(url);161 }162 @Override163 public void switchTo(FluentList<? extends FluentWebElement> elements) {164 control.switchTo(elements);165 }166 @Override167 public void switchTo(FluentWebElement element) {168 control.switchTo(element);169 }170 @Override171 public void switchTo() {172 control.switchTo();173 }174 @Override175 public void switchToDefault() {176 control.switchToDefault();177 }178 @Override179 public String pageSource() {180 return control.pageSource();181 }182 @Override183 public WindowAction window() {184 return control.window();185 }186 @Override187 public Set<Cookie> getCookies() {188 return control.getCookies();189 }190 @Override191 public Cookie getCookie(String name) {192 return control.getCookie(name);193 }194 @Override195 public String url() {196 return control.url();197 }198 @Override199 public WebDriver getDriver() {200 return control.getDriver();201 }202 @Override203 public CssSupport css() {204 return control.css();205 }206 @Override207 public ContainerContext inject(Object container) {208 return control.inject(container);209 }210 @Override211 public ContainerContext injectComponent(Object componentContainer, Object parentContainer, SearchContext context) {212 return control.injectComponent(componentContainer, parentContainer, context);213 }214 @Override215 public <T> T newInstance(Class<T> cls) {216 return control.newInstance(cls);217 }218 @Override219 public FluentWebElement newFluent(WebElement element) {220 return control.newFluent(element);221 }222 @Override223 public <T> T newComponent(Class<T> componentClass, WebElement element) {224 return control.newComponent(componentClass, element);225 }226 @Override227 public FluentList<FluentWebElement> newFluentList() {228 return control.newFluentList();229 }230 @Override231 public FluentList<FluentWebElement> newFluentList(FluentWebElement... elements) {232 return control.newFluentList(elements);233 }234 @Override235 public FluentList<FluentWebElement> newFluentList(List<FluentWebElement> elements) {236 return control.newFluentList(elements);237 }238 @Override239 public FluentList<FluentWebElement> asFluentList(WebElement... elements) {240 return control.asFluentList(elements);241 }242 @Override243 public FluentList<FluentWebElement> asFluentList(Iterable<WebElement> elements) {244 return control.asFluentList(elements);245 }246 @Override247 public FluentList<FluentWebElement> asFluentList(List<WebElement> elements) {248 return control.asFluentList(elements);249 }250 @Override251 public <T extends FluentWebElement> FluentList<T> newFluentList(Class<T> componentClass) {252 return control.newFluentList(componentClass);253 }254 @Override255 public <T extends FluentWebElement> FluentList<T> newFluentList(Class<T> componentClass, T... elements) {256 return control.newFluentList(componentClass, elements);257 }258 @Override259 public <T extends FluentWebElement> FluentList<T> newFluentList(Class<T> componentClass, List<T> elements) {260 return control.newFluentList(componentClass, elements);261 }262 @Override263 public <T extends FluentWebElement> FluentList<T> asFluentList(Class<T> componentClass, WebElement... elements) {264 return control.asFluentList(componentClass, elements);265 }266 @Override267 public <T extends FluentWebElement> FluentList<T> asFluentList(Class<T> componentClass, Iterable<WebElement> elements) {268 return control.asFluentList(componentClass, elements);269 }270 @Override271 public <T extends FluentWebElement> FluentList<T> asFluentList(Class<T> componentClass, List<WebElement> elements) {272 return control.asFluentList(componentClass, elements);273 }274 @Override275 public <T> ComponentList<T> newComponentList(Class<T> componentClass) {276 return control.newComponentList(componentClass);277 }278 @Override279 public <T> ComponentList<T> asComponentList(Class<T> componentClass, WebElement... elements) {280 return control.asComponentList(componentClass, elements);281 }282 @Override283 public <T> ComponentList asComponentList(Class<T> componentClass, Iterable<WebElement> elements) {284 return control.asComponentList(componentClass, elements);285 }286 @Override287 public <T> ComponentList<T> asComponentList(Class<T> componentClass, List<WebElement> elements) {288 return control.asComponentList(componentClass, elements);289 }290 @Override291 public <T> ComponentList<T> newComponentList(Class<T> componentClass, T... componentsList) {292 return control.newComponentList(componentClass, componentsList);293 }294 @Override295 public <T> ComponentList<T> newComponentList(Class<T> componentClass, List<T> componentsList) {296 return control.newComponentList(componentClass, componentsList);297 }298 @Override299 public <L extends List<T>, T> L newComponentList(Class<L> listClass, Class<T> componentClass) {300 return control.newComponentList(listClass, componentClass);301 }302 @Override303 public <L extends List<T>, T> L asComponentList(Class<L> listClass, Class<T> componentClass, WebElement... elements) {304 return control.asComponentList(listClass, componentClass, elements);305 }306 @Override307 public <L extends List<T>, T> L asComponentList(Class<L> listClass, Class<T> componentClass, Iterable<WebElement> elements) {308 return control.asComponentList(listClass, componentClass, elements);309 }310 @Override311 public <L extends List<T>, T> L asComponentList(Class<L> listClass, Class<T> componentClass, List<WebElement> elements) {312 return control.asComponentList(listClass, componentClass, elements);313 }314 @Override315 public <L extends List<T>, T> L newComponentList(Class<L> listClass, Class<T> componentClass, T... componentsList) {316 return control.newComponentList(listClass, componentClass, componentsList);317 }318 @Override319 public <L extends List<T>, T> L newComponentList(Class<L> listClass, Class<T> componentClass, List<T> componentsList) {320 return control.newComponentList(listClass, componentClass, componentsList);321 }322 @Override323 public boolean isComponentClass(Class<?> componentClass) {324 return control.isComponentClass(componentClass);325 }326 @Override327 public boolean isComponentListClass(Class<? extends List<?>> componentListClass) {328 return false;329 }330 @Override331 public Capabilities capabilities() {332 return control.capabilities();333 }334 @Override335 public FluentWebElement click() {336 webElement.click();337 return this;338 }339 @Override340 public FluentWebElement doubleClick() {341 mouse().doubleClick();342 return this;343 }344 @Override345 public FluentWebElement contextClick() {346 mouse().contextClick();347 return this;348 }349 @Override350 public FluentWebElement waitAndClick() {351 return waitAndClick(Duration.ofSeconds(5));352 }353 @Override354 public FluentWebElement waitAndClick(Duration duration) {355 await().atMost(duration).until(this).clickable();356 this.scrollToCenter();357 this.click();358 return this;359 }360 @Override361 public boolean present() {362 return LocatorProxies.present(webElement);363 }364 @Override365 public FluentWebElement now() {366 LocatorProxies.now(webElement);367 return this;368 }369 @Override370 public FluentWebElement now(boolean force) {371 if (force) {372 reset();373 }374 return now();375 }376 @Override377 public FluentWebElement reset() {378 LocatorProxies.reset(webElement);379 return this;380 }381 @Override382 public boolean loaded() {383 return LocatorProxies.loaded(webElement);384 }385 /**386 * XPath Axes accessor (parent, ancestors, preceding, following, ...).387 *388 * @return object to perform XPath Axes transformations.389 * @deprecated Use {@link #dom()} instead.390 */391 @Deprecated392 public Dom axes() {393 return dom;394 }395 /**396 * XPath Axes accessor (parent, ancestors, preceding, following, ...).397 *398 * @return object to perform XPath Axes transformations.399 */400 public Dom dom() {401 return dom;402 }403 /**404 * Get a conditions object used to verify condition on this element.405 *406 * @return conditions object407 */408 public FluentConditions conditions() {409 return conditions;410 }411 /**412 * Build a wait object to wait for a condition of this element.413 *414 * @return a wait object415 */416 public FluentWaitElement await() {417 return new FluentWaitElement(control.await(), this);418 }419 /**420 * Execute mouse actions on the element421 *422 * @return mouse actions object423 */424 public MouseElementActions mouse() {425 return mouseActions;426 }427 /**428 * Execute keyboard actions on the element429 *430 * @return keyboard actions object431 */432 public KeyboardElementActions keyboard() {433 return keyboardActions;434 }435 /**436 * Wrap all underlying elements in a component.437 *438 * @param componentClass component class439 * @param <T> type of component440 * @return element as component.441 */442 public <T> T as(Class<T> componentClass) {443 T component = instantiator.newComponent(componentClass, getElement());444 control.injectComponent(component, this, getElement());445 return component;446 }447 /**448 * Clear the element449 *450 * @return fluent web element451 */452 public FluentWebElement clear() {453 if (!isInputOfTypeFile()) {454 webElement.clear();455 }456 return this;457 }458 /**459 * Clear React input using Backspace only460 *461 * @return fluent web element462 */463 public FluentWebElement clearReactInput() {464 if (this.attribute("value").length() != 0) {465 javascriptActions.modifyAttribute("value", "");466 }467 return this;468 }469 /**470 * Submit the element471 *472 * @return fluent web element473 */474 public FluentWebElement submit() {475 webElement.submit();476 return this;477 }478 /**479 * Set the text element480 *481 * @param text value to set482 * @return fluent web element483 */484 public FluentWebElement write(String... text) {485 clear();486 if (text.length != 0) {487 webElement.sendKeys(text[0]);488 }489 return this;490 }491 /**492 * return the name of the element493 *494 * @return name of the element495 */496 public String name() {497 return webElement.getAttribute("name");498 }499 /**500 * return any value of custom attribute (generated=true will return "true" if attribute("generated") is called.501 *502 * @param name custom attribute name503 * @return name value504 * @see WebElement#getAttribute(String)505 */506 public String attribute(String name) {507 return webElement.getAttribute(name);508 }509 /**510 * Get the value of a given CSS property.511 *512 * @param propertyName the css property name of the element513 * @return The current, computed value of the property.514 * @see WebElement#getCssValue(String)515 */516 public String cssValue(String propertyName) {517 return webElement.getCssValue(propertyName);518 }519 /**520 * return the id of the elements521 *522 * @return id of element523 */524 public String id() {525 return webElement.getAttribute("id");526 }527 /**528 * return the visible text of the element529 *530 * @return text of element531 * @see WebElement#getText()532 */533 public String text() {534 return webElement.getText();535 }536 /**537 * return the text content of the element (even invisible through textContent attribute)538 *539 * @return text content of element540 */541 public String textContent() {542 return webElement.getAttribute("textContent");543 }544 /**545 * return the value of the elements546 *547 * @return value of attribute548 */549 public String value() {550 return webElement.getAttribute("value");551 }552 /**553 * return true if the element is displayed, other way return false554 *555 * @return boolean value of displayed check556 * @see WebElement#isDisplayed()557 */558 public boolean displayed() {559 boolean displayed;560 try {561 displayed = webElement.isDisplayed();562 } catch (NoSuchElementException e) {563 displayed = false;564 }565 return displayed;566 }567 /**568 * return true if the element is enabled, other way return false569 *570 * @return boolean value of enabled check571 * @see WebElement#isEnabled()572 */573 public boolean enabled() {574 boolean enabled;575 try {576 enabled = webElement.isEnabled();577 } catch (NoSuchElementException e) {578 enabled = false;579 }580 return enabled;581 }582 /**583 * return true if the element is selected, other way false584 *585 * @return boolean value of selected check586 * @see WebElement#isSelected()587 */588 public boolean selected() {589 boolean selected;590 try {591 selected = webElement.isSelected();592 } catch (NoSuchElementException e) {593 selected = false;594 }595 return selected;596 }597 /**598 * Check that this element is visible and enabled such that you can click it.599 *600 * @return true if the element can be clicked, false otherwise.601 */602 public boolean clickable() {603 boolean clickable;604 try {605 clickable = ExpectedConditions.elementToBeClickable(getElement())606 .apply(control.getDriver()) != null;607 } catch (NoSuchElementException | StaleElementReferenceException e) {608 clickable = false;609 }610 return clickable;611 }612 /**613 * Check that this element is no longer attached to the DOM.614 *615 * @return false is the element is still attached to the DOM, true otherwise.616 */617 public boolean stale() {618 return ExpectedConditions.stalenessOf(getElement()).apply(control.getDriver());619 }620 /**621 * return the tag name622 *623 * @return string value of tag name624 * @see WebElement#getTagName()625 */626 public String tagName() {627 return webElement.getTagName();628 }629 /**630 * return the webElement631 *632 * @return web element633 */634 public WebElement getElement() {635 return webElement;636 }637 @Override638 public WebElement getWrappedElement() {639 return getElement();640 }641 /**642 * return the size of the element643 *644 * @return dimension/size of element645 * @see WebElement#getSize()646 */647 public Dimension size() {648 return webElement.getSize();649 }650 /**651 * Converts this element as a single element list.652 *653 * @return list of element654 */655 public FluentList<FluentWebElement> asList() {656 return instantiator.asComponentList(FluentListImpl.class, FluentWebElement.class, Arrays.asList(webElement));657 }658 @Override659 public FluentList<FluentWebElement> find(By locator, SearchFilter... filters) {660 return search.find(locator, filters);661 }662 @Override663 public FluentList<FluentWebElement> find(String selector, SearchFilter... filters) {664 return search.find(selector, filters);665 }666 @Override667 public FluentList<FluentWebElement> find(SearchFilter... filters) {668 return search.find(filters);669 }670 @Override671 public FluentList<FluentWebElement> find(List<WebElement> rawElements) {672 return search.find(rawElements);673 }674 @Override675 public FluentWebElement el(WebElement rawElement) {676 return search.el(rawElement);677 }678 /**679 * Get the HTML of a the element680 *681 * @return the underlying html content682 */683 public String html() {684 return webElement.getAttribute("innerHTML");685 }686 @Override687 public Fill<FluentWebElement> fill() {688 return new Fill<>(this);689 }690 @Override691 public FillSelect<FluentWebElement> fillSelect() {692 return new FillSelect<>(this);693 }694 @Override695 public FluentWebElement frame() {696 control.window().switchTo().frame(this);697 return this;698 }699 @Override700 public Optional<FluentWebElement> optional() {701 if (present()) {702 return Optional.of(this);703 } else {704 return Optional.empty();705 }706 }707 /**708 * This method return true if the current FluentWebElement is an input of type file709 *710 * @return boolean value for is input file type711 */712 private boolean isInputOfTypeFile() {713 return "input".equalsIgnoreCase(tagName()) && "file".equalsIgnoreCase(attribute("type"));714 }715 /**716 * Save actual hook definitions to backup.717 *718 * @param hookRestoreStack restore stack719 */720 /* default */ void setHookRestoreStack(Stack<List<HookDefinition<?>>> hookRestoreStack) {721 hookControl.setHookRestoreStack(hookRestoreStack);722 }723 @Override724 public String toString() {725 return label.toString();726 }727 @Override728 public <R> R noHook(Class<? extends FluentHook> hook, Function<FluentWebElement, R> function) {729 return getHookControl().noHook(hook, function);730 }731 @Override732 public <O, H extends FluentHook<O>> FluentWebElement withHook(Class<H> hook, O options) {733 return getHookControl().withHook(hook, options);734 }735 @Override736 public <O, H extends FluentHook<O>> FluentWebElement withHook(Class<H> hook) {737 return getHookControl().withHook(hook);738 }739 @Override740 public FluentWebElement noHook(Class<? extends FluentHook>... hooks) {741 return getHookControl().noHook(hooks);742 }743 @Override744 public <R> R noHook(Function<FluentWebElement, R> function) {745 return getHookControl().noHook(function);746 }747 @Override748 public FluentWebElement noHookInstance(Class<? extends FluentHook>... hooks) {749 return getHookControl().noHookInstance(hooks);750 }751 @Override752 public FluentWebElement restoreHooks() {753 return getHookControl().restoreHooks();754 }755 @Override756 public FluentWebElement noHookInstance() {757 return getHookControl().noHookInstance();758 }759 @Override760 public FluentWebElement noHook() {761 return getHookControl().noHook();762 }763 @Override764 public FluentWebElement scrollToCenter() {765 return getJavascriptActions().scrollToCenter();766 }767 @Override768 public FluentWebElement scrollIntoView() {769 return getJavascriptActions().scrollIntoView();770 }771 @Override772 public FluentWebElement scrollIntoView(boolean alignWithTop) {773 return getJavascriptActions().scrollIntoView(alignWithTop);774 }775 @Override...
Source:FluentListImpl.java
...73 }74 private FluentLabel<FluentList<E>> getLabel() {75 return label;76 }77 private HookControl<FluentList<E>> getHookControl() { //NOPMD UnusedPrivateMethod78 return hookControl;79 }80 private FluentJavascriptActionsImpl<FluentList<E>> getJavascriptActions() { //NOPMD UnusedPrivateMethod81 return javascriptActions;82 }83 @Override84 public List<WebElement> toElements() {85 return this.stream().map(FluentWebElement::getElement).collect(toList());86 }87 @Override88 public FluentWaitElementList await() {89 return new FluentWaitElementList(control.await(), this);90 }91 @Override92 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();412 boolean atLeastOne = false;413 for (E fluentWebElement : this) {414 if (fluentWebElement.conditions().clickable()) {415 atLeastOne = true;416 clickAction.accept(fluentWebElement);417 }418 }419 if (!atLeastOne) {420 throw new NoSuchElementException(LocatorProxies.getMessageContext(proxy)421 + " has no element clickable. At least one element should be clickable to perform a " + clickType + ".");422 }423 return this;424 }425 private void validateListIsNotEmpty() {426 if (size() == 0) {427 throw LocatorProxies.noSuchElement(proxy);428 }429 }430 private FluentList<E> findBy(Function<FluentWebElement, Collection<E>> filteredElementsFinder) {431 List<E> finds = new ArrayList<>();432 for (FluentWebElement e : this) {433 finds.addAll(filteredElementsFinder.apply(e));434 }435 return instantiator.newComponentList(getClass(), componentClass, finds);436 }437 @Override438 public FluentList<E> withLabel(String label) {439 return getLabel().withLabel(label);440 }441 @Override442 public FluentList<E> withLabelHint(String... labelHint) {443 return getLabel().withLabelHint(labelHint);444 }445 @Override446 public FluentList<E> noHookInstance() {447 return getHookControl().noHookInstance();448 }449 @Override450 public FluentList<E> noHook() {451 return getHookControl().noHook();452 }453 @Override454 public <O, H extends FluentHook<O>> FluentList<E> withHook(Class<H> hook) {455 return getHookControl().withHook(hook);456 }457 @Override458 public <R> R noHook(Class<? extends FluentHook> hook, Function<FluentList<E>, R> function) {459 return getHookControl().noHook(hook, function);460 }461 @Override462 public FluentList<E> restoreHooks() {463 return getHookControl().restoreHooks();464 }465 @Override466 public <O, H extends FluentHook<O>> FluentList<E> withHook(Class<H> hook, O options) {467 return getHookControl().withHook(hook, options);468 }469 @Override470 public FluentList<E> noHook(Class<? extends FluentHook>... hooks) {471 return getHookControl().noHook(hooks);472 }473 @Override474 public FluentList<E> noHookInstance(Class<? extends FluentHook>... hooks) {475 return getHookControl().noHookInstance(hooks);476 }477 @Override478 public <R> R noHook(Function<FluentList<E>, R> function) {479 return getHookControl().noHook(function);480 }481 /**482 * Scrolls to first element of list483 *484 * @return this object reference to chain methods calls485 */486 @Override487 public FluentList<E> scrollToCenter() {488 return getJavascriptActions().scrollToCenter();489 }490 /**491 * Scrolls to first element of list492 *493 * @return this object reference to chain methods calls...
getHookControl
Using AI Code Generation
1package org.test;2import org.fluentlenium.adapter.junit.FluentTest;3import org.junit.Test;4import org.junit.runner.RunWith;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.htmlunit.HtmlUnitDriver;7import org.openqa.selenium.support.events.EventFiringWebDriver;8import org.openqa.selenium.support.events.WebDriverEventListener;9import org.springframework.test.context.ContextConfiguration;10import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;11@RunWith(SpringJUnit4ClassRunner.class)12public class 4 extends FluentTest {13 public WebDriver getDefaultDriver() {14 return new EventFiringWebDriver(new HtmlUnitDriver()).register(new WebDriverEventListener() {15 public void beforeAlertAccept(WebDriver driver) {16 System.out.println("beforeAlertAccept");17 }18 public void afterAlertAccept(WebDriver driver) {19 System.out.println("afterAlertAccept");20 }21 public void afterAlertDismiss(WebDriver driver) {22 System.out.println("afterAlertDismiss");23 }24 public void beforeAlertDismiss(WebDriver driver) {25 System.out.println("beforeAlertDismiss");26 }27 public void beforeNavigateTo(String url, WebDriver driver) {28 System.out.println("beforeNavigateTo");29 }30 public void afterNavigateTo(String url, WebDriver driver) {31 System.out.println("afterNavigateTo");32 }33 public void beforeNavigateBack(WebDriver driver) {34 System.out.println("beforeNavigateBack");35 }36 public void afterNavigateBack(WebDriver driver) {37 System.out.println("afterNavigateBack");38 }39 public void beforeNavigateForward(WebDriver driver) {40 System.out.println("beforeNavigateForward");41 }42 public void afterNavigateForward(WebDriver driver) {43 System.out.println("afterNavigateForward");44 }45 public void beforeNavigateRefresh(WebDriver driver) {46 System.out.println("beforeNavigateRefresh");47 }48 public void afterNavigateRefresh(WebDriver driver) {49 System.out.println("afterNavigateRefresh");50 }51 public void beforeFindBy(org.openqa.selenium.By by, org.openqa.selenium.WebElement element, WebDriver driver) {52 System.out.println("beforeFindBy");53 }54 public void afterFindBy(org.openqa.selenium.By by, org.openqa.selenium.WebElement element, WebDriver driver)
getHookControl
Using AI Code Generation
1package testcases;2import org.fluentlenium.adapter.FluentTest;3import org.fluentlenium.core.annotation.Page;4import org.junit.Test;5import org.junit.runner.RunWith;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.htmlunit.HtmlUnitDriver;8import org.openqa.selenium.support.FindBy;9import org.openqa.selenium.support.How;10import org.openqa.selenium.support.ui.Select;11import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;12import pages.GooglePage;13@RunWith(SpringJUnit4ClassRunner.class)14public class GoogleTest extends FluentTest {15 GooglePage googlePage;16 public WebDriver getDefaultDriver() {17 return new HtmlUnitDriver();18 }19 public void test() {20 goTo(googlePage);21 googlePage.fillSearchField("FluentLenium");22 googlePage.clickSearchButton();23 googlePage.getHookControl().click();24 googlePage.getHookControl().click();25 googlePage.getHookControl().click();26 }27}28package pages;29import org.fluentlenium.core.FluentPage;30import org.fluentlenium.core.domain.FluentWebElement;31import org.openqa.selenium.support.FindBy;32public class GooglePage extends FluentPage {33 @FindBy(how = How.NAME, using = "q")34 private FluentWebElement searchField;35 @FindBy(how = How.NAME, using = "btnG")36 private FluentWebElement searchButton;37 @FindBy(how = How.LINK_TEXT, using = "FluentLenium")38 private FluentWebElement hookControl;39 public void fillSearchField(String search) {40 searchField.fill().with(search);41 }42 public void clickSearchButton() {43 searchButton.click();44 }45 public FluentWebElement getHookControl() {46 return hookControl;47 }48}
getHookControl
Using AI Code Generation
1package org.seleniumhq.selenium.fluent;2import org.fluentlenium.core.FluentPage;3import org.fluentlenium.core.annotation.PageUrl;4import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.support.FindBy;8public class FluentPageClass extends FluentPage {9 @FindBy(id = "q")10 WebElement searchBox;11 @FindBy(className = "search-button")12 WebElement searchButton;13 public void isAt() {14 assert (searchBox.isDisplayed());15 }16 public void search(String searchStr) {17 searchBox.click();18 searchBox.sendKeys(searchStr);19 searchButton.click();20 }21 public void searchWithHook(String searchStr) {22 getHookControl(searchBox).click();23 getHookControl(searchBox).sendKeys(searchStr);24 getHookControl(searchButton).click();25 }26}27package org.seleniumhq.selenium.fluent;28import org.fluentlenium.core.FluentPage;29import org.fluentlenium.core.annotation.PageUrl;30import org.openqa.selenium.By;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.WebElement;33import org.openqa.selenium.support.FindBy;34public class FluentPageClass extends FluentPage {35 @FindBy(id = "q")36 WebElement searchBox;37 @FindBy(className = "search-button")38 WebElement searchButton;39 public void isAt() {40 assert (searchBox.isDisplayed());41 }42 public void search(String searchStr) {43 searchBox.click();44 searchBox.sendKeys(searchStr);45 searchButton.click();46 }47 public void searchWithHook(String searchStr) {48 getHookControl(searchBox).click();49 getHookControl(searchBox).sendKeys(searchStr);50 getHookControl(searchButton).click();51 }52}53package org.seleniumhq.selenium.fluent;54import org.fluentlenium.core.FluentPage;55import org.fluentlenium.core.annotation.PageUrl;56import org.openqa.selenium.By;57import org.openqa.selenium.WebDriver;58import org.openqa.selenium.WebElement;59import org.openqa.selenium
getHookControl
Using AI Code Generation
1import org.fluentlenium.core.domain.FluentWebElement;2import org.fluentlenium.core.hook.wait.Wait;3import org.fluentlenium.core.hook.wait.WaitControl;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.support.FindBy;7public class Test extends FluentTest {8 @FindBy(id = "id")9 public FluentWebElement fluentWebElement;10 public void test() {11 WaitControl waitControl = fluentWebElement.getHookControl(Wait.class);
getHookControl
Using AI Code Generation
1package org.fluentlenium.core.domain;2import org.fluentlenium.core.FluentControl;3import org.fluentlenium.core.FluentPage;4import org.fluentlenium.core.components.ComponentInstantiator;5import org.openqa.selenium.By;6import org.openqa.selenium.WebElement;7import java.util.List;8public class FluentWebElement {9 private final WebElement element;10 private final ComponentInstantiator instantiator;11 public FluentWebElement(WebElement element, ComponentInstantiator instantiator) {12 this.element = element;13 this.instantiator = instantiator;14 }15 public FluentWebElement(WebElement element, FluentControl fluentControl) {16 this(element, fluentControl.getInstantiator());17 }18 public FluentWebElement(WebElement element, FluentPage page) {19 this(element, page.getInstantiator());20 }21 public WebElement getElement() {22 return element;23 }24 public ComponentInstantiator getInstantiator() {25 return instantiator;26 }27 public FluentWebElement find(By locator) {28 return instantiator.newFluentWebElement(element.findElement(locator));29 }30 public FluentWebElement find(String locator) {31 return instantiator.newFluentWebElement(element.findElement(By.cssSelector(locator)));32 }33 public List<FluentWebElement> findMany(By locator) {34 return instantiator.newFluentWebElements(element.findElements(locator));35 }36 public List<FluentWebElement> findMany(String locator) {37 return instantiator.newFluentWebElements(element.findElements(By.cssSelector(locator)));38 }39 public FluentWebElement findFirst(By locator) {40 return instantiator.newFluentWebElement(element.findElement(locator));41 }42 public FluentWebElement findFirst(String locator) {43 return instantiator.newFluentWebElement(element.findElement(By.cssSelector(locator)));44 }45 public FluentWebElement findLast(By locator) {46 List<WebElement> elements = element.findElements(locator);47 return instantiator.newFluentWebElement(elements.get(elements.size() - 1));48 }49 public FluentWebElement findLast(String locator) {50 List<WebElement> elements = element.findElements(By.cssSelector(locator));51 return instantiator.newFluentWebElement(elements.get(elements.size() - 1));52 }53 public FluentWebElement getHookControl() {54 return instantiator.newFluentWebElement(element);55 }56}
getHookControl
Using AI Code Generation
1package com.automationrhapsody.fluentlenium;2import static org.fluentlenium.core.filter.FilterConstructor.withText;3import static org.junit.Assert.assertEquals;4import static org.junit.Assert.assertTrue;5import org.fluentlenium.adapter.junit.FluentTest;6import org.junit.Test;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.htmlunit.HtmlUnitDriver;9public class FluentleniumGetHookControlTest extends FluentTest {10 public WebDriver getDefaultDriver() {11 return new HtmlUnitDriver();12 }13 public void testGetHookControl() {14 assertEquals("Automation Rhapsody", title());15 assertTrue($("a", withText("About")).getHookControl().isDisplayed());16 }17}
getHookControl
Using AI Code Generation
1package org.test;2import org.fluentlenium.core.domain.FluentWebElement;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.testng.annotations.AfterTest;8import org.testng.annotations.BeforeTest;9import org.testng.annotations.Test;10public class GetHookControl {11 WebDriver driver;12 public void setup() {13 driver = new ChromeDriver();14 driver.manage().window().maximize();15 }16 public void getHookControl() {17 WebElement hookControl = element.getHookControl();18 System.out.println("Hook Control: " + hookControl);19 }20 public void tearDown() {21 driver.quit();22 }23}24Sr.No. Method Description 1 FluentWebElement(WebElement element) Constructor to initialize the FluentWebElement class. 2 FluentWebElement(WebElement element, FluentControl control, FluentWait fluentWait) Constructor to initialize the FluentWebElement class. 3 FluentWebElement(WebElement element, FluentControl control) Constructor to initialize the FluentWebElement class. 4 FluentWebElement(WebElement element, FluentWait fluentWait) Constructor to initialize the FluentWebElement class. 5 FluentWebElement(WebElement element, FluentControl control, FluentWait fluentWait, FluentList fluentList) Constructor to initialize the FluentWebElement class. 6 FluentWebElement(WebElement element, FluentControl control, FluentList fluentList) Constructor to initialize the FluentWebElement class. 7 FluentWebElement(WebElement element, FluentWait fluentWait, FluentList fluentList) Constructor to initialize the FluentWebElement class. 8 FluentWebElement(WebElement element, FluentList fluentList) Constructor to initialize the FluentWebElement class. 9 FluentWebElement(WebElement element, FluentControl control, FluentWait fluentWait, FluentList fluentList, FluentJavascript fluentJavascript) Constructor to initialize the FluentWebElement class. 10 FluentWebElement(WebElement element, FluentControl control, FluentList fluentList, FluentJavascript fluentJavascript) Constructor to initialize the FluentWebElement class. 11 Fluent
getHookControl
Using AI Code Generation
1package demo;2import org.fluentlenium.core.FluentPage;3import org.fluentlenium.core.hook.wait.Wait;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6public class FluentWebElementDemo extends FluentPage {7 public String getUrl() {8 }9 public void isAt() {10 assert title().equals("Google");11 }12 public void test() {13 WebElement element = find("#lst-ib").getHookControl();14 }15}16package demo;17import org.fluentlenium.core.FluentPage;18import org.fluentlenium.core.hook.wait.Wait;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.WebElement;21public class FluentWebElementDemo extends FluentPage {22 public String getUrl() {23 }24 public void isAt() {25 assert title().equals("Google");26 }27 public void test() {28 WebElement element = find("#lst-ib").getHookControl();29 }30}31package demo;32import org.fluentlenium.core.FluentPage;33import org.fluentlenium.core.hook.wait.Wait;34import org.openqa.selenium.WebDriver;35import org.openqa.selenium.WebElement;36public class FluentWebElementDemo extends FluentPage {37 public String getUrl() {38 }39 public void isAt() {40 assert title().equals("Google");41 }42 public void test() {43 WebElement element = find("#lst-ib").getHookControl();44 }45}46package demo;47import org.fluentlenium.core.FluentPage;48import org.fluentlenium.core.hook.wait.Wait;49import org.openqa.selenium.WebDriver;50import org.openqa.selenium.WebElement;51public class FluentWebElementDemo extends FluentPage {52 public String getUrl() {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!