Currently working on selenium webdriver and using java.
I have created a java project as OneReports and inside the project i have many java files as shown in the screenshot
I'm trying to run the java file through command prompt and getting error as follows:
C:\Program Files\Eclipse\eclipse>java LoginOneReports.java
Error: Could not find or load main class LoginOneReports.java
At the same time i want to create a task scheduler for the Test.xml. The xml file contains three java files as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestAll">
<test name="test1">
<classes>
<class name="test.LoginOneReports" />
</classes>
</test>
<test name="test2">
<classes>
<class name="test.OEPR_DefaultTab" />
</classes>
</test>
<test name="test3">
<classes>
<class name="test.OEPR_InternalvsExternalTab" />
</classes>
</test>
</suite>
I have created a run.bat as follows:
#echo off
set ProjectPath=C:\Documents and Settings\amth\workspace\OneReports\src\
echo %ProjectPath%
set PATH=%ProjectPath%bin;%ProjectPath%lib*
set path=%PATH%%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files (x86)\Java\jdk1.7.0_51\bin;
echo %PATH%
pause
echo java org.testng.TestNG %ProjectPath%Test.xml
I'm getting the error as error could not find or load main class. Please any one can help immediately.
From command line run the below commands one by one
cd C:\Documents and Settings\amth\workspace\OneReports\src\test
javac LoginOneReports.java
java -cp . LoginOneReports
You should study the docs on how to run the java program from command line
http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html
http://www.sergiy.ca/how-to-compile-and-launch-java-code-from-command-line/
Related
I Have TestNg Class look like the following code:
And I have On Jenkins two jobs: job1 and job2 job1 to execute TestsFluxPro and job2 to execute TestsVente tests
my question is how to configure Jenkins to tell in each job run the chosen class test for example in job 1 I want to execute com. AZ. testsFlux. TestsVente!!!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"
/>
<listener class-name="com.az.utilities.CustomListeners" />
</listeners>
<test name="Managetestss" group-by-instances="true">
<parameter name="browser" value="firefox"></parameter>
<classes>
<class name="com.az.testsFlux.TestsFluxPro" />
<class name="com.az.testsFlux.TestsVente" />
</classes>
</test>
</suite>
Reconsider using testng.xml, you will not be able to parameterize it from Jenkins.
There is a possibility to run your TestNG test in command-line mode where you have -testclass parameter:
-testclass A comma-separated list of classes that can be found in your classpath. A list of class files separated by commas (e.g. org.foo.Test1,org.foo.test2).
So you should be able to kick off your tests execution like:
For com.az.testsFlux.TestsFluxPro :
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsFluxPro
For com.az.testsFlux.TestsVente
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsVente
To run both:
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsVente,com.az.testsFlux.TestsFluxPro
etc.
I have a testng.xml like below. I am trying to run test by names which are in testng.xml (myfirstcase or mysecondcase) by using maven command line.
command line:
mvn -Dtest=myfirstcase -Dsurefire.suiteXmlFiles=/Users/huseyintumer/IdeaProjects/experitestandroid/testng.xml test -f /Users/huseyintumer/IdeaProjects/experitestandroid/pom.xml
When i command line below, it works. But parameters in testng.xml does not pass.
mvn -Dtest=firstTest -Dsurefire.suiteXmlFiles=/Users/huseyintumer/IdeaProjects/experitestandroid/testng.xml test -f /Users/huseyintumer/IdeaProjects/experitestandroid/pom.xml
Actually i dont want to run test by class name. I need to run test by test names in testng.xml with parameters.
testng.xml:
<suite name="Suite" parallel="tests">
<test name="myfirstcase">
<classes>
<class name="firstTest">
<parameter name="udid" value="CQ300002LG" />
</class>
</classes>
</test>
<test name="mysecondcase">
<classes>
<class name="firstTest">
<parameter name="udid" value="BH90018AAX" />
</class>
</classes>
</test>
Actually I'm testing multiple website for my company. All the website have the same structure and i'm testing various things on each.
For my test i have a Selenium Java Maven project using TestNG. For each web site, i've created a sub folder and generate a specific testing.xml file to specify each test i'm doing for the website.
Here the structure : http://imgur.com/g0VHfMw
My testing.xml files are like this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test suite website 1" parallel="tests" thread-count="2">
<test name="Test1">
<classes>
<class name="package.for.mytest1"></class>
</classes>
</test>
<test name="Test2">
<classes>
<class name="package.for.mytest2"></class>
</classes>
</test>
<test name="Test3">
<classes>
<class name="package.for.mytest3"></class>
</classes>
</test>
</suite>
How can I merge this 4 test suite in one testNG report ? And if it's possible, is there a way to only show the unstable or failed test on it ?
Any ideas ? Thanks for your help
Try Allure it could easily generate combined report for several suites and show only failed/broken tests by default.
Either you can Use Suite-XML tag in TestNG.xml file to report all your test in single report or implement a reporter of your own to collect all the results and then at the end flush everything into report of your own format with whatever information you need.
You can create a separate testng.xml file in which you can give the path of other testsuites files.
eg:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name= "Allsuites" verbose="1" preserve-order="true" >
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>
<suite-files preserve-order="true">
<suite-file path="testng1.xml" />
<suite-file path="testng2.xml" />
<suite-file path="testng3.xml" />
</suite-files>
</suite>
In eclipse, when we run some java file, having test methods, by right clicking on it and selecting Run As -> TestNG Test, we can see following line in 'Console' tab -
[TestNG] Running:
C:\Users\USER-NAME\AppData\Local\Temp\testng-eclipse-1663319006\testng-customsuite.xml
This means TestNG generates testng-cutomsuite.xml and runs it.
testng-cutomsuite.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default suite">
<test verbose="2" name="Default test">
<classes>
<class name="org.test.saifur.StackOverflowTest"/>
</classes>
</test> <!-- Default test -->
</suite> <!-- Default suite -->
But if I've testng.xml in my project and it has parameters like -
<parameter name="browser" value="chrome" />
<parameter name="baseUrl" value="http://stackoverflow.com" />
and when I run my test class as TestNG through eclipse, I want these parameters to be added to testng-customsuite.xml so that those parameters will be used in the test script.
Is there any way by which I can achieve above?
I got answer for this question from testng-users google groups(https://groups.google.com/forum/#!topic/testng-users/q7mLtIsEUCc). Posting same here so that if others who are looking for this get benefited -
Set your testng.xml as a TestNG template xml file via Project > Properties > TestNG in eclipse. What you are looking for should now be available.
This feature exists only in eclipse and not in IntelliJ
Here , this is one another link, so thought of sharing for someone looking for answer. It shows exactly what your question ask. We need to create XML Template globally and then
c.getCurrentXmlTest().getParameter("n") this can get the parameters in #Test
I have a JAR(xyz.jar) with test class test.sample.ClassX. I am trying to use this class in testng.xml shown below,
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SuiteX" verbose="1" >
<test name="TestX" >
<classes>
<class name="test.sample.ClassX" />
</classes>
</test>
</suite>
My pom.xml has dependency(xyz.jar) added. I can execute this suite from eclipse but fails when i try to execute from command-line(mac) with below error,
error: package test.sample does not exist
Any idea what the issue might be ?
My first guess is that you might not have a class defined like:
package test.sample;
public class TestX
{
...