Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException: Cannot invoke method propertyMissing() on null object #15

Closed
cressie176 opened this issue Jun 1, 2012 · 11 comments

Comments

@cressie176
Copy link

I'm getting the problem described in #6

I've started with a completely blank project.
Followed the instructions at https://github.com/hauner/grails-cucumber/wiki/Testing-Grails-with-Cucumber-and-Geb to the point where firefox is launching and the test is failing.
Then I went through and updated geb and selenium to the latest versions - everything still worked.
Finally I updated cucumber from 0.2.3 to 0.5.0 at which point I get the NullPointer...

| Error Error executing script TestApp: java.lang.NullPointerException: Cannot invoke method propertyMissing() on null object (Use --stacktrace to see the full trace)

BuildConfig.groovy

def gebVersion = '0.7.0'
def seleniumVersion = '2.21.0'

dependencies {
    test "org.codehaus.geb:geb-junit4:$gebVersion"
    test "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
    test "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
}

plugins {
    runtime ":hibernate:$grailsVersion"
    runtime ":jquery:1.7.1"
    runtime ":resources:1.1.6"

    test ":geb:$gebVersion"
test ":cucumber:0.2.3"

    build ":tomcat:$grailsVersion"
}

GebConfig.groovy

import org.openqa.selenium.firefox.FirefoxDriver

driver = {
    new FirefoxDriver()
}

No CucumberConfig.groovy

StackTrace

phobos:cucumber-test steve$ grails test-app functional:cucumber --stacktrace
| Server running. Browse to http://localhost:8080/cucumber-test
| Server stopped
| Tests FAILED  - view reports in target/test-reports
| Error Error executing script TestApp: java.lang.NullPointerException: Cannot invoke method propertyMissing() on null object (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.NullPointerException: Cannot invoke method propertyMissing() on null object
at geb.Page.propertyMissing(Page.groovy)
at cucumber.runtime.groovy.GroovyBackend.parse(GroovyBackend.java:96)
at cucumber.runtime.groovy.GroovyBackend.loadGlue(GroovyBackend.java:61)
at cucumber.runtime.Runtime.<init>(Runtime.java:63)
at grails.plugin.cucumber.CucumberTestType.prepareCucumber(CucumberTestType.groovy:90)
at grails.plugin.cucumber.CucumberTestType.doPrepare(CucumberTestType.groovy:56)
at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:282)
at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:248)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:195)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:184)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at TestApp$_run_closure1.doCall(TestApp.groovy:82)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at java_util_concurrent_Callable$call.call(Unknown Source)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:591)
at gant.Gant.executeTargets(Gant.groovy:590)
| Error Error executing script TestApp: java.lang.NullPointerException: Cannot invoke method propertyMissing() on null object
@hauner
Copy link
Owner

hauner commented Jun 2, 2012

Not 100% sure but I guess it is the CucumberConfig.groovy file. If you use test/cucumberand test/functional you have to configure this in the config file because the plugin uses test/functional as default now. I have updated the cucumber grails geb article.

Another possibility is a missing import in a step file. If you see GroovyBackend.parse in the callstack, cucumber has a problem parsing a groovy script file (hooks or steps). Spent already a few hours myself looking for this erro a couple of times....

I hope this helps..

@miinx
Copy link

miinx commented Jun 6, 2012

I'm getting the exact same issue. And Martin has been kindly trying to help me on the geb mailing list: http://markmail.org/message/ycduw5arw54k5ydz

So far unsolved.

@miinx
Copy link

miinx commented Jun 6, 2012

This is what's in my CucumberConfig.groovy file:

cucumber {
tags = ["~@wip"]

features = ["test/cucumber"]
glue = [
    "test/cucumber",
    "test/functional"
]

}

@hauner
Copy link
Owner

hauner commented Jun 6, 2012

Hi,

two things:

