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

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

Source:FluentInjectorHookTest.java Github

copy

Full Screen

...8import org.fluentlenium.core.domain.FluentList;9import org.fluentlenium.core.domain.FluentWebElement;10import org.fluentlenium.core.hook.Hook;11import org.fluentlenium.core.hook.HookOptions;12import org.fluentlenium.core.hook.NanoHook;13import org.fluentlenium.core.hook.NanoHookAnnotation;14import org.fluentlenium.core.hook.NanoHookOptions;15import org.fluentlenium.core.hook.NoHook;16import org.fluentlenium.core.proxy.LocatorHandler;17import org.fluentlenium.core.proxy.LocatorProxies;18import org.junit.After;19import org.junit.Before;20import org.junit.Test;21import org.junit.runner.RunWith;22import org.mockito.Mock;23import org.mockito.junit.MockitoJUnitRunner;24import org.openqa.selenium.By;25import org.openqa.selenium.WebDriver;26import org.openqa.selenium.WebElement;27import org.openqa.selenium.support.ByIdOrName;28import org.openqa.selenium.support.pagefactory.ElementLocator;29import java.util.Arrays;30import java.util.List;31import java.util.function.Supplier;32import static java.util.Collections.singletonList;33import static org.assertj.core.api.Assertions.assertThat;34import static org.mockito.Mockito.mock;35import static org.mockito.Mockito.reset;36import static org.mockito.Mockito.verify;37import static org.mockito.Mockito.when;38@RunWith(MockitoJUnitRunner.class)39public class FluentInjectorHookTest {40 @Mock41 private WebDriver webDriver;42 private FluentAdapter fluentAdapter;43 private FluentInjector injector;44 @Before45 public void before() {46 fluentAdapter = new FluentAdapter();47 fluentAdapter.initFluent(webDriver);48 injector = new FluentInjector(fluentAdapter, null, new ComponentsManager(fluentAdapter),49 new DefaultContainerInstantiator(fluentAdapter));50 }51 @After52 public void after() {53 reset(webDriver);54 }55 public static class FluentWebElementContainer {56 @Hook(NanoHook.class)57 private FluentWebElement injected;58 }59 @Test60 public void testFluentWebElement() {61 FluentWebElementContainer container = new FluentWebElementContainer();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 }...

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

...49 }50 @Test51 public void testBuildHook() {52 List<HookDefinition<?>> hookDefinitions = new ArrayList<>();53 hookDefinitions.add(new HookDefinition<>(NanoHook.class));54 hookDefinitions.add(new HookDefinition<>(NanoHook.class, new NanoHookOptions("option")));55 hookDefinitions.add(new HookDefinition<>(NanoHook.class));56 List<FluentHook> fluentHooks = hookChainBuilder.build(() -> element, () -> locator, () -> "toString", hookDefinitions);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() {87 super(null, null, null, null, null, null);88 }89 }90 @Test91 public void testInvalidConstructorHook() {92 List<HookDefinition<?>> hookDefinitions = new ArrayList<>();93 hookDefinitions.add(new HookDefinition<>(InvalidConstructorHook.class));94 Assertions95 .assertThatThrownBy(() -> hookChainBuilder.build(() -> element, () -> locator, () -> "toString", hookDefinitions))96 .isExactlyInstanceOf(HookException.class).hasMessage("An error has occurred with a defined hook.");97 }...

Full Screen

Full Screen

NanoHook

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.adapter.junit.FluentTest;2import org.fluentlenium.core.hook.NanoHook;3import org.junit.Test;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.htmlunit.HtmlUnitDriver;6public class NanoHookTest extends FluentTest {7 public void testNanoHook() {8 NanoHook hook = new NanoHook();9 hook.setClassName("gsfi");10 hook.setMethod("sendKeys");11 hook.setArgs("Fluentlenium");12 hook.execute(getDriver());13 hook.setMethod("submit");14 hook.execute(getDriver());15 }16 public WebDriver getDefaultDriver() {17 return new HtmlUnitDriver();18 }19}20NanoHookTest > testNanoHook() PASSED21public class NanoHook {22 private String className;23 private String method;24 private Object[] args;25 public void execute(WebDriver driver) {26 try {27 Class<?> clazz = Class.forName(className);28 Object object = clazz.cast(driver);29 Method method = clazz.getMethod(this.method, getClasses(args));30 method.invoke(object, args);31 } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {32 e.printStackTrace();33 }34 }35 public void setClassName(String className) {36 this.className = className;37 }38 public void setMethod(String method) {39 this.method = method;40 }41 public void setArgs(Object... args) {42 this.args = args;43 }44 private Class<?>[] getClasses(Object[] args) {45 Class<?>[] classes = new Class[args.length];46 for (int i = 0; i < args.length; i++) {47 classes[i] = args[i].getClass();48 }49 return classes;50 }51}

Full Screen

Full Screen

NanoHook

Using AI Code Generation

copy

Full Screen

