Geb/Groovy : Page object class considered as a property in another when refering to with "to" option - intellij-idea

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 ?

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

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.

Related

IntelliJ This class already exists conflict between main and test directory

I'm trying to name my class Util inside the src/test directory. However, another class with this same name already exists inside src/main, and IntelliJ is blocking me from doing this renaming. Funny thing is that the class inside the test folder was already named Util and that was fine before, but today IntelliJ started complaining about it and was no longer finding my methods inside that class, looking for them inside the Util class inside src/main instead.
I tried deleting the idea folder and reloading the project, but the same error is still there and I'm not sure how to fix it.
Thank you.

Listener in Testng

I have created a listener class in my project. Now what I have read in web there are two methods to add a listener either to your class or to testng file.
Please check in the folder structure. For now, I m using it like this in my java class but it is giving me error as in image attached:
#Listeners({Test.tes.Utils.ListenerUse.class})
From your screenshots, I understand that your test class HomeTestCases.java resides in the package Test.test.MyHomepageTestCases in src/test/java
You are trying to refer to the listener ListenerToUse.java that resides in the package Test.tes.Utilsin src/main/java.
When you use #Listeners(Test.tes.MyHomepageTestCases.MyHomepageTestCases.ListenerToUse.class)
Here you are basically telling Java to look for the listener class ListenerToUse inside Test.tes.MyHomepageTestCases.MyHomepageTestCases (as a nested class), but that's not the case because ListenerToUse is NOT a embedded class inside MyHomepageTestCases.java.
To fix the problem please do the following:
Change: #Listeners(Test.tes.MyHomepageTestCases.MyHomepageTestCases.ListenerToUse.class)
To: #Listeners(Test.tes.Utils.ListenerToUse.class)
I think the issue is you're mixing the package of your Listener, and the package of the class where you want to add it.
Your code now:
#Listeners(Test.tes.MyHomePageTestCases.MyHomePageTestCases.ListenerUse.class)
Correct package:
#Listeners(Test.tes.Utils.ListenerUse.class)
However, you've named your package "Test", which is (besides breaking Java naming conventions -> https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html) clashing with the TestNG Test class. On your screenshot, I can see that "Test" is grayed out. If you hover with your mouse over it, you'll probably see Eclipse has resolved it as "org.testng.annotations.Test". So you have two options:
Name your packages properly and try again
Expand the imports sections of your HomeTestCases class; manually add:
import Test.tes.Utils.ListenerUse;
and delete the following:
import org.testng.annotations.Test;

How to select a different module to run when you click the Run button in IntelliJ IDEA?

In my IntelliJ IDEA project, I have 3 modules written in Kotlin:
An HTTP Servlet one.
A desktop swing application; and
A library that contains contracts that the above two listed projects share to talk to each other.
When I click the Run button, it starts the Tomcat server and loads up my servlet project. That is because, and I am guessing here, the new project creation template inside of the IDE created a new Run Configuration for the entire project and it is defined in this run configuration that it must start the module that has the servlet inside it.
Now that the servlet runs fine, I'd like to also run the desktop application written using Swing.
How do I do that? I've done this once before but I have forgotten how I did it.
Do I have to define a new Run Configuation? I tried that this way:
I selected Kotlin from the left pane titled Add New Configuration and specified the name of the class that had the main function, and also the name of the module that had this class.
Here is the source code of my main class.
package bookyard.client;
import javax.swing.SwingUtilities;
public class Program {
public fun main(args : Array<String>) {
SwingUtilities.invokeLater(LoginDialogEventLoop());
}
}
But when I click the Run button after choosing that run configuration's name, the process reports an error that suggests that the class name I specified as having the main function actually does not have the main function, which I am not sure why that is.
The main method needs to be static, and the method you have declared is not. In Kotlin, you can either declare main as a top-level function (outside of a class), or, if you want to keep it inside the class, use the following syntax:
class Program {
companion object {
#JvmStatic fun main(args: Array<String) { ... }
}
}

SilverStripe 3: Can a module extend mysite/code/Page.php?

Good afternoon,
I don't know if what I want to do is possible, so here goes.
I have a module that extends Page_Controller, but I want certain functions to be accessible via the site root.
Eg: getMyDataObjectList();
Currently, they only work if I go through the normal MVC routing structure.
I've found that when I place the function 'getMyDataObjectList' within '/mysite/code/Page.php' it works.The problem is, I don't want to place the code in there. I want it bundled with my Custom Module, but to work the same as though it was in 'mysite/code/Page.php'
[Example Scenario]
site root: http://[somesite].com
By default, the 'Page.ss' template loads.
I would like the theme developer to be able to call my module functions (API) within any template/Layout page, and have the result returned from the site root
Currently, this only works if I move the "API" functions to '/mysite/code/Page.php'
If the code is in my module, then data is only returned when you go to:
http://[somesite].com/[module_controller]
Can this be achieved? If so, how?
Thanks for your assistance.
[Update - Code Solution]
///>MyExtension.php
class MyExtension extends Extension{
public function getMyDataObjectList(){
return 'object list goes here!';
}
}//class
///>[Module] => _config.php
Object::add_extension('Page_Controller', 'MyExtension');
And as always, I do a (/dev/build?flush=1) just in case.
Thanks to: 'simon_w'
Yes, this is relatively straightforward. Simply, create an Extension subclass with your methods in them and then add that to Page_Controller. An Extension subclass is almost exactly the same as a DataExtension, they're just for classes other than DataObjects.

Prestashop Class 'ProductCore' not found

So first of all I am new to prestashop.
I installed it and bought a theme.
After installing the theme I get this error when I try to view my store
(with error reporting on, otherwise it was a blank screen)
Fatal error: Class 'ProductCore' not found in /nfs/home/mywebsite.com/public_html/store/classes/Product.php on line 4
I haven't done anything with the codes...
Why do I get this and how can I get rid of it?
The file Product.php in /nfs/home/mywebsite.com/public_html/store/classes/ must be the one from the original distribution and if needed overridden at nfs/home/mywebsite.com/public_html/store/override/classes/.
The original class is defined as: "class ProductCore extends ObjectModel"
The override as "class Product extends ProductCore"
Most probably the file that must be in the "override" folder is being copied at the core classes folder.
Just copy the /nfs/home/mywebsite.com/public_html/store/classes/Product.php to /nfs/home/mywebsite.com/public_html/store/override/classes/
and the Product.php from the original distribution (the same PS version) to /nfs/home/mywebsite.com/public_html/store/classes/
Make sure you backup all the files that you're overriding.