Error while running TestNG using bat file - jenkins

Why this error:
Error: Could not find or load main class org.testng.TestNG
Occur while running TestNG using bat file?

You must provide classpath to testng jar using -cp argument. also for other dependent jars like selenium and test classes (project)
Try the following command:
java -cp J:\temp\testng\*;J:\temp\workspace\TestNGExamples\bin;J:\automation\* org.testng.TestNG J:\temp\workspace\TestNGExamples\testng1.xml
Note: please update the paths as per your machine.
For -cp argument, given the directory paths to
testng jar
test classes (project bin directory)
selenium jar

Related

Jenkins fails to find SureFire Reports

Jenkins Version : 2.176.2
Executing Selenium tests via Jenkins : Ecplsie+mvn+Jenkins
Selenium Workspace Folder : C:\Users\admin\eclipse-workspace\ACA
The actual location of the testng-results.xml: C:\Users\admin\eclipse-workspace\ACA\target\surefire-reports\testng-results.xml
Jenkins Insatlled / Home Directory: C:\Program Files (x86)\Jenkins
Building in workspace C:\Program Files (x86)\Jenkins\workspace\ACATestAutomationJob
Executing Maven: -B -f C:\Users\admin\eclipse-workspace\ACA\pom.xml clean install
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **/target/surefire-reports/testng-results.xml
Did not find any matching files.
How do i make jenkins locate this testng-results.xml?
Thanks,
Raj
Look into Jenkins Console Output, it should report where the build is running (so called WORKSPACE) and where TestNG Results Plugin attempts to locate the results file:
The path to the TestNG results file must be relative to the WORKSPACE and have the syntax of Ant FileSet
If you're uncertain regarding how to properly build the path to the test artifacts - post the full paths to WORKSPACE and the testng-results.xml / emailable-report.html and we will help you to come up with the correct definitions.
In the meantime you could use wildcard paths like:
**/testng-results.xml
so Jenkins will scan its WORKSPACE recursively looking for the testng-results.xml file in all available locations
Your install command also looks suspicious, normally you should not be putting your test artifacts to the Maven repository so you might want to use mvn test or mvn verify instead.
More information:
Turbo Boost Your Digital App Test Automation with Jenkins
https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

how to run Selenium tests in Jenkins

