Getting error Could not find or load main class org.testng.TestNG - selenium

I'm trying to run TestNG from command line, but it's giving me error.
Can someone tell me where am I going wrong?
java -cp C:/TestNG directory/testng-6.2.jar;C:\project directory\src\com\suites\suite\shop org.testng.TestNG testng.xml
Error: Could not find or load main class org.testng.TestNG
My scripts runs fine when I ran them from eclipse testng plugin.

Copy the below commands in a text file.
Edit the location.
Save it as yourtext.bat
Now, double click on the batch file created.
cd C:\Workspace\projectname
java -cp C:\Workspace\projectname\lib*;C:\Workspace\projectname\bin org.testng.TestNG testng.xml

Path of TestNG.jar file was not set up.
Follow instructions of following site to set up. It worked for me:
http://qtp-automate.blogspot.com/2011/10/running-selenium-testng-test-from.html

Try above answers.
If still not work, then you might have downloaded the wrong version of testng.jar. From link testng.org, please click "here for ant users" to download a full testng.jar(11 mega bytes), not a "Maven Central" version(no more than 100k).
I have tested those two versions on centos following testng tutorial point

Possibly your testng.jar file is not in the lib folder that C:\Workspace\projectname\lib.
You should find testng.jar first in your computer and move it manually to C:\Workspace\projectname\lib. Then it will work

Check that the lib folder contains testng-6.8.jar(or any other version) file because testng.xml even executes successfully without testng-6.8.jar (or any other version) with the jars that gets added when we add TestNG library.

My Assumptions:
You are trying to run test file from command prompt
libs folder generated under Project/tagret upon using "mvn clean package -DskipTests"
class file generated under Project/target/test-classes/package-name
With above assumptions in mind, you can follow below process.
Setting class path in command prompt:
1. Open project location in command prompt
2. set classpath=C:\User\SeleniumTestProject\target\test-classes;C:\User\SeleniumTestProject\target\libs\*
3. java org.testng.TestNG C:\User\SeleniumTestProject\testng.xml

Related

"NoClassDefFoundError" when the jar file built by Intellij Idea artifacts was executed in command line

I have a problem with running my jar execution file built by Intellij Idea Artifacts in command line. Error message is
NoClassDefFoundError: io.mattmoore.kotlin.playground.cinterop.Greeter
But it worked when I use the IDE to execute "RUN".
Do you have any Idea why is that happening?
Highly appreciated if someone could give me a hint about how to fix it.
Harrison
IDE knows better where to find dependencies, but once you export .jar file, you need to manually ensure that no dependency is missing
(and that all get loaded).
Example:
To run MyProgram.jar, place all your dependencies inside of libs directory (which you need to create beside it), then use command like:
java -cp 'MyProgram.jar:libs/*' my_package.MyMainClass
OR for Windows (use semicolon)
java -cp 'MyProgram.jar;libs/*' my_package.MyMainClass
Note that dependency means other .jar files, for example, the one that defines io.mattmoore.kotlin.playground.cinterop.Greeter class.
See also How to call ".jar” with additional classpath option?

JavaFX application fail to launch with native exe bundle created with intellij ide

I have build a JavaFX application which can be executed by its jar file. However if i try to run it using the native exe bundle i am receiving two popups:
Error Invoking method
Failed to launch JVM
and the application fails to start.
The Javafx application is build with intellij ide.
The project structure looks as follows;
when launching the application following popup shows..
The config file looks as follows:-
The packaged jar file is executing properly...
the problem occurs when starting application with launching exe file.
kindly tell me what could went wrong?
UPDATE:
It seems that the build output runtime/bin directory does not contain java.exe file therefore i think the application does not launches.
the output when try to run the application is as follows:
i have build the application with intellij idea, i think there is a problem with that. Kindly look into this matter.
UPDATED:-
Run it from the command line using the runtime that was bundled for you:
If you made an executable Jar (with a proper manifest specifying the classpath and main class)
cd firecap
runtime\bin\java -jar app\libs\your-main.jar
If you don't have an executable jar use something like
cd firecap
runtime\bin\java -cp app\libs\*.* your.main.class.name
Since java.exe is a console program you should be able to see the full error output to get a better idea of what is going wrong.
You very likely have missed including a needed module in the runtime.
It is also possible you ran into a bug that I discovered recently: https://bugs.openjdk.java.net/browse/JDK-8254920
I created my runtime image with this command:
"C:\Program Files\BellSoft\LibericaJDK-15-Full\bin\jlink.exe" --no-header-files --no-man-page, --compress=1 --add-modules java.management,java.logging,javafx.controls,java.xml,java.desktop --output C:\MyProject\build\image\runtime
But yours may be different depending on what modules you need. Note also that I used a JDK from BellSoft that included the JavaFX modules to make it easier.

