Geb Binding

9 views
Skip to first unread message

Varun Jain

unread,
Jan 9, 2020, 4:48:02 PM1/9/20
to Geb User Mailing List
My automation tests use Cucumber and Geb. I am trying to create a browser object at the beginning of my test execution in the cucumber before hooks. To share the browser object, I am trying to use Geb biding but when I create a class variable bindingUpdater and then trying to use it then I am getting error.  Can someone help me and explain what is going on. Should I only be using the env.groovy file to use binding?
Following is the code which I am trying in my machine ( copied the code from Marcin's repo https://github.com/geb/geb-example-gradle/tree/master/src/test)

package hooks

import geb.Browser
import geb.binding.BindingUpdater
import io.cucumber.java.After
import io.cucumber.java.AfterStep
import io.cucumber.java.Before
import io.cucumber.java.BeforeStep

class Hooks {

BindingUpdater bindingUpdater
Browser theBrowser

@Before
public void createBrowser() {
if (!bindingUpdater.binding.hasVariable('browser')) {
theBrowser = new Browser()
bindingUpdater = new BindingUpdater(bindingUpdater.binding, theBrowser)
bindingUpdater.initialize()
} else {
// save for later screenshot taking
theBrowser = browser
}

go "/cart"
}

Error 

      java.lang.NullPointerException: Cannot get property 'binding' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:304)
at hooks.Hooks.createBrowser(Hooks.groovy:17)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at cucumber.runtime.Utils$1.call(Utils.java:26)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)


Varun

Marcin Erdmann

unread,
Jan 11, 2020, 12:10:32 PM1/11/20
to geb-...@googlegroups.com
Hi Varun,

It looks like you're getting a null pointer exception which isn't surprising to me at all because you're not initialising the `bindingUpdater` variable anywhere and you are attempting to access a property of it. 

To be honest, I've never really used Cucumber for anything meaningful. All of the experience I have with it is keeping the project at https://github.com/geb/geb-example-cucumber-jvm, which was contributed by a community member, working as I release new versions of Geb. I can see that you are using what looks like a "hooks class" to me as opposed to using a script at src/cucumber/resources/env/env.groovy like in the example but I don't know which one is more "correct" for a cucumber project that is being bootstrapped at this point in time. I think this is a question which can probably only be answered by somebody with more knowledge about using Cucumber especially with Groovy.

Cheers,
Marcin

--
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/10e57b36-f4f6-4667-97db-2ffbe306da57%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages