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
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/geb-user/10e57b36-f4f6-4667-97db-2ffbe306da57%40googlegroups.com.