How do I run a EXE Go executable from within IntelliJ IDEA?

I have a Go program which I'm working on in IntelliJ IDEA on a Windows machine. The program's structure is a little unconventional (don't want to go into detail here as its besides the point) because of which I first have to compile the program using the following command:
go build -o cli.exe
And then I can run cli.exe directly in the command prompt.
But how do I configure the run configuration in IntelliJ IDEA so that it doesn't mind running a Windows executable ? Because if I try to tell it to run an EXE file as it's run configuration, it gives me error "Main file is invalid"
How do I solve this ?
Make sure you have a file name (not a folder name) in field File on Run/Debug Configuration window (In IntelliJ IDEA go to menu Run->Edit Configuration...->your_configuration). That was my case.
You may be able to install the Bash plugin on Windows, then create a run configuration using the Bash plugin, and just run your executable from a script.
Create a Go Application run configuration and that should work. You can choose to run either a file or a package. If you would share more details then the answer would be more complete. If you still have an issue with this, please open an issue to the bug tracker and I'll be able to help out (please follow the issue template there).

How to run a java application created in intelliJ at the command line?

I have a simple "Hello World" application created in intelliJ using Java. How do I run the application outside of intelliJ at a terminal command line?
First result in google: http://www.skylit.com/javamethods/faqs/javaindos.html
Run Command Prompt (found under All Programs/Accessories in the Start menu). Type
C:\> cd \mywork
This makes C:\mywork the current directory.
C:\mywork> dir
This displays the directory contents. You should see HelloWorld.java among the files.
C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin
This tells the system where to find JDK programs.
C:\mywork> javac HelloWorld.java
This runs javac.exe, the compiler. You should see nothing but the next system prompt...
C:\mywork> dir
javac has created the HelloWorld.class file. You should see HelloWorld.java and HelloWorld.class among the files.
C:\mywork> java HelloWorld
This runs the Java interpreter. You should see the program output:
Hello, World!
I have been struggling to output java code to terminal these days. I finally found a way to do that. Following are my steps hope this is of some use to you.
Get the class path where your main method locates and switch to that directory. In my case, my main stays in
Set path of your jdk, for example
set path=C:\Program Files\Java\jdk1.8.0_66\bin
Compile and run your code. Remember to include your package name. About package please have a look of this site: http://www.javatpoint.com/package
In my case, my main method is in Main.java, and Main.java is included in package sample
You can do exactly the same steps to get your output from cmd, command line console.

How to run TestNG with command line

I am running Test cases in Selenium with TestNG framework. Through eclipse I can run all xml together, but how can I run it by command line or bat file.
I have tried with
start java -ea -Dfile.encoding=Cp1252 -classpath "/D:/Eclipse 3.6.2/eclipse/plugins/org.testng.eclipse_6.8.6.20141201_2240/lib/testng.jar;D:\XML\SpringIntegration_NIC\new_temp\bin;D:\XML\SpringIntegration\lib\SeleniumServer.jar;D:\XML\SpringIntegration\lib\selenium-server-standalone-2.37.0.jar;D:\XML\SpringIntegration\lib\selenium-java-2.37.0.zip;D:\XML\SpringIntegration_NIC\new_temp\lib\sikuli-script.jar;D:\XML\SpringIntegration_NIC\new_temp\lib\sikuli-ide.jar;D:\XML\SpringIntegration_NIC\new_temp\build.xml" org.testng.remote.RemoteTestNG -serport 28844 -d D:\XML\SpringIntegration_NIC\new_temp\test-output D:\XML\SpringIntegration_NIC\new_temp\TestNG_parallel.xml
This is command how eclipse is giving while running from the eclipse. I have tried but some time its running and most of the time not running.
Navigate to the directory of your project using command line. Set a project path like this:
C:\projects\Selenium_Project set ProjectPath = C:\projects\Selenium_Project
Create a classpath which should point to the seleniu/testng class files and jar files.
C:\projects\Selenium_Project set classpath = %ProjectPath%\bin;%ProjectPath%\Lib\*
Where \bin points to class files and \Lib points to jar files, if you have kept jar files in other folder then point to that folder only.
Execute java command to run
C:\projects\Selenium_Project java org.testng.TestNG %ProjectPath%\TestXml.xml
Above solution will work if you are using Eclipse IDE
Please run testNg XML using following :
C:\TestNG_WORKSPACE>java -cp "C:\TestNG_WORKSPACE" org.testng.TestNG testng.xml