I am trying to execute a TestNG Suite file via the command line in order to initiate a regression run.
Currently I am doing this through my Eclipse IDE successfully by right-click on the "testng.xml" file then selecting Run As > TestNG Suite.
However, when I try to run it via the command line, I get an error message. Steps below:
I navigate to the directory where my "testng.xml" file is saved. e.g. C:\Users\xxx\Documents\eclipse projects\Automated Testing\config
Run the command:
java org.testng.TestNG testng.xml
The above command generates the below response:
Error: Could not find or load main class org.testng.TestNG
I tried setting the classpath to include all of the selenium and testNG Jar files as per below:
set classpath C:/Users/xxxx/Downloads/selenium-java-2.25.0/selenium-2.25.0/libs/*
However, this generates the below error message:
Environment variable classpath C:/Users/xxxx/Downloads/selenium-java-2.25.0/selenium- 2.25.0/libs/* not defined
I have looked on the testNG Documentation (http://testng.org/doc/documentation-main.html) and this just says that testNG has to be in your classpath, so now I am a bit stuck. Any help would be greatly appreciated.
Either methods work :)
Method #1
cd C:\Workspace\projectname
java -cp C:\Workspace\projectname\lib\*;C:\Workspace\projectname\bin org.testng.TestNG testng.xml
Method #2
cd C:\Workspace\projectname
set ProjectPath=C:\Workspace\projectname
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\lib\*
echo %classpath%
java org.testng.TestNG %ProjectPath%\testng.xml
Thanks #siemic, I have finally got it working now. Basically you just need
to run the two commands below:
set classpath=..\bin;C:\libs\selenium-java-2.25.0.jar;C:\libs\testng-6.0.1-nobsh
noguice.jar;C:\libs*
java org.testng.TestNG
It was the first command that I was having trouble with, so just to elaborate I needed to set the following three items on the classpath:
The BIN Directory of my project. This is because the java files that I have developed are located here.
The Selenium.jar file, this is because I am using the selenium framework
The testng.jar file, needed because this is my unit testing framework
Then finally I used a wildcard to include all other JAR files within my libraries folder. The weird thing
is I needed to fully specificy the name of the selenium and testng jar files, or else the tests don't work. Not too sure why.
Anyway it is working fine now and I am able to execute the tests via the command line.
Related
I was trying to run a TestNG.xml file from CMD but there are no errors shown and it seems that ChromeDriver is not starting.
Note: if i go to Eclipse -> right click on testng.xml -> run as TestNG suite it will work perfectly.
Below is the message i get when executing through cmd.
The bat file contains:
java -cp "D:\Java Applications\WebDriverProject\lib*;D:\Java Applications\WebDriverProject\bin" org.testng.TestNG testng.xml
pause
The testng.xml contains:
The project structure from eclipse is:
I figured this out. First of all, how you set up the classpath environment is crucial. The very first path must be a path to your project bin folder (where the .class files are found). I will just paste what my classpath environment looks like:
set classpath=C:\eclipse-2018\ACR_Tests\bin;C:\Selenium_dependencies\*;C:\TestNG\plugins\*
Set TestNG classpath:
java -classpath %classpath% org.testng.TestNG testng.xml
Note:
I have a "Selenium dependencies" folder also added to the classpath, this is a folder containing more selenium libraries, including chromedriver.jar
Download the zipped package:
selenium-chrome-driver JAR 3.12.0
It contains the dependencies that you need.
https://jar-download.com/artifacts/org.seleniumhq.selenium/selenium-chrome-driver/3.12.0/source-code
Extract all to a folder. In my case I called it "Selenium_dependencies".
Also, for TestNG libraries I'm using 7.0.0 release which you can download here:
http://dl.bintray.com/testng-team/testng-eclipse-release/zipped/
My testng.xml is like so:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="P1.ACR_Server"/> <!-- package.class -->
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Also - ensure that you have client-combined.jar included on the build path.
The build path should contain these libraries:
Running your tests using Maven (Recommended way)
From your screenshot I am inferring that yours is a maven project. Maven is a build tool that helps with building java code, running tests etc., in an easy fashion. But it looks like you haven't imported your project into eclipse as a Maven project.
So if you would like to run your tests via Maven, you would need to do the following :
Remove your project from the workspace (delete it from the workspace but not from the file system). Refer here to learn how to do it.
Now remove the following files from your project folder manually :
.settings (I think this should be a folder)
.classpath
.project
If you have already setup Maven properly in your machine (Refer here to learn how to do that), you can easily clean up the eclipse related files by opening up a command prompt, using cd command to navigate into your project directory such that dir pom.xml lists the pom.xml and then running the command mvn eclipse:clean
Now refer to this StackOverFlow post to learn how to import a maven project into eclipse and import the project into eclipse.
You now have your project configured properly so that eclipse recognizes your project as a maven project. Now to run the tests from the command prompt, (refer to surefire documentation to learn how to add surefire plugin to your pom file) run mvn clean test
Running your tests from command prompt
For running your project without using any build tool, you just need to append target\test-classes and target\classes directories to your java -cp command run it. So your modified batch file can look like below
java -cp "D:\Java Applications\WebDriverProject\lib*;D:\Java Applications\WebDriverProject\bin;D:\Java Applications\WebDriverProject\target\classes;D:\Java Applications\WebDriverProject\target\test-classes" org.testng.TestNG testng.xml
pause
On a side note, please add verbose="2" or higher to the <suite> tag in your suite xml file, so that it shows you what error occurred.
Also please ensure that your testng.xml resides under src\test\resources folder (you can very well create this folder if it doesn't exist).
well try to put TestNG.jar file https://mvnrepository.com/artifact/org.testng/testng/6.7 and jcommander jar https://mvnrepository.com/artifact/com.beust/jcommander/1.7 in lib folder.
Stackoverflow helped me a lot to reach that point but now I'm completely stuck, here is my problem :
I'm currently developing several tests to check a website. I code with Java in Eclipse, using testNG plugin with ReportNG for report, all of this using Windows 7 pro.
My tests work, and my report is well generated, so now I have to put it on Jenkins for my company so they will run my tests every X hours.
In order to launch my tests, I have made a file, named Run.bat, which runs the Java code, I tested it and it works, here is the code :
Run.bat
set classpath=blex_test_v1\bin;blex_test_v1\lib\*
java org.testng.TestNG blex_test_v1\blex_test_v1.xml
I now try to launch the tests on Jenkins, creating a new job and configuring it with the build section :
Run.bat
And this is my problem, I've tried everything (relative path, only the name of the file etc...) I always get this error :
java.io.IOException: Cannot run program "cmd" (in directory "/var/jenkins_home/jobs/blex_functional_test/workspace"): error=2, No such file or directory
So I checked the Jenkins workspace but my Run.bat is in it :
Workspace
I have read that Jenkins is in Linux so it might cause problem with bat files, so I tried to create a script but I didn't succeed either ..
So my question is : How can I run my test on Jenkins using my file Run.bat ? What am I doing wrong here ?
Thanks a lot !
Finally I can add an answer :
Jenkins is installed on a Unix machine so you can't run a bat file, it has to be a bash script.
To create a bash script, refer here.
Then you have to make sure that the plugin Xvfb is installed (and works) on the computer where Jenkins is installed.
I use testNG with reportNg and it doesn't work with the last firefox version so you I use firefox v34.0.5 and this version must be installed also on the Jenkins computer.
If you want to open the report after the execution, install another plugin and configure it (report HTML or something like that)
God it took me about a week but it's good to see it working !
I am using custom Nagios plugins for the first time and am running into this error when I create a service for the plugin.
(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/check_load.py, ...) failed. errno is 2: No such file or directory
The plugin works when I run it on the command line, however does not work when it runs within Nagios.
I followed these steps to get the plugin into Nagios
https://assets.nagios.com/downloads/nagiosxi/docs/Managing-Plugins-in-Nagios-XI.pdf
Here is what it looks like in the Nagios UI
The plugin is in the correct path: /usr/local/nagios/libexec and the resource.cfg file has the same path within it.
I tried two separate plugins, both which work on the command line, and the result is the same error.
The error indicates the file location is incorrect, however the plugin is in the specified directory and runs with no errors within that directory.
I am totally stumped and appreciate any help.
For anyone reading this, I solved the problem.
The first time I added the plugin, I forgot to add the python extension. When I updated the already created plugin, Nagios still threw the error.
Once I completely deleted the plugin and re-created it the 'file not found', error went away.
I faced a similar issue when I was trying to add a custom plugin ( I had custom plugins in ruby and python ).
The issue was the missing shebang line at the start of the script (which determines the script's ability to be executed like a standalone executable).
For example, if you have a python plugin custom-plugin.py then make sure this script has shebang at the start of script #!/usr/bin/env python3. Also if you have other scripts (ruby, bash etc.) make sure to add the appropriate path at the start of your scripts.
Also, check the path for plugins Nagios version. For my setup path was /usr/local/nagios/libexec/ and make sure your custom plugin is executable and has correct ownership permissions.
Sample custom template I used :
define command {
command_name check_switch_health
command_line /usr/local/nagios/libexec/check_snmp.rb --host $HOSTADDRESS$ --model "$ARG1$" --community "$ARG2$"
}
The above workaround worked for me.
To run tests in Jenkins I use the next batch command:
"C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" /result:TestResult.xml "C:\Users\Denis\Documents\Visual Studio 2013\Projects\MyProject\App.nunit"
Here how it looks in Jenkis:
The problem is: it doesn't generate TestResult.xml file!
When I run the same command as a .bat file from my desctop it creates the TestResult.xml file.
Any ideas what is wrong with Jenkins?
P.S. I searched for created file in all possible folders and even via "search"
I came up with thought that the file is generated and removed then or something like this.
The thing is that I don't see this file indeed but Jenkins generated report based on this file! So I think maybe after generating report the file was removed automatically.
I had faced the same issue and I found the test results xml file under my user directory in Win 7.
Note : I think it's some problem with nunit that it doesn't export the file to the location of which we provide the path.
I want to create a batch file for running Selenium. I need it to run it in Jenkins, now you can ask why you will do it with a batch file? There is a plugin for it, so use that one. Now it is impossible to use that plugin because it is to complex what I want, so I need to do it with a batch file.
I'm using selenium-java-2.20.0 and Firefox.
Thanks already!
This is the code and the error that I get:
C:\Users\User\Desktop>#echo off
C:\Users\User\Desktop>java -jar C:\Users\User\Downloads\selenium-java-2.20.0\selenium-2.20.0\selenium-java-2.20.0.jar -htmlSuite "iexploreproxy" "http://localhost" "C:\Users\User\Documents\Runner.html" "C:\Reports\Selenium\result.html"
Failed to load Main-Class manifest attribute from C:\Users\User\Downloads\selenium-java-2.20.0\selenium-2.20.0\selenium-java-2.20.0.jar
You're using the wrong JAR file. You want selenium-server-standalone-2.20.0.jar.