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.
Related
I have a testng xml file that is setup to run a specific class that has methods containing the following group tags or are grouped as one of the following:
parallel-test
sequential-test
smoke-test
Although some of my tests are designated as either parallel or sequential, some of the test may contain an additional tag 'smoke-test.' In this scenario, I want to be able to just run those that are grouped as 'smoke-test.' When I run the tests, it either cannot find any tests or it just runs all tests grouped as 'sequential-test.' I cannot seem to restrict the test run from this xml file to just those tests grouped as 'smoke-test.' In the same class, I have multiple testNG methods that have either the 'parallel-test' group or the 'sequential-test' group. What it looks like the TestNG xml file is doing is just ignoring the 'parallel-test' group. Thats great, but what if there is Testng method that contains the group 'parallel-test' and 'smoke-test?' I want to run every test regardless of whether it is for parallel testing or sequential, but ONLY those that have the additional group tag 'smoke-test.' My environment is the following:
IntelliJ
Maven
TestNG
Java
Please help. See sample test method in the WebTest.Test class:
#Test(groups = {"sequential-test","smoke-test"},description = "Test will validate something")
public void RunTest()
{
//do something
}
Here is the sample xml file below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!--This is a template to be modified for QA environment tests-->
<suite name="Smoke Test">
<listeners>
<listener class-name="Listeners.Listeners"/>
<listener class-name="Listeners.ExtentListeners"/>
</listeners>
<parameter name="environment" value="QA"></parameter>
<test verbose="2" name="Sequential tests" parallel="methods" thread-count="1">
<!--<groups>
<run>
<exclude name="parallel-test"/>
</run>
</groups>-->
<classes>
<class name="WebTests.Test">
<methods>
<include name="smoke-test"/>
</methods>
</class>
</classes>
</test>
</suite>
Below XML Suite should run the all test method having group 'smoke-test'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<!--This is a template to be modified for QA environment tests-->
<suite name="Smoke Test">
<listeners>
<listener class-name="Listeners.Listeners"/>
<listener class-name="Listeners.ExtentListeners"/>
</listeners>
<parameter name="environment" value="QA"></parameter>
<test verbose="2" name="Sequential tests" parallel="methods" thread-count="1">
<groups>
<run>
<include name="smoke-test"/>
</run>
</groups>
<classes>
<class name="WebTests.Test"/>
</classes>
</test>
</suite>
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>
I currently have two different TestSuites (SUITE1.XML and SUITE2.xml) with different configurations (e.g browsers, Os)...
I call both SUITES inside testng.xml to run on saucelabs... and it runs fine... Only what I am concerned is, I want these suites to run parallel instead of sequential...
The output i get is
[TestNG] Running:
/Users/muzamilabbasi/Automation/BaublebarTest/Suite1.xml
This is Browser String FIREFOX
This is Platform String WIN8
This is Version String 25
This is Browser String FIREFOX
This is Platform String WIN8
This is Version String 25
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Page Title isGoogle
Page Title isGoogle
===============================================
mysuite1
Total tests run: 2, Failures: 0, Skips: 0
===============================================
[TestNG] Running:
/Users/muzamilabbasi/Automation/BaublebarTest/Suite2.xml
This is Browser String FIREFOX
This is Platform String XP
This is Version String 7
This is Browser String FIREFOX
This is Platform String XP
This is Version String 7
Page Title isGoogle
Page Title isGoogle
I have searched alot of web and mostly answers I got is using ANT {PARALLEL} task I can achieve but how? I need an example.. Please help.
I am using macOS & TESTNG 6.8.6
Another option is to use a suite-of-suites. I'll preface this by saying it's been a while since I've worked with this setup, but hopefully you'll find enough detail here to at least get started.
First, you'd define two (or more) suite XML files:
<suite name="Suite1">
<test name="test1">
<classes>
<class name="fully.qualified.ClassName" />
</classes>
<methods>
<include name="method1" />
</methods>
</test>
</suite>
and...
<suite name="Suite2">
<test name="test2">
<classes>
<class name="fully.qualified.ClassName" />
</classes>
<methods>
<include name="method2" />
</methods>
</test>
</suite>
Then, you'd define a suite-of-suites XML file:
<suite name="suite of suites">
<suite-files>
<suite-file path="Suite1.xml" />
<suite-file path="Suite2.xml" />
</suite-files>
</suite>
Do note, that the suite-file path value is the relative path from the current suite-of-suites XML file to the XML file you're calling. If they're in the same directory, simply the file name will suffice.
Additionally, both XML types do support the <parameter> tag. The standard suite XML will read both at <suite> and in the <test> levels, and I've found that <parameter> tags at the <suite> level on the suite-of-suites XML file will work as well.
Finally, on execution, you'd need only pass in the suite-of-suites XML file as your suite file argument.
EDIT:
Here's how I was able to make my two suites run in parallel. The trick was setting up my main() method properly.
public class TestRunner
{
public static void main(String[] args)
{
TestNG testng = new TestNG();
TestListenerAdapter adapter = new TestListenerAdapter();
List<String> suites = new ArrayList<String>();
testng.addListener(adapter);
suites.add(args[0]);
testng.setTestSuites(suites);
testng.setParallel("parallel");
testng.setSuiteThreadPoolSize(5);
testng.setOutputDirectory("path to output");
testng.run();
}
}
Then, on the command line:
java -jar ParallelSuiteDemo.jar SuiteOfSuites.xml
Note, my jar and all xml files were in the same directory with this configuration. The command line args and <suite-file> entries would need to be configured properly if you wish you use a directory structure.
This yielded my two suite.xml files running in parallel on a Selenium Grid.
There may be better ways of doing this, to be honest. This is just what worked for me when I was trying to do something similar.
You no need to run suits in parallel....instead you can write two tests in single testng.xml suit and can run it in parallel.
If you want to use two different configurations for different tests (browser/os etc) make that as a parameter in testng.xml and use selenium grid to redirect each threads to appropriate nodes
Have look at the below example
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Test Suit" verbose="2" parallel="tests">
<test name="Regression Test">
<parameter name="browser" value="firefox" />
<parameter name="os" value="win7" />
<classes>
<class name="pakagename.classname" />
</classes>
</test>
<test name="Smoke Test">
<parameter name="browser" value="chrome" />
<parameter name="os" value="mac" />
<classes>
<class name="pakagename.classname" />
</classes>
</test>
Also may be you can run two testng.xml suits using ANT or MAVEN. But I prefer 1st one. Please add the below section in pom.xml of your MAVEN project
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng1.xml</suiteXmlFile>
<suiteXmlFile>testng2.xml</suiteXmlFile>
</suiteXmlFiles>
<reportsDirectory>${basedir}/src/test/java/</reportsDirectory>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugins>
<build>
Yes, you can do this by using "suitethreadpoolsize" attribute of testng
<suite-files suitethreadpoolsize="2">
<suite-file path="suite1.xml" />
<suite-file path="suite2.xml" />
</suite-files>
Refer the testng's official website for more details
http://testng.org/doc/documentation-main.html#parallel-running
Thanks!
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/