I want to run my Selenium Webdriver Maven tests in Jenkins. I've followed the tutorial: https://www.guru99.com/maven-jenkins-with-selenium-complete-tutorial.html and https://www.safaribooksonline.com/library/view/jenkins-the-definitive/9781449311155/ch04s06.html
But now, I want to run each of hundreds tests that I've written in Selenium Webdriver with Eclipse.
I use Maven to create testng.xml (where I have my Maven projects to can execute a list of tests in the same execution).
I use Eclipse to write Java to create tests in Selenium Webdriver.
I use github to import tests.
I show you my github project... I don't know how to access into the different folders to execute each testng.xml files, sorry, I'm pretty new here.
Could anybody help me with this issue?
Thanks so much!!!!
Create a freestyle Jenkins job and then go to the configuration page of your job and in Source Code Management section add the URL of your Git repo where you have kept your TestNG tests. This will help to bring the tests from the repository to your workspace.
Then go to the Build section and select Execute windows batch script if and then add the following script:
java -cp ".;/path/to/testng-x.x.x.jar;/path/to/jcommander-x.xx.jar;/path/to/test-classes" org.testng.TestNG /path/to/test.xml
For Linux use the following script with Execute shell in `Build step:
cd /path/to/test.xml
java -cp "/path/to/testng-x.x.x.jar:/path/to/bin" org.testng.TestNG testng.xml
Where /bin folder contains the compiled code for the TestNG tests.
Then save the job and run the build to execute TestNG test cases.
Note: You can find the required JAR files inside the .m2 folder.

Error: Could not find or load main class org.testng.TestNG

Error: Could not find or load main class org.testng.TestNG
I used the following steps/commands to run my testNG script through command prompt:
1. in my project folder, create a lib folder and copy all the jar files
2. open cmd --> cd myProjectDirectoryPath
3. set classpath=myProjectDirectoryPath/bin
4. set classpath=myProjectDirectoryPath/lib/*
5. java org.testNG.TestNG testng.xml
but after that i am getting Could not find or load main class org.testng.TestNG
error. tried to debug but still not successful. can someone help me.
Try at least to add to classpath:
set classpath=myProjectDirectoryPath/bin
set classpath=%classpath%;myProjectDirectoryPath/lib/*
If not, the second "set" override the first.
Of specify the cp (classpath) directly ni the java command:
java -cp myProjectDirectoryPath/bin;myProjectDirectoryPath/lib/* org.testng.TestNG testng.xml
In both instance, make sure you have a testng.jar in one of those folders.

IntelliJ code coverage runner - headless

According to:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206842605-Running-IntelliJ-code-coverage-headless-on-Jenkins-
It is possible to use intellij code-coverage runner in a headless environment - i.e. Jenkins.
This is nice since IntelliJ reports much more accurate coverage results on new groovy code than e.g. Cobertura. And I can also collect information from Grails tests - unit and integration. However, I have no idea on how to set it up - gradle, maven, custom build-script or whatever - on Jenkins.
When IntelliJ runs Grails tests it fires the following command:
C:\Program Files\Java\jdk1.7.0_79\bin\java
-XX:+TieredCompilation
-XX:TieredStopAtLevel=1
-XX:CICompilerCount=3
-Dgrails.full.stacktrace=true
-Djline.WindowsTerminal.directConsole=false
-Dgrails.build.listeners=org.jetbrains.groovy.grails.rt.GrailsIdeaTestListener
-Didea.launcher.port=7533
"-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3\bin" -classpath C:\Users\xxx\AppData\Local\Temp\classpath.jar
-Dfile.encoding=UTF-8 com.intellij.rt.execution.application.AppMain org.grails.cli.GrailsCli test-app -echoOut
Which indicates that IntelliJ should be installed to run it headless. Is it possible to execute the above command in a headless env?
I have tried unpacking intellij and by executing the following (slightly modified for linux) command:
java
-XX:+TieredCompilation
-XX:TieredStopAtLevel=1
-XX:CICompilerCount=3
-Dgrails.full.stacktrace=true
-Djline.WindowsTerminal.directConsole=false -Dgrails.build.listeners=org.jetbrains.groovy.grails.rt.GrailsIdeaTestListen r
-Didea.launcher.port=7533
-Didea.launcher.bin.path=/home/jenkins/idea/bin -classpath /tmp/classpath.jar
-Dfile.encoding=UTF-8 org.grails.cli.GrailsCli test-app -echoOut
it fails with:
Error: Could not find or load main class com.intellij.rt.execution.application.AppMain even with idea_rt.jar added to the command with "cp" flag.
Is this a goose chase, or could it be done?
Did you check classpath.jar on Windows? This file is automatically generated and links lots of jars via Manifest to avoid OS limitation for the maximum command line length. Your /tmp/classpath.jar either doesn't exist or doesn't link the dependencies correctly.
Final classpath would include several IDE jars from the lib directory, project classes from the output directory and dependencies, plugin jars, etc. In other words, everything required to run the app would be linked from the generated classpath.jar file.

Ant java task NoClassDefFoundError

I want to make a simple ant build hibernate test project.
There is no error during the compilation and the build (jar).
But when I run it I get this:
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration ...
I have found an advise, what said : jars should be added to classpath in the command line, (classpath is ignored when the jar run from ant ... ehh), ok I tried the following:
java -jar dist/student.jar -cp /home/myname/workspace/basic_ant1/lib/hibernate/hibernate-core-4.2.8.Final.jar
But still have the some error :NoClassDefFoundError ...
What did I wrong ?
Thanks for the replies in advance.
(org.hibernate.cfg is in hibernate-core-4.2.8.Final.jar)
Cs.
-jar and -cp are mutually exclusive.
If you want to use java -jar then your main JAR file needs a Class-Path entry in its manifest that points to all the other jars its Main-Class requires (the manifestclasspath task is a handy way to generate this value).
If you use java -cp then you have to give the main class name on the command line, the Main-Class from the manifest is ignored.

Resources