0

I am new to Groovy programing and I am currently trying to test a web app with Geb and Spock on IntelliJ IDE. I wanted to try a simple script first without using Spock, that is why I use a simple main class for creating Browser and so on and run some basic tests (understand: verifying if I am at the correct page).

Everything was working well but I had a lot of page class that were melt in the same folder as my main class, modules and so on. So I decided to clean up by using packages. Here is my project folders:

src

---main

------groovy

------------app

---------------module

---------------pages

---------------templates

module folder contains the modules used in my pages pages folder contains the actual page the browser will browse templates folder contains some super pages class for not repeating content through pages instances.

My class Main with main method is in app folder.

So I re-run the code that was previously working well (when every source files were in the same folder) and I get an error Exception in thread "main" groovy.lang.MissingPropertyException: No such property: homePage for class: app.pages.loginPage

The line that seems to be the problem is this one (in loginPage.groovy) :

loginButton(to: homePage){$("input", id: "loginButton_submit")}

Which is in the static content of loginPage class.

I don't understand why I get this error as loginPage and homePage are in the same package. I guess I don't understand some groovy stuff here or compiling mechanics.

Here is the error messages I got :

The package is the correct one both in homePage and loginPage (they are in the same one) so the class seems to be resolved. But when running, `homePage` is considered as a static property of `loginPage`I suppose and as it is not declared in `loginPage` properties it cannot work. Here is my log :

Exception in thread "main" groovy.lang.MissingPropertyException: No such property: homePage for class: app.pages.loginPage at groovy.lang.MetaClassImpl.invokeStaticMissingProperty(MetaClassImpl.java:1004) at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1859) at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1835) at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3735) at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:175) at groovy.lang.Closure.getPropertyTryThese(Closure.java:312) at groovy.lang.Closure.getPropertyOwnerFirst(Closure.java:306) at groovy.lang.Closure.getProperty(Closure.java:295) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:50) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) at app.pages.loginPage$__clinit__closure4.doCall(loginPage.groovy:28)...

Do you have any ideas ?

2 Answers 2

0

Check to see if the package your homePage belongs to was updated when you moved it from "main" to "pages":

package app.pages

class homePage extends Page {

   }

If the package is incorrect or undeclared on the homePage class your loginPage will not be able to resolve it

6
  • The package is the correct one both in homePage and loginPage (they are in the same one) so the class seems to be resolved. But when running, homePage is considered as a static property of loginPageI suppose and as it is not declared in loginPage properties it cannot work. I added my output if it can help...
    – Saub
    May 5, 2017 at 12:13
  • As Rushby suggests, the class is not resolved and this is why homePage is treated as a property. Do both of the source files for aforementioned classes have package app.pages declaration at top of them? Does the error occur from both the IDE and Gradle? Note that by convention class names in Java and Groovy usually start with a capital letter.
    – erdi
    May 6, 2017 at 17:13
  • Yep packages are good. The error occurs only when I run the main. It seems that the reference to homePage in the option (to: homePage) is not considered as a reference to a class because when I tried with geb.Page which is an abstract class I don't get the missing property exception. So is it possible in groovy to refer to a class and not to an instance of one ?
    – Saub
    May 8, 2017 at 7:49
  • I fixed it by importing app.pages.homePage in loginPage class. However, I still don't understand why I need to do so whereas loginPage and homePage are in the same package.
    – Saub
    May 8, 2017 at 7:58
  • Classes located in the same package are automatically imported, make sure both pages belong to "app.pages". It would appear my answer was correct then?
    – Rushby
    May 8, 2017 at 8:29
0

Finally solved it thanks to this comment:

Note that by convention class names in Java and Groovy usually start with a capital letter.

All my classes where considered as variable. I still don't get why the behavior is different in default package so if anyone has a clue...

Thanks all for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.