How to use click method of org.fluentlenium.core.hook.NanoHook class

Best FluentLenium code snippet using org.fluentlenium.core.hook.NanoHook.click

Source:FluentInjectorHookTest.java Github

copy

Full Screen

...62 WebElement element = mock(WebElement.class);63 when(webDriver.findElement(new ByIdOrName("injected"))).thenReturn(element);64 injector.inject(container);65 assertThat(container.injected).isNotNull();66 container.injected.getElement().click();67 verify(element).click();68 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(container.injected.getElement());69 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);70 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);71 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);72 assertThat(elementWrapperHook.getOptionValue()).isEqualTo(null);73 assertThat(elementWrapperHook.getBeforeFindElementNano()).isNotEqualTo(0L);74 assertThat(elementWrapperHook.getAfterFindElementNano()).isNotEqualTo(0L);75 assertThat(elementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);76 assertThat(elementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);77 }78 public static class Options extends NanoHookOptions {79 public Options() {80 super("options");81 }82 }83 public static class FluentWebElementOptionContainer {84 @Hook(NanoHook.class)85 @HookOptions(Options.class)86 private FluentWebElement injected;87 }88 @Test89 public void testFluentWebElementOption() {90 FluentWebElementOptionContainer container = new FluentWebElementOptionContainer();91 WebElement element = mock(WebElement.class);92 when(webDriver.findElement(new ByIdOrName("injected"))).thenReturn(element);93 injector.inject(container);94 assertThat(container.injected).isNotNull();95 container.injected.getElement().click();96 verify(element).click();97 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(container.injected.getElement());98 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);99 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);100 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);101 assertThat(elementWrapperHook.getOptionValue()).isEqualTo("options");102 assertThat(elementWrapperHook.getBeforeFindElementNano()).isNotEqualTo(0L);103 assertThat(elementWrapperHook.getAfterFindElementNano()).isNotEqualTo(0L);104 assertThat(elementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);105 assertThat(elementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);106 }107 public static class WebElementWrapper {108 private final WebElement element;109 public WebElementWrapper(WebElement element) {110 this.element = element;111 }112 public WebElement getElement() {113 return element;114 }115 }116 public static class WebElementWrapperContainer {117 @Hook(NanoHook.class)118 private WebElementWrapper injected;119 }120 @Test121 public void testWebElementWrapper() {122 WebElementWrapperContainer container = new WebElementWrapperContainer();123 WebElement element = mock(WebElement.class);124 when(webDriver.findElement(new ByIdOrName("injected"))).thenReturn(element);125 injector.inject(container);126 assertThat(container.injected).isNotNull();127 container.injected.getElement().click();128 verify(element).click();129 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(container.injected.getElement());130 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);131 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);132 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);133 assertThat(elementWrapperHook.getBeforeFindElementNano()).isNotEqualTo(0L);134 assertThat(elementWrapperHook.getAfterFindElementNano()).isNotEqualTo(0L);135 assertThat(elementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);136 assertThat(elementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);137 }138 public static class FluentListContainer {139 @Hook(NanoHook.class)140 private FluentList<FluentWebElement> injected;141 }142 @Test143 public void testFluentList() {144 FluentListContainer container = new FluentListContainer();145 WebElement element1 = mock(WebElement.class);146 WebElement element2 = mock(WebElement.class);147 WebElement element3 = mock(WebElement.class);148 when(webDriver.findElements(new ByIdOrName("injected"))).thenReturn(Arrays.asList(element1, element2, element3));149 injector.inject(container);150 LocatorHandler listLocatorHandler = LocatorProxies.getLocatorHandler(container.injected);151 NanoHook listLocatorHook = (NanoHook) listLocatorHandler.getHookLocator();152 assertThat(listLocatorHook.getBeforeFindElementNano()).isEqualTo(0L);153 assertThat(listLocatorHook.getAfterFindElementNano()).isEqualTo(0L);154 assertThat(listLocatorHook.getBeforeFindElementsNano()).isEqualTo(0L);155 assertThat(listLocatorHook.getAfterFindElementsNano()).isEqualTo(0L);156 assertThat(container.injected).hasSize(3);157 assertThat(listLocatorHook.getBeforeFindElementNano()).isEqualTo(0L);158 assertThat(listLocatorHook.getAfterFindElementNano()).isEqualTo(0L);159 assertThat(listLocatorHook.getBeforeFindElementsNano()).isNotEqualTo(0L);160 assertThat(listLocatorHook.getAfterFindElementsNano()).isNotEqualTo(0L);161 for (FluentWebElement webElement : container.injected) {162 assertThat(webElement).isNotNull();163 webElement.click();164 verify(LocatorProxies.getLocatorResult(webElement.getElement())).click();165 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(webElement.getElement());166 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);167 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);168 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);169 assertThat(elementWrapperHook.getBeforeFindElementNano()).isEqualTo(0L);170 assertThat(elementWrapperHook.getAfterFindElementNano()).isEqualTo(0L);171 assertThat(elementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);172 assertThat(elementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);173 }174 }175 public static class WebElementWrapperListContainer {176 @Hook(NanoHook.class)177 private List<WebElementWrapper> injected;178 }179 @Test180 public void testWebElementWrapperList() {181 WebElementWrapperListContainer container = new WebElementWrapperListContainer();182 WebElement element1 = mock(WebElement.class);183 WebElement element2 = mock(WebElement.class);184 WebElement element3 = mock(WebElement.class);185 when(webDriver.findElements(new ByIdOrName("injected"))).thenReturn(Arrays.asList(element1, element2, element3));186 injector.inject(container);187 LocatorHandler listLocatorHandler = LocatorProxies.getLocatorHandler(container.injected);188 NanoHook listLocatorHook = (NanoHook) listLocatorHandler.getHookLocator();189 assertThat(listLocatorHook.getBeforeFindElementNano()).isEqualTo(0L);190 assertThat(listLocatorHook.getAfterFindElementNano()).isEqualTo(0L);191 assertThat(listLocatorHook.getBeforeFindElementsNano()).isEqualTo(0L);192 assertThat(listLocatorHook.getAfterFindElementsNano()).isEqualTo(0L);193 assertThat(container.injected).hasSize(3);194 assertThat(listLocatorHook.getBeforeFindElementNano()).isEqualTo(0L);195 assertThat(listLocatorHook.getAfterFindElementNano()).isEqualTo(0L);196 assertThat(listLocatorHook.getBeforeFindElementsNano()).isNotEqualTo(0L);197 assertThat(listLocatorHook.getAfterFindElementsNano()).isNotEqualTo(0L);198 for (WebElementWrapper webElement : container.injected) {199 assertThat(webElement).isNotNull();200 webElement.getElement().click();201 verify(LocatorProxies.getLocatorResult(webElement.getElement())).click();202 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(webElement.getElement());203 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);204 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);205 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);206 }207 }208 public static class NanoHook2 extends NanoHook {209 public NanoHook2(FluentControl fluentControl, ComponentInstantiator instantiator, Supplier<WebElement> elementSupplier,210 Supplier<ElementLocator> locatorSupplier, Supplier<String> toStringSupplier, NanoHookOptions options) {211 super(fluentControl, instantiator, elementSupplier, locatorSupplier, toStringSupplier, options);212 }213 }214 @NoHook215 public static class SubContainer3 {216 private WebElementWrapper subInjected3;217 }218 @Hook(NanoHook2.class)219 public static class SubContainer2 extends FluentPage {220 private WebElementWrapper subInjected2;221 @NoHook(@Hook(NanoHook.class))222 private WebElementWrapper subInjected2NoHook;223 }224 public static class SubContainer {225 private FluentWebElement subInjected;226 @NoHook227 private FluentWebElement subNoHookInjected;228 @Page229 private SubContainer2 subContainer2;230 @Page231 private SubContainer3 subContainer3;232 }233 @Hook(NanoHook.class)234 public static class FluentWebElementClassContainer {235 private FluentWebElement injected;236 @Page237 private SubContainer subContainer;238 }239 @Test240 public void testFluentWebElementClass() { // NOPMD ExcessiveMethodLength241 FluentWebElementClassContainer container = new FluentWebElementClassContainer();242 WebElement element = mock(WebElement.class);243 when(webDriver.findElement(new ByIdOrName("injected"))).thenReturn(element);244 WebElement subElement = mock(WebElement.class);245 when(webDriver.findElement(new ByIdOrName("subInjected"))).thenReturn(subElement);246 WebElement subNoHookElement = mock(WebElement.class);247 when(webDriver.findElement(new ByIdOrName("subNoHookInjected"))).thenReturn(subNoHookElement);248 WebElement subElement2 = mock(WebElement.class);249 when(webDriver.findElement(new ByIdOrName("subInjected2"))).thenReturn(subElement2);250 WebElement subElement2NoHook = mock(WebElement.class);251 when(webDriver.findElement(new ByIdOrName("subInjected2NoHook"))).thenReturn(subElement2NoHook);252 WebElement subElement3 = mock(WebElement.class);253 when(webDriver.findElement(new ByIdOrName("subInjected3"))).thenReturn(subElement3);254 WebElement subElementMethod = mock(WebElement.class);255 when(webDriver.findElements(By.cssSelector("#subInjectedMethod"))).thenReturn(singletonList(subElementMethod));256 injector.inject(container);257 assertThat(container.injected).isNotNull();258 container.injected.getElement().click();259 verify(element).click();260 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(container.injected.getElement());261 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);262 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);263 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);264 assertThat(elementWrapperHook.getOptionValue()).isEqualTo(null);265 assertThat(elementWrapperHook.getBeforeFindElementNano()).isNotEqualTo(0L);266 assertThat(elementWrapperHook.getAfterFindElementNano()).isNotEqualTo(0L);267 assertThat(elementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);268 assertThat(elementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);269 assertThat(container.subContainer.subInjected).isNotNull();270 container.subContainer.subInjected.getElement().click();271 verify(subElement).click();272 LocatorHandler subElementWrapperHandler = LocatorProxies273 .getLocatorHandler(container.subContainer.subInjected.getElement());274 NanoHook subElementWrapperHook = (NanoHook) subElementWrapperHandler.getInvocationTarget(null);275 assertThat(subElementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);276 assertThat(subElementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);277 assertThat(subElementWrapperHook.getOptionValue()).isEqualTo(null);278 assertThat(subElementWrapperHook.getBeforeFindElementNano()).isNotEqualTo(0L);279 assertThat(subElementWrapperHook.getAfterFindElementNano()).isNotEqualTo(0L);280 assertThat(subElementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);281 assertThat(subElementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);282 container.subContainer.subNoHookInjected.getElement().click();283 verify(subNoHookElement).click();284 LocatorHandler subNoHookElementWrapperHandler = LocatorProxies285 .getLocatorHandler(container.subContainer.subNoHookInjected.getElement());286 assertThat(subNoHookElementWrapperHandler.getInvocationTarget(null))287 .isSameAs(subNoHookElementWrapperHandler.getLocatorResult());288 container.subContainer.subContainer2.subInjected2.getElement().click();289 verify(subElement2).click();290 LocatorHandler subElement2WrapperHandler = LocatorProxies291 .getLocatorHandler(container.subContainer.subContainer2.subInjected2.getElement());292 assertThat(subElement2WrapperHandler.getInvocationTarget(null)).isExactlyInstanceOf(NanoHook2.class);293 NanoHook2 nanoHook2 = (NanoHook2) subElement2WrapperHandler.getInvocationTarget(null);294 assertThat(nanoHook2.getElement()).isExactlyInstanceOf(NanoHook.class);295 assertThat(((NanoHook) nanoHook2.getElement()).getElement()).isSameAs(subElement2);296 container.subContainer.subContainer2.subInjected2NoHook.getElement().click();297 verify(subElement2NoHook).click();298 LocatorHandler subElement2NoHookWrapperHandler = LocatorProxies299 .getLocatorHandler(container.subContainer.subContainer2.subInjected2NoHook.getElement());300 assertThat(subElement2NoHookWrapperHandler.getInvocationTarget(null)).isExactlyInstanceOf(NanoHook2.class);301 NanoHook2 nanoHook2NoHook = (NanoHook2) subElement2NoHookWrapperHandler.getInvocationTarget(null);302 assertThat(nanoHook2NoHook.getElement()).isSameAs(subElement2NoHook);303 container.subContainer.subContainer3.subInjected3.getElement().click();304 verify(subElement3).click();305 LocatorHandler subNoHook3ElementWrapperHandler = LocatorProxies306 .getLocatorHandler(container.subContainer.subContainer3.subInjected3.getElement());307 assertThat(subNoHook3ElementWrapperHandler.getInvocationTarget(null))308 .isSameAs(subNoHook3ElementWrapperHandler.getLocatorResult());309 WebElementWrapper subInjectedMethod = container.subContainer.subContainer2.find("#subInjectedMethod").first()310 .as(WebElementWrapper.class);311 LocatorProxies.now(subInjectedMethod.getElement());312 LocatorHandler subInjectedMethodHandler = LocatorProxies.getLocatorHandler(subInjectedMethod.getElement());313 assertThat(subInjectedMethodHandler.getInvocationTarget(null)).isExactlyInstanceOf(NanoHook2.class);314 WebElementWrapper subInjectedMethodNoHook = container.subContainer.subContainer2.find("#subInjectedMethod").first()315 .noHook().as(WebElementWrapper.class);316 LocatorProxies.now(subInjectedMethodNoHook.getElement());317 LocatorHandler subInjectedMethodNoHookHandler = LocatorProxies.getLocatorHandler(subInjectedMethodNoHook.getElement());318 assertThat(subInjectedMethodNoHookHandler.getInvocationTarget(null)).isSameAs(subElementMethod);319 WebElementWrapper subInjectedMethodNoHook2 = container.subContainer.subContainer2.find("#subInjectedMethod").noHook()320 .first().as(WebElementWrapper.class);321 LocatorProxies.now(subInjectedMethodNoHook2.getElement());322 LocatorHandler subInjectedMethodNoHook2Handler = LocatorProxies.getLocatorHandler(subInjectedMethodNoHook2.getElement());323 assertThat(subInjectedMethodNoHook2Handler.getInvocationTarget(null)).isSameAs(subElementMethod);324 }325 @NanoHookAnnotation("test")326 public static class FluentWebElementAnnotationContainer {327 protected FluentWebElement injected;328 @NoHook329 protected FluentWebElement injectedNoHook;330 }331 @Test332 public void testFluentWebElementAnnotationContainer() {333 FluentWebElementAnnotationContainer container = new FluentWebElementAnnotationContainer();334 WebElement element = mock(WebElement.class);335 when(webDriver.findElement(new ByIdOrName("injected"))).thenReturn(element);336 WebElement elementNoHook = mock(WebElement.class);337 when(webDriver.findElement(new ByIdOrName("injectedNoHook"))).thenReturn(elementNoHook);338 injector.inject(container);339 assertThat(container.injected).isNotNull();340 container.injected.getElement().click();341 verify(element).click();342 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(container.injected.getElement());343 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);344 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);345 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);346 assertThat(elementWrapperHook.getOptionValue()).isEqualTo("test");347 assertThat(elementWrapperHook.getBeforeFindElementNano()).isNotEqualTo(0L);348 assertThat(elementWrapperHook.getAfterFindElementNano()).isNotEqualTo(0L);349 assertThat(elementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);350 assertThat(elementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);351 assertThat(container.injectedNoHook).isNotNull();352 container.injectedNoHook.getElement().click();353 verify(elementNoHook).click();354 LocatorHandler elementNoHookHandler = LocatorProxies.getLocatorHandler(container.injectedNoHook.getElement());355 WebElement elementNoHookLocatorResult = (WebElement) elementNoHookHandler.getInvocationTarget(null);356 assertThat(elementNoHookLocatorResult).isSameAs(elementNoHook);357 }358 public static class FluentWebElementAnnotation {359 @NanoHookAnnotation("test")360 private FluentWebElement injected;361 }362 @Test363 public void testFluentWebElementAnnotation() {364 FluentWebElementAnnotation container = new FluentWebElementAnnotation();365 WebElement element = mock(WebElement.class);366 when(webDriver.findElement(new ByIdOrName("injected"))).thenReturn(element);367 injector.inject(container);368 assertThat(container.injected).isNotNull();369 container.injected.getElement().click();370 verify(element).click();371 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(container.injected.getElement());372 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);373 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);374 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);375 assertThat(elementWrapperHook.getOptionValue()).isEqualTo("test");376 assertThat(elementWrapperHook.getBeforeFindElementNano()).isNotEqualTo(0L);377 assertThat(elementWrapperHook.getAfterFindElementNano()).isNotEqualTo(0L);378 assertThat(elementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);379 assertThat(elementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);380 }381 public static class FluentWebElementExtendsContainer extends FluentWebElementAnnotationContainer {382 private FluentWebElement injected2;383 }384 @Test385 public void testFluentWebElementExtendsContainer() {386 FluentWebElementExtendsContainer container = new FluentWebElementExtendsContainer();387 WebElement element = mock(WebElement.class);388 when(webDriver.findElement(new ByIdOrName("injected"))).thenReturn(element);389 WebElement element2 = mock(WebElement.class);390 when(webDriver.findElement(new ByIdOrName("injected2"))).thenReturn(element2);391 WebElement elementNoHook = mock(WebElement.class);392 when(webDriver.findElement(new ByIdOrName("injectedNoHook"))).thenReturn(elementNoHook);393 injector.inject(container);394 assertThat(container.injected).isNotNull();395 container.injected.getElement().click();396 verify(element).click();397 LocatorHandler elementWrapperHandler = LocatorProxies.getLocatorHandler(container.injected.getElement());398 NanoHook elementWrapperHook = (NanoHook) elementWrapperHandler.getInvocationTarget(null);399 assertThat(elementWrapperHook.getBeforeClickNano()).isNotEqualTo(0L);400 assertThat(elementWrapperHook.getAfterClickNano()).isNotEqualTo(0L);401 assertThat(elementWrapperHook.getOptionValue()).isEqualTo("test");402 assertThat(elementWrapperHook.getBeforeFindElementNano()).isNotEqualTo(0L);403 assertThat(elementWrapperHook.getAfterFindElementNano()).isNotEqualTo(0L);404 assertThat(elementWrapperHook.getBeforeFindElementsNano()).isEqualTo(0L);405 assertThat(elementWrapperHook.getAfterFindElementsNano()).isEqualTo(0L);406 assertThat(container.injected2).isNotNull();407 container.injected2.getElement().click();408 verify(element2).click();409 LocatorHandler elementWrapperHandler2 = LocatorProxies.getLocatorHandler(container.injected2.getElement());410 NanoHook elementWrapperHook2 = (NanoHook) elementWrapperHandler2.getInvocationTarget(null);411 assertThat(elementWrapperHook2.getBeforeClickNano()).isNotEqualTo(0L);412 assertThat(elementWrapperHook2.getAfterClickNano()).isNotEqualTo(0L);413 assertThat(elementWrapperHook2.getOptionValue()).isEqualTo("test");414 assertThat(elementWrapperHook2.getBeforeFindElementNano()).isNotEqualTo(0L);415 assertThat(elementWrapperHook2.getAfterFindElementNano()).isNotEqualTo(0L);416 assertThat(elementWrapperHook2.getBeforeFindElementsNano()).isEqualTo(0L);417 assertThat(elementWrapperHook2.getAfterFindElementsNano()).isEqualTo(0L);418 assertThat(container.injectedNoHook).isNotNull();419 container.injectedNoHook.getElement().click();420 verify(elementNoHook).click();421 LocatorHandler elementNoHookHandler = LocatorProxies.getLocatorHandler(container.injectedNoHook.getElement());422 WebElement elementNoHookLocatorResult = (WebElement) elementNoHookHandler.getInvocationTarget(null);423 assertThat(elementNoHookLocatorResult).isSameAs(elementNoHook);424 }425}...

Full Screen

Full Screen

Source:SearchHookTest.java Github

copy

Full Screen

...38 when(element.isEnabled()).thenReturn(true);39 }40 @Test41 public void testHookedSearch() {42 FluentWebElement hookedElement = search.el(".selector").withHook(NanoHook.class).click();43 Mockito.verify(element).click();44 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());45 NanoHook hookElement = (NanoHook) componentHandler.getInvocationTarget(null);46 Assertions.assertThat(hookElement.getBeforeClickNano()).isNotEqualTo(0L);47 Assertions.assertThat(hookElement.getAfterClickNano()).isNotEqualTo(0L);48 }49 @Test50 public void testHookSearchFirstAfter() {51 FluentWebElement hookedElement = search.$(".selector").withHook(NanoHook.class).first().click();52 Mockito.verify(element).click();53 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());54 NanoHook hookElement = (NanoHook) componentHandler.getInvocationTarget(null);55 Assertions.assertThat(hookElement.getBeforeClickNano()).isNotEqualTo(0L);56 Assertions.assertThat(hookElement.getAfterClickNano()).isNotEqualTo(0L);57 }58 @Test59 public void testHookSearchFirstBefore() {60 FluentWebElement hookedElement = search.$(".selector").first().withHook(NanoHook.class).click();61 Mockito.verify(element).click();62 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());63 NanoHook hookElement = (NanoHook) componentHandler.getInvocationTarget(null);64 Assertions.assertThat(hookElement.getBeforeClickNano()).isNotEqualTo(0L);65 Assertions.assertThat(hookElement.getAfterClickNano()).isNotEqualTo(0L);66 }67 @Test68 public void testHookSearchNoHook() {69 FluentWebElement hookedElement = search.$(".selector").first().withHook(NanoHook.class).noHook().click();70 Mockito.verify(element).click();71 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());72 WebElement hookElement = componentHandler.getInvocationTarget(null);73 Assertions.assertThat(hookElement).isNotInstanceOf(NanoHook.class);74 }75 @Test76 public void testHookSearchNoHookClickAndRestore() {77 FluentWebElement hookedElement = search.$(".selector").first().withHook(NanoHook.class).noHook().click().restoreHooks();78 Mockito.verify(element).click();79 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());80 NanoHook hookElement = (NanoHook) componentHandler.getInvocationTarget(null);81 Assertions.assertThat(hookElement.getBeforeClickNano()).isEqualTo(0L);82 Assertions.assertThat(hookElement.getAfterClickNano()).isEqualTo(0L);83 }84 @Test85 public void testHookSearchHookBeforeFirstNoHookClickAndRestore() {86 FluentWebElement hookedElement = search.$(".selector").withHook(NanoHook.class).first().noHook().click().restoreHooks();87 Mockito.verify(element).click();88 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());89 NanoHook hookElement = (NanoHook) componentHandler.getInvocationTarget(null);90 Assertions.assertThat(hookElement.getBeforeClickNano()).isEqualTo(0L);91 Assertions.assertThat(hookElement.getAfterClickNano()).isEqualTo(0L);92 }93 @Test94 public void testHookSearchNoHookFunction() {95 FluentWebElement hookedElement = search.$(".selector").withHook(NanoHook.class).first()96 .noHook(FluentWebElement::click);97 Mockito.verify(element).click();98 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());99 NanoHook hookElement = (NanoHook) componentHandler.getInvocationTarget(null);100 Assertions.assertThat(hookElement.getBeforeClickNano()).isEqualTo(0L);101 Assertions.assertThat(hookElement.getAfterClickNano()).isEqualTo(0L);102 }103 @Test104 public void testHookSearchFirstNoHookFunction() {105 FluentWebElement hookedElement = search.$(".selector").first().withHook(NanoHook.class)106 .noHook(FluentWebElement::click);107 Mockito.verify(element).click();108 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());109 NanoHook hookElement = (NanoHook) componentHandler.getInvocationTarget(null);110 Assertions.assertThat(hookElement.getBeforeClickNano()).isEqualTo(0L);111 Assertions.assertThat(hookElement.getAfterClickNano()).isEqualTo(0L);112 }113 @Test114 public void testHookSearchNoHookClone() {115 FluentWebElement hookedElement = search.$(".selector").withHook(NanoHook.class).first().noHookInstance().click();116 Mockito.verify(element).click();117 LocatorHandler<WebElement> componentHandler = LocatorProxies.getLocatorHandler(hookedElement.getElement());118 WebElement hookElement = componentHandler.getInvocationTarget(null);119 Assertions.assertThat(hookElement).isNotInstanceOf(NanoHook.class);120 }121 @Test122 public void testHookSearchListNoHookClone() {123 FluentList<FluentWebElement> hookedElement = search.$(".selector").withHook(NanoHook.class).noHookInstance().click();124 Mockito.verify(element).click();125 LocatorHandler<List<WebElement>> componentHandler = LocatorProxies.getLocatorHandler(hookedElement);126 List<WebElement> hookElement = componentHandler.getInvocationTarget(null);127 Assertions.assertThat(hookElement).isNotInstanceOf(NanoHook.class);128 }129}...

Full Screen

Full Screen

Source:DefaultHookChainBuilderTest.java Github

copy

Full Screen

...57 Assertions.assertThat(fluentHooks).hasSize(hookDefinitions.size());58 Assertions.assertThat(fluentHooks.get(0)).isInstanceOf(NanoHook.class);59 Assertions.assertThat(fluentHooks.get(1)).isInstanceOf(NanoHook.class);60 Assertions.assertThat(fluentHooks.get(2)).isInstanceOf(NanoHook.class);61 fluentHooks.get(0).click();62 verify(element).click();63 verify(fluentHooks.get(0)).click();64 verify(fluentHooks.get(1), never()).click();65 verify(fluentHooks.get(2), never()).click();66 reset(element);67 reset(fluentHooks.toArray());68 fluentHooks.get(2).click();69 verify(element).click();70 verify(fluentHooks.get(0)).click();71 verify(fluentHooks.get(1)).click();72 verify(fluentHooks.get(2)).click();73 Assertions.assertThat(((NanoHook) fluentHooks.get(2)).getBeforeClickNano())74 .isLessThanOrEqualTo(((NanoHook) fluentHooks.get(1)).getBeforeClickNano());75 Assertions.assertThat(((NanoHook) fluentHooks.get(1)).getBeforeClickNano())76 .isLessThanOrEqualTo(((NanoHook) fluentHooks.get(0)).getBeforeClickNano());77 Assertions.assertThat(((NanoHook) fluentHooks.get(2)).getAfterClickNano())78 .isGreaterThanOrEqualTo(((NanoHook) fluentHooks.get(1)).getAfterClickNano());79 Assertions.assertThat(((NanoHook) fluentHooks.get(1)).getAfterClickNano())80 .isGreaterThanOrEqualTo(((NanoHook) fluentHooks.get(0)).getAfterClickNano());81 Assertions.assertThat(((NanoHook) fluentHooks.get(0)).getOptionValue()).isNull();82 Assertions.assertThat(((NanoHook) fluentHooks.get(1)).getOptionValue()).isEqualTo("option");83 Assertions.assertThat(((NanoHook) fluentHooks.get(2)).getOptionValue()).isNull();84 }85 private static class InvalidConstructorHook extends BaseHook<Object> {86 InvalidConstructorHook() {...

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.core.hook;2import org.fluentlenium.core.FluentControl;3import org.fluentlenium.core.FluentPage;4import org.fluentlenium.core.domain.FluentWebElement;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7public class NanoHook extends FluentPage {8 private FluentControl fluentControl;9 public NanoHook(WebDriver driver) {10 super(driver);11 }12 public NanoHook(FluentControl fluentControl) {13 super(fluentControl);14 this.fluentControl = fluentControl;15 }16 public void click(FluentWebElement element) {17 element.click();18 }19 public void click(WebElement element) {20 element.click();21 }22 public void click(String cssSelector) {23 click(findFirst(cssSelector));24 }25 public void click(int index, String cssSelector) {26 click(find(cssSelector).get(index));27 }28 public void click(int index) {29 click(findFirst().get(index));30 }31 public String getUrl() {32 return null;33 }34 public void isAt() {35 }36}37package org.fluentlenium.core.hook;38import org.fluentlenium.core.FluentControl;39import org.fluentlenium.core.FluentPage;40import org.fluentlenium.core.domain.FluentWebElement;41import org.openqa.selenium.WebDriver;42import org.openqa.selenium.WebElement;43public class NanoHook extends FluentPage {44 private FluentControl fluentControl;45 public NanoHook(WebDriver driver) {46 super(driver);47 }48 public NanoHook(FluentControl fluentControl) {49 super(fluentControl);50 this.fluentControl = fluentControl;51 }52 public void click(FluentWebElement element) {53 element.click();54 }55 public void click(WebElement element) {56 element.click();57 }58 public void click(String cssSelector) {59 click(findFirst(cssSelector));60 }61 public void click(int index, String cssSelector) {62 click(find(cssSelector).get(index));63 }64 public void click(int index) {65 click(findFirst().get(index));66 }67 public String getUrl() {68 return null;69 }70 public void isAt() {71 }72}

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1package com.automationrhapsody.fluentlenium;2import org.fluentlenium.adapter.junit.FluentTest;3import org.fluentlenium.core.hook.NanoHook;4import org.junit.Test;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.htmlunit.HtmlUnitDriver;7public class ClickTest extends FluentTest {8 public WebDriver newWebDriver() {9 return new HtmlUnitDriver();10 }11 public void testClick() {12 NanoHook.click(findFirst("#menu-item-180"));13 }14}15package com.automationrhapsody.fluentlenium;16import org.fluentlenium.adapter.junit.FluentTest;17import org.fluentlenium.core.hook.NanoHook;18import org.junit.Test;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.htmlunit.HtmlUnitDriver;21public class ClickTest extends FluentTest {22 public WebDriver newWebDriver() {23 return new HtmlUnitDriver();24 }25 public void testClick() {26 NanoHook.click(findFirst("#menu-item-180"));27 }28}29package com.automationrhapsody.fluentlenium;30import org.fluentlenium.adapter.junit.FluentTest;31import org.fluentlenium.core.hook.NanoHook;32import org.junit.Test;33import org.openqa.selenium.WebDriver;34import org.openqa.selenium.htmlunit.HtmlUnitDriver;35public class ClickTest extends FluentTest {36 public WebDriver newWebDriver() {37 return new HtmlUnitDriver();38 }39 public void testClick() {40 NanoHook.click(findFirst("#menu-item-180"));41 }42}43package com.automationrhapsody.fluentlenium;44import org.fluentlenium.adapter.junit.FluentTest;45import org.fluentlenium.core.hook.NanoHook;46import org.junit.Test;47import org.openqa.selenium.WebDriver;

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1public class 4 extends FluentTest {2 public WebDriver newWebDriver() {3 return new ChromeDriver();4 }5 public String getWebDriver() {6 return "chrome";7 }8 public void test() {9 $("#lst-ib").fill().with("selenium");10 $("#lst-ib").click();11 }12}13public class 5 extends FluentTest {14 public WebDriver newWebDriver() {15 return new ChromeDriver();16 }17 public String getWebDriver() {18 return "chrome";19 }20 public void test() {21 $("#lst-ib").fill().with("selenium");22 $("#lst-ib").click();23 }24}25public class 6 extends FluentTest {26 public WebDriver newWebDriver() {27 return new ChromeDriver();28 }29 public String getWebDriver() {30 return "chrome";31 }32 public void test() {33 $("#lst-ib").fill().with("selenium");34 $("#lst-ib").click();35 }36}37public class 7 extends FluentTest {38 public WebDriver newWebDriver() {39 return new ChromeDriver();40 }41 public String getWebDriver() {42 return "chrome";43 }44 public void test() {45 $("#lst-ib").fill().with("selenium");46 $("#lst-ib").click();47 }48}49public class 8 extends FluentTest {50 public WebDriver newWebDriver() {51 return new ChromeDriver();52 }53 public String getWebDriver() {

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1package com.fluentlenium;2import org.fluentlenium.core.FluentPage;3import org.fluentlenium.core.hook.NanoHook;4import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7public class NanoHookTest extends FluentPage {8 public String getUrl() {9 }10 public void clickOnElement() {11 WebElement element = getDriver().findElement(By.name("btnK"));12 NanoHook.click(element);13 }14 public void clickOnElementWithNanoHook() {15 NanoHook.click(find(By.name("btnK")));16 }17 public void clickOnElementWithFluentLenium() {18 click(find(By.name("btnK")));19 }20 public static void main(String[] args) {21 NanoHookTest test = new NanoHookTest();22 WebDriver driver = test.getDriver();23 driver.get(test.getUrl());24 test.clickOnElement();25 driver.get(test.getUrl());26 test.clickOnElementWithNanoHook();27 driver.get(test.getUrl());28 test.clickOnElementWithFluentLenium();29 }30}31package com.fluentlenium;32import org.fluentlenium.core.FluentPage;33import org.fluentlenium.core.hook.NanoHook;34import org.openqa.selenium.By;35import org.openqa.selenium.WebDriver;36import org.openqa.selenium.WebElement;37public class NanoHookTest extends FluentPage {38 public String getUrl() {39 }40 public void clickOnElement() {41 WebElement element = getDriver().findElement(By.name("btnK"));42 NanoHook.click(element);43 }44 public void clickOnElementWithNanoHook() {45 NanoHook.click(find(By.name("btnK")));46 }47 public void clickOnElementWithFluentLenium() {48 click(find(By.name("btnK")));49 }50 public static void main(String[] args) {51 NanoHookTest test = new NanoHookTest();52 WebDriver driver = test.getDriver();

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.core.hook; 2import org.fluentlenium.core.hook.NanoHook;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.chrome.ChromeOptions;8import java.util.List;9import java.util.concurrent.TimeUnit;10public class NanoHookClick {11 public static void main(String[] args) throws Exception {12 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lenovo\\Downloads\\chromedriver_win32\\chromedriver.exe");13 WebDriver driver = new ChromeDriver();14 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);15 NanoHook hook = new NanoHook(driver);16 WebElement element = elements.get(0);17 hook.click(element);18 driver.quit();19 }20}

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 FluentDriver driver = new FluentDriver();4 driver.$("input[name='q']").fill().with("FluentLenium");5 driver.$("input[name='btnK']").click();6 driver.quit();7 }8}9public class 5 {10 public static void main(String[] args) {11 FluentDriver driver = new FluentDriver();12 driver.$("input[name='q']").fill().with("FluentLenium");13 driver.$("input[name='btnK']").click();14 driver.quit();15 }16}17public class 6 {18 public static void main(String[] args) {19 FluentDriver driver = new FluentDriver();20 driver.$("input[name='q']").fill().with("FluentLenium");21 driver.$("input[name='btnK']").click();22 driver.quit();23 }24}25public class 7 {26 public static void main(String[] args) {27 FluentDriver driver = new FluentDriver();28 driver.$("input[name='q']").fill().with("FluentLenium");29 driver.$("input[name='btnK']").click();30 driver.quit();31 }32}33public class 8 {34 public static void main(String[] args) {35 FluentDriver driver = new FluentDriver();36 driver.$("input[name='q']").fill().with("FluentLenium");37 driver.$("input[name='btnK']").click();38 driver.quit();39 }40}

Full Screen

Full Screen

click

Using AI Code Generation

copy

Full Screen

1package com.example;2import org.fluentlenium.adapter.junit.FluentTest;3import org.fluentlenium.core.hook.NanoHook;4import org.junit.Test;5import org.junit.runner.RunWith;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.htmlunit.HtmlUnitDriver;8import org.springframework.boot.test.SpringApplicationConfiguration;9import org.springframework.boot.test.WebIntegrationTest;10import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;11@RunWith(SpringJUnit4ClassRunner.class)12@SpringApplicationConfiguration(classes = DemoApplication.class)13public class DemoApplicationTests extends FluentTest {14 public WebDriver getDefaultDriver() {15 return new HtmlUnitDriver();16 }17 public void testClick() {18 $("button").click();19 NanoHook hook = new NanoHook(this);20 hook.click("button");21 fluentWait(1000);22 assertThat(pageSource()).contains("Hello World");23 assertThat(title()).isEqualTo("Hello World");24 }25}26package com.example;27import org.fluentlenium.adapter.junit.FluentTest;28import org.fluentlenium.core.hook.NanoHook;29import org.junit.Test;30import org.junit.runner.RunWith;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.htmlunit.HtmlUnitDriver;33import org.springframework.boot.test.SpringApplicationConfiguration;34import org.springframework.boot.test.WebIntegrationTest;35import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;36@RunWith(SpringJUnit4ClassRunner.class)37@SpringApplicationConfiguration(classes = DemoApplication.class)38public class DemoApplicationTests extends FluentTest {39 public WebDriver getDefaultDriver() {40 return new HtmlUnitDriver();41 }42 public void testClick() {43 $("button").click();44 NanoHook hook = new NanoHook(this);

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