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.
Related
I am trying to find bugs in a java file. I have added findbug plugin that is integrated with maven in Jenkins. I have used the following commands:
mvn compile
mvn findbugs:findbugs
I have a confusion on where to locate a file in the above command(.ear or .java file etc) for finding bugs.
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'm investigating to OpenNI SDK ant it's wrappers for .NET. So, I created MSBuild AfterBuild target to copy files from SDK folder (path from environment variable) to build output folder. Now build works on each computer (even if SDK isn't installed). But in this case build is very heavy.
Is there the way to create links to this files in solution? I need build to execute only for computers with installed SDK.
Add an Exists condition to the AfterBuild target, this would prevent the AfterBuild target from running.
<Target Condition="Exists('$(SdkLocation)')" Name="AfterBuild">
...
</Target>
You could also make a BeforeBuild target containing an Error task that will cause the build to break if the SDK is not detected.
<Target Name="BeforeBuild">
<Error Condition="!Exists('$(SdkLocation)')" Text="OpenNI SDK not found." />
</Target>
MsBuild should also be copying the SDK files to the output file if you've added References in the dependent projects. Are you copying extra files?
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.
I'm having a little trouble understanding how Solr fits in with Jetty, and why I can't seem to get the start.jar in the distribution package to work.
I can run all of the example configurations via java -jar start.jar. However, when I try to run something like the follwing --
java -Dsolr.solr.home=/Users/jwwest/solr -jar $(brew --prefix solr)/libexec/example/start.jar
-- the following error occurs:
java.io.FileNotFoundException: No XML configuration files specified in start.config or command line.
at org.eclipse.jetty.start.Main.start(Main.java:506)
at org.eclipse.jetty.start.Main.main(Main.java:95)
I opened up the start.jar file, and there is a start.config file located inside of the jar which I'm assuming should handle this configuration for me. I'm not understanding why it will work when run from inside of the distribution examples directory, but not outside of it.
You also need to define the jetty.home property. Try:
java -Dsolr.solr.home=/Users/jwwest/solr -jar $(brew --prefix solr)/libexec/example/start.jar -Djetty.home=$(brew --prefix solr)/libexec/example
You can see the effective command line start.jar generates by using the --dry-run command line flag.
java -jar start.jar --dry-run
That will output everything with full path names so you can run it from outside the directory.
Source: http://www.eclipse.org/jetty/documentation/9.0.0.M3/advanced-jetty-start.html
The start.jar is a jetty specific mechanism that works to build out all the classpath requirements for starting up Jetty. It is generally only used in the scope of the jetty distribution. Pulling the start.jar out of the configuration and placing it somewhere else renders the default configuration of the start.config rather moot.
My understanding of Solr is that it bundles itself with a distribution of jetty, placing what it needs to run into the distribution and repackages it as its own. They may have a custom start.config file that further adds its own locations for classpath resources and the like, or not.
The exception you are seeings stems from the start.config file expecting an etc/ directory containing jetty.xml formatted xml files which are used to configure the jetty process.
Jetty being often used in an embedded format has little to do with this issue, it is simply a common use case because jetty is incredibly easy to embed into an application. Embedded instances of jetty rarely (if ever) leverage a start.jar...instead it is up to the embedding application to manage its own classpath.
First, you need to change your folder where start.jar is located, then execute the same command.
Jetty is often used as embedded container. If you want to use the jetty, then a good start would be to copy the example directory and rename it to what you want it to be. The solr directory is the one for basic configuration.
Else it is recommended to use tomcat and the solr.war file.