--
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 geb-user+u...@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/f3d8efea-b285-47d0-90c4-0ba459332dc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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.groovyimport geb.Browser
import geb.navigator.EmptyNavigator
class EmptyCustomNavigator extends EmptyNavigator {
EmptyCustomNavigator(Browser browser) {
super(browser)
}
}___________________________
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 <adiga...@gmail.com> 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 geb-...@googlegroups.com.
class LoginPage extends BasePage {
static at = { username.displayed }
static content = { username(wait:true) { $("#username input", 0) } password(wait: true) { $("#password input")} signIn(wait:true) { $("#confirmButton button") } }} @Override
Navigator click() {
ensureContainsSingleElement("click")
contextElements.first().click()
log.info("[" + <<NAVIGATOR NAME>> + "] Click element")
this
}
--
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 geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/8942a582-07f4-471f-94d7-44673ab4572c%40googlegroups.com.