Thank you Marcin. I'm able to override the method following your 
instruction :)

Below is the snippet which did the trick for me.

GebConfig.groovy
innerNavigatorFactory = { Browser browser, List<WebElement> elements ->
 elements ? new NonEmptyCustomNavigator(browser, elements) : new 
EmptyCustomNavigator()
}



NonEmptyCustomNavigator.groovy

import geb.Browser
import geb.navigator.Navigator
import geb.navigator.NonEmptyNavigator
import groovy.util.logging.Log4j
import org.openqa.selenium.WebElement

@Log4j
class NonEmptyCustomNavigator extends NonEmptyNavigator{

 NonEmptyCustomNavigator(Browser browser, Collection<? extends WebElement> 
contextElements) {
 super(browser, contextElements)
 }

 @Override
 Navigator click() {
 ensureContainsSingleElement("click")
 contextElements.first().click()
 log.info("[" + contextElements.first().toString() + "] Click element")
 this
 }
}

EmptyCustomNavigator.groovy

import geb.Browser
import geb.navigator.EmptyNavigator

class EmptyCustomNavigator extends EmptyNavigator {

 EmptyCustomNavigator(Browser browser) {
 super(browser)
 }
}


___________________________


On Monday, 15 April 2019 00:14:59 UTC+5:30, Marcin Erdmann wrote:
>
> Yes, InnerNavigatorFactory has been conceived to allow users to provide 
> their own implementation of Navigator. Your use case of adding some logging 
> to certain methods defined on Navigator is exactly what this mechanism is 
> for.
>
> Simply extend NonEmptyNavigator and EmptyNavigator with what's needed, and 
> then copy the snippet from the manual section you mentioned in your email (
> http://gebish.org/manual/current/#navigator-factory) into the config file 
> (http://gebish.org/manual/current/#the-config-script) replacing 
> MyCustomNavigator and MyCustomEmptyNavigator with the names of your custom 
> Navigator implementation classes.
>
> On Fri, Apr 12, 2019 at 4:26 PM Jeevan Adiga <[email protected] 
> <javascript:>> wrote:
>
>> Hello,
>>
>> I'm trying to override few methods like click() and leftShift()/value() 
>> to log the action using any logging lib like log4j / slf4j.
>>
>> Can NavigatorFactory(http://gebish.org/manual/current/#navigator-factory) 
>> be used to extend/override methods in EmptyNavigator and NonEmptyNavigator 
>> class?
>>
>> If yes, can you please provide pointer/steps/code snippet that needs to 
>> be done to achieve this.
>>
>> If not possible, please suggest any other way of achieving this.
>>
>> Thank you.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Geb User Mailing List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/geb-user/f3d8efea-b285-47d0-90c4-0ba459332dc5%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/geb-user/f3d8efea-b285-47d0-90c4-0ba459332dc5%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Geb 
User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/geb-user/3dc884ce-9f27-4693-80bf-9f8dc11d0993%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to