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;
Related
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.
My team members and me often face the problem in Intellij that we cannot import some classes via Alt+Enter because Intellij hasn't indexed them successfully.
Our set up
We have different Flutter projects which belong and work together.
ProjectFolder:
our_project/customer_app
our_project/provider_app
our_project/server_app
our_project/model_app
Some of these projects have dependencies to other projects which are declared in the pubspec.yaml file.
Problem
E.g. the customer_app has a dependency to the model_app.
Now we add this new class in model_app such as class MyModel.
Later in the process we want to use MyModel inside of the customer_app.
If we type something like MyModel() and try to press Alt+Enter it doesn't find the class immediately. (it works miracously only sometimes)
What we have to do then is to copy the path of MyModel and do the import manually. Which is often time consuming.
We even tried to run flutter packages get which also doesn't help to find this import of MyModel. Ideally we want that Intellij find the import automatically by indexing it without copying the path out of the other project.
This is a known issue and planned to be fixed eventually.
You can upvote https://github.com/dart-lang/sdk/issues/25820
I can create a Groovy project and even run it. But when I type main or print there are no auto-complete / code completion suggestions at all. I have groovy-2.4.1 in the external library folder along with Java 1.8. I find Intellij frustrating and non-intuitive to use.
In a groovy script main does show correct code completion but when I click enter it puts "main()" without the String[] args that I can see in the suggestion.
You have created a Groovy class where code has to be embedded into a class to be executable and where only class member declarations are expected (e.g. functions, fields). Select to create a Groovy script (or just delete class declaration) to be able to write executable code in top level file. See also Scripts versus classes.
I was having the same problem when I was in a rush and forgot to add a method in which to write the code. Just type 'psvm + Enter' inside the class. This will create a main method in which code completion will work. Also, you can remove the public keyword as classes and methods in Groovy are by default public.
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.
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) { ... }
}
}