1public class 4 extends FluentTest {2 public WebDriver newWebDriver() {3 return new FirefoxDriver();4 }5 public void test() {6 $("a").first().click();7 $("a").get(1).click();8 $("a").get(2).click();9 $("a").get(3).click();10 $("a").get(4).click();11 }12}

Full Screen

Full Screen

NanoHook

Using AI Code Generation

copy

Full Screen

1package com.mycompany.app;2import org.fluentlenium.core.hook.NanoHook;3import org.fluentlenium.core.hook.HookOptions;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.chrome.ChromeDriver;9import org.openqa.selenium.chrome.ChromeOptions;10import org.openqa.selenium.remote.DesiredCapabilities;11import org.openqa.selenium.remote.RemoteWebDriver;12import org.openqa.selenium.support.ui.ExpectedConditions;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.openqa.selenium.support.ui.FluentWait;15import org.openqa.selenium.support.ui.Wait;16import org.openqa.selenium.support.ui.Select;17import org.openqa.selenium.JavascriptExecutor;18import org.openqa.selenium.Keys;19import org.openqa.selenium.interactions.Actions;20import org.openqa.selenium.NoSuchElementException;21import org.openqa.selenium.StaleElementReferenceException;22import org.openqa.selenium.OutputType;23import org.openqa.selenium.TakesScreenshot;24import java.io.File;25import java.util.concurrent.TimeUnit;26import java.util.function.Function;27import java.util.concurrent.TimeUnit;28import java.util.List;29import java.util.ArrayList;30import java.util.Map;31import java.util.HashMap;32import java.util.Set;33import java.util.HashSet;34import java.util.Arrays;35import java.util.Iterator;36import java.util.Calendar;37import java.util.Date;38import java.util.Random;39import java.util.TimeZone;40import java.text.SimpleDateFormat;41import java.text.DateFormat;42import java.io.*;43import java.io.IOException;44import java.io.InputStream;45import java.io.OutputStream;46import java.io.FileInputStream;47import java.io.FileOutputStream;48import java.io.FileNotFoundException;49import java.io.FileReader;50import java.io.BufferedReader;51import java.io.BufferedWriter;52import java.io.FileWriter;53import java.io.InputStreamReader;54import java.io.PrintWriter;55import java.io.RandomAccessFile;56import java.net.HttpURLConnection;57import java.net.URL;58import java.net.URLConnection;59import java.net.InetAddress;60import java.net.UnknownHostException;61import java.net.MalformedURLException;62import java.net.URLDecoder;63import java.net.URLEncoder;64import java.net.Proxy;65import java.net.InetSocketAddress;66import java.net.Authenticator;67import java.net.PasswordAuthentication;68import java.net.SocketAddress;69import java.net.Socket;70import java.net.ServerSocket;71import java.lang.reflect.Method;72import java.lang.reflect.Field;73import java.lang.reflect.InvocationTargetException;74import java.lang.reflect.Type;75import java.lang.reflect.Constructor;76import java.lang.reflect.Array;77import java.lang.reflect.Proxy;78import java.lang.reflect.InvocationHandler;79import java.lang

Full Screen

Full Screen

NanoHook

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.adapter.junit.FluentTest;2import org.fluentlenium.core.hook.NanoHook;3import org.junit.Test;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6public class NanoHookTest extends FluentTest {7 public WebDriver newWebDriver() {8 System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");9 return new ChromeDriver();10 }11 public void nanoHookTest() {12 NanoHook hook = new NanoHook();13 hook.setDriver(getDriver());14 hook.find("input[name='q']");15 }16}17import org.fluentlenium.adapter.junit.FluentTest;18import org.fluentlenium.core.hook.NanoHook;19import org.junit.Test;20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.chrome.ChromeDriver;22public class NanoHookTest extends FluentTest {23 public WebDriver newWebDriver() {24 System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");25 return new ChromeDriver();26 }27 public void nanoHookTest() {28 NanoHook hook = new NanoHook();29 hook.setDriver(getDriver());30 hook.find("input[name='q']").text("FluentLenium");31 }32}33import org.fluentlenium.adapter.junit.FluentTest;34import org.fluentlenium.core.hook.NanoHook;35import org.junit.Test;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.chrome.ChromeDriver;38public class NanoHookTest extends FluentTest {39 public WebDriver newWebDriver() {40 System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");41 return new ChromeDriver();42 }43 public void nanoHookTest() {44 NanoHook hook = new NanoHook();45 hook.setDriver(getDriver());46 hook.find("input[name='

Full Screen

Full Screen

NanoHook

Using AI Code Generation

copy

Full Screen

1public class 4 extends FluentTest {2 public WebDriver newWebDriver() {3 return new HtmlUnitDriver();4 }5 public void checkNanoHook() {6 $("input[name='q']").fill().with("FluentLenium");7 $("input[name='q']").submit();8 await().atMost(10, TimeUnit.SECONDS).until($("h3.r")).hasSize(10);9 $("h3.r").first().click();10 await().atMost(10, TimeUnit.SECONDS).untilPage().isLoaded();11 assertThat(window().title()).contains("FluentLenium");12 }13}14public class 5 extends FluentTest {15 public WebDriver newWebDriver() {16 return new HtmlUnitDriver();17 }18 public void checkFluentWait() {19 $("input[name='q']").fill().with("FluentLenium");20 $("input[name='q']").submit();21 await().atMost(10, TimeUnit.SECONDS).until($("h3.r")).hasSize(10);22 $("h3.r").first().click();23 await().atMost(10, TimeUnit.SECONDS).untilPage().isLoaded();24 assertThat(window().title()).contains("FluentLenium");25 }26}27public class 6 extends FluentTest {28 public WebDriver newWebDriver() {29 return new HtmlUnitDriver();30 }31 public void checkFluentControl() {32 $("input[name='q']").fill().with("FluentLenium");33 $("input[name='q']").submit();34 await().atMost(10, TimeUnit.SECONDS).until($("h3.r")).hasSize(10);35 $("h3.r").first().click();36 await().atMost(10, TimeUnit.SECONDS).untilPage().isLoaded();37 assertThat(window().title()).contains("FluentLenium");38 }39}

Full Screen

Full Screen

NanoHook

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.core.hook;2import java.lang.reflect.Method;3import java.util.Map;4import java.util.concurrent.ConcurrentHashMap;5import javassist.util.proxy.MethodHandler;6import javassist.util.proxy.Proxy;7import javassist.util.proxy.ProxyFactory;8import org.fluentlenium.core.FluentControl;9import org.fluentlenium.core.FluentPage;10import org.fluentlenium.core.action.ActionControl;11import org.fluentlenium.core.action.FillControl;12import org.fluentlenium.core.action.InputControl;13import org.fluentlenium.core.action.KeyboardControl;14import org.fluentlenium.core.action.MouseControl;15import org.fluentlenium.core.action.ScrollControl;16import org.fluentlenium.core.action.WindowControl;17import org.fluentlenium.core.components.Components;18import org.fluentlenium.core.components.DefaultComponentsInstantiator;19import org.fluentlenium.core.components.DefaultComponentsManager;20import org.fluentlenium.core.components.DefaultComponentsRegistry;21import org.fluentlenium.core.components.DefaultComponentsScanner;22import org.fluentlenium.core.components.ComponentsManager;23import org.fluentlenium.core.components.ComponentsRegistry;24import org.fluentlenium.core.components.ComponentsScanner;25import org.fluentlenium.core.domain.FluentWebElement;26import org.fluentlenium.core.events.Events;27import org.fluentlenium.core.events.EventFiringControl;28import org.fluentlenium.core.events.EventFiringHook;29import org.fluentlenium.core.inject.DefaultContainer;30import org.fluentlenium.core.inject.DefaultContainerContext;31import org.fluentlenium.core.inject.DefaultContainerFactory;32import org.fluentlenium.core.inject.DefaultContainerInstantiator;33import org.fluentlenium.core.inject.DefaultContainerRegistry;34import org.fluentlenium.core.inject.DefaultContainerScanner;35import org.fluentlenium.core.inject.Container;36import org.fluentlenium.core.inject.ContainerContext;37import org.fluentlenium.core.inject.ContainerFactory;38import org.fluentlenium.core.inject.ContainerInstantiator;39import org.fluentlenium.core.inject.ContainerRegistry;40import org.fluentlenium.core.inject.ContainerScanner;41import org.fluentlenium.core.script.DefaultScript;42import org.fluentlenium.core.script.Script;43import org.fluentlenium.core.wait.FluentWait;44import org.fluentlenium.core.wait.WaitControl;45import org.fluentlenium.core

Full Screen

Full Screen

NanoHook

Using AI Code Generation

copy

Full Screen

1package com.mycompany.app;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.chrome.ChromeDriver;7public class 4 extends FluentTest {8 public WebDriver newWebDriver() {9 return new ChromeDriver();10 }11 public void test() {12 NanoHook.hook(this).takeScreenShot();13 }14}15package com.mycompany.app;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.chrome.ChromeDriver;21public class 5 extends FluentTest {22 public WebDriver newWebDriver() {23 return new ChromeDriver();24 }25 public void test() {26 NanoHook.hook(this).takeScreenShot();27 }28}

Full Screen

Full Screen

NanoHook

Using AI Code Generation

copy

Full Screen

1package com.mycompany.app;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.chrome.ChromeDriver;7public class 4 extends FluentTest {8 public WebDriver newWebDriver() {9 return new ChromeDriver();10 }11 public void test() {12 NanoHook.hook(this).takeScreenShot();13 }14}15package com.mycompany.app;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.chrome.ChromeDriver;21public class 5 extends FluentTest {22 public WebDriver newWebDriver() {23 return new ChromeDriver();24 }25 public void test() {26 NanoHook.hook(this).takeScreenShot();27 }28}

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