could you please try to remove the "test/functional" from glue. That does not work with the plugin since 0.5.0. It will be automatically on the classpath so we can still call the geb stuff from the steps but we don't want cucumber to look in "test/functional" for step or hook code.

Adding "test/functional" to the Books_geb example breaks the example with MethodMissing. It is not exactly the same message but I think it should help...

if not, it would be great if you could simply email me the source of your grails project (if there is nothing secret about it) so that I can take a look at it.

I have already gained some practice tracking down such issues building the plugin. ;-) It is probably just some little detail that needs to be documented.

Or may be we are looking at the wrong place and it is an environment problem:

I'm testing (using the Books_geb example) with grails 2.0.3/4, geb 0.7.0 and grails-cucumber-0.5.0.

What is your environment?

@miinx
Copy link

miinx commented Jun 7, 2012

OMG that made all the difference! Thank you Martin.

I removed the "test/features" section from CucumberConfig & changed it to "glue = features" as yours is, and now my tests are running. (Not passing yet, got other issues now! But at least they're running.

I did actually have the CucumberConfig file like that initially, but I also had the file structure with everything mixed together. Possibly the combination of correct file structure & correct glue config was required.

Thank you so much for your help, Martin!

@cressie176
Copy link
Author

Hi Martin,

Sorry for the lack of response. This is a pet project and I got side
tracked onto real work for a few days. I got it working now too. I'd
referenced an older version of the Geb plugin, and also not separated out
the steps into a separate cucumber directory.

Now that's working I've hit another snag. It doesn't seem possible to use
the grails-remote-control plugin with the cucumber plugin to setup remote
test data, e.g.

remote {
Book.build()
}

The reason is that the remote plugin requires the remote closure to be
compiled into a class file, but grails isn't creating class files for the
code under test/cucumber. I can workaround by putting the closures below
the test/functional source folder, but it's going to be a bit nasty. Any
thoughts?

Thanks,

Steve

On 2 June 2012 16:25, Martin Hauner <
reply@reply.github.com

wrote:

Not 100% sure but I guess it is the CucumberConfig.groovy file. If you
use test/cucumberand test/functional you have to configure this in the
config file because the plugin uses test/functional as default now. I
have updated the cucumber grails geb article.

Another possibility is a missing import in a step file. If you see
GroovyBackend.parse in the callstack, cucumber has a problem parsing a
groovy script file (hooks or steps). Spent already a few hours myself
looking for this erro a couple of times....


Reply to this email directly or view it on GitHub:
#15 (comment)

@hauner
Copy link
Owner

hauner commented Jun 15, 2012

Hi Steve,

moved the compiled step def issue to #17, closing this one. :)

@hauner hauner closed this as completed Jun 15, 2012
@superchris
Copy link

I'm getting exactly this same error, tried to follow these instructions and still get it.

@cressie176
Copy link
Author

I'm using the grails-cucumber plugin in my "jinkies" project. Might be a useful point of reference. Source code here - https://github.com/acuminous/jinkies

@hauner
Copy link
Owner

hauner commented Jan 20, 2013

Hi superchris,

did you try the suggestions mentioned in the older comments? If so, can you provide a stripped down grails project that I could look at?

I'm still working on #17 by the way (.. trying to understand my code I wrote a few month back ;-) too catch compile errors before running the cucumber features.

@trestletech
Copy link

FYI - I got this issue in IntelliJ when trying to run an individual test (Shift + F10) because it seems to explicitly name the test in the command executed:

--conf C:\<mypath>\grails-2.2.0/conf/groovy-starter.conf "test-app unit: com.myproj.PkgBuildService.testOneWarning -echoOut"

where testOneWarning is the name of a test. If I change the name of that test, the same code still gets run (for some reason), resulting in this Null Pointer exception when, presumably, the system can't find this test.

The workaround, for me, was to re-configure the context (Shift + Ctrl + F10) and select Grails which somehow brings it to recognize that there are new function names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants