I Want to run one test choosen from testng file in jenkins via command shell in EXECUTE SCRIPT SHELL JENKINS as:
#!/bin/bash
args=("$#")
function goto
{
label=$1
cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
eval "$cmd"
exit
}
export projectLocation=E:\a\workspace_S2-2\FrameWorkAuto
cd $projectLocation
export classpath=$projectLocation$\bin;projectLocation\lib\*
java -cp "$projectLocation$\bin;projectLocation\lib\*" org.testng.TestNG -
testname "ManageAchat" TestNG.xml
My test.xml file looks like below:
<?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">
<classes>
<class name="com.az.testsFlux.TNR_Vente_TestsVente" />
</classes>
</test>
<test name="ManageAchat" group-by-instances="true">
<classes>
<class name="com.az.testsFlux.TNR_Achat_TestsAchat" />
</classes>
</test>
</suite>
java -cp "$projectLocation$\bin;projectLocation\lib\*" org.testng.TestNG -
testname "ManageAchat" TestNG.xml
When you use -testname you are telling TestNG to use the name called "ManageAchat" for the current test that is to be executed. This is overridden if there was a suite file found which defines a different name for the test via the <test> tag.
You should be using -testnames.
Quoting the documentation.
A comma separated list of test names.Only tests defined in a <test>
tag matching one of these names will be run.
For more information, refer to the official documentation here.
Related
I am creating Simple Page Object Model framework in Selenium Java.
One .java class is one scenario.
So if i write this in TestNg.xml it works fine for one scenario.
**<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="1" name="Test Simple Suite" parallel="false">
<listeners>
<listener class-name="com.proj.Listener.Listeners"></listener>
</listeners>
<test thread-count="1" name="Test Basic Scenario1" parallel="false">
<classes>
<class name="TC001_SampleCase"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->**
However, when i write second class, it also start the execution of the same. Expected is, it should execute in sequence. Following testNg executes both classed in parallel
**<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="1" name="Test Simple Suite" parallel="false">
<listeners>
<listener class-name="com.proj.Listener.Listeners"></listener>
</listeners>
<test thread-count="1" name="Test Basic Scenario1" parallel="false">
<classes>
<class name="TC001_SampleCase"/>
<class name="TC002_SampleCase"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->**
Would be really helpful, if anyone from the community can help on this issue. Thanks!
Also note, in both classes i have given priorities to #Test.
TC001_SampleCase consists 20 #Test given Priority from 1 to 20
TC002_SampleCase consists 15 #Test given Priority from 21 to 35
TestNg version: 7.3
Selenium version: 3.141.59
Can you try removing the Parallel Tag from Suite line. Just keep as below and try.
<suite thread-count="1" name="Test Simple Suite">
To executed test cases sequentially using testng.xml files, please pass
preserve-order="true"
I have three classes with different tests that I want to execute on chrome browser. The most important thing is that I want to run in parallel on Windows and macOS. How should I do it on Selenium 4 with Hub - > node setup?
My testng file looks like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Suite 1" parallel="classes" verbose="1" >
<test name="Test windows and macOS">
<classes>
<class name="test1"/>
<class name="test2"/>
<class name="test3"/>
</classes>
</test>
</suite>
When test is executed tests are running only on Windows with two browser windows.
Selenium documentation doesn't explain how to do this.
I have a testng.xml which will create a Claim for 2 companies parallel, the parameter here is company name. A gist of test tags in testng.xml are as below:
<suite name="Suite" thread-count="2" parallel="tests">
<test name="Test1">
<parameter name="TestParam" value="CompanyName1" />
<classes>
<class name="CreateClaim" />
</classes>
</test>
<test name="Test2">
<parameter name="TestParam" value="CompanyName2" />
<classes>
<class name="CreateClaim" />
</classes>
</test>
When I run this testng.xml, logs are generated haphazardly, mixing the logs of two test tags.
Is there any way in which I can save the logs of first test tag in one file and second test tag in other file?
It will be easy for us to check logs of each company specifically.
I have two testNG suites in my project. I want to run both of them in parallel.
Suite1:
class A
class B
Suite2:
class C
class D
I want to run SUITE1 and SUITE2 in parallel on the same machine. However, Class B of SUITE1 should be run only after Class A. Same with the second suite: the first and second classes need to be run in serial.
How do I achieve this?
In order to achieve, you need to add annotation as #Test(priority=??). The default value will be zero for priority.
If you don't mention the priority, it will take all the test cases as "priority=0" and execute.
If we define priority as "priority=", these test cases will get executed only when all the test cases which don't have any priority as the default priority will be set to "priority=0"
You dont need two xml for your requirement. Follow these and you should have same test running parallel.
<suite name="Test-class Suite" parallel="tests" thread-count="2">
<test name="Test-class test 1">
<classes>
<class name="com.ClassA" />
<class name="com.ClassB" />
</classes>
</test>
<test name="Test-class test 2">
<classes>
<class name="com.ClassC" />
<class name="com.ClassD" />
</classes>
</test>
Make sure your parallel parameter have parallel='true' and thread-count as per your requirement.
to execute classes as specified order, need to use preserve-order="true". As per below xml file, ClassB is specified first so ClassB is executed first then ClassA as we specified preserve-order="true"
If you want to execute #Test methods in class as per required order, please use priority. like below
#Test(priority=1)
below is xml file for example..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" preserve-order="true">
<test name="TestA">
<classes>
<class name="com.test.ClassB"/>
<class name="com.test.ClassA"/>
</classes> </test> <!-- Test A-->
<test name="TestB">
<classes>
<class name="com.test.ClassD"/>
<class name="com.test.ClassC"/>
</classes> </test> <!-- Test B-->
</suite> <!-- Suite -->
*****updating as per comment
Hi,
To execute two suites, need to create two xml files and specify your suites in those xml files. Then create another xml file to call these suites xml files..
Lets say i have one suite in testng1.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite1" parallel="false" preserve-order="true">
<test name="TestA">
<classes>
<class name="com.test.NewTest1"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
another suite in testng2.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite2" parallel="false" preserve-order="true">
<test name="TestB">
<classes>
<class name="com.test.NewTest1"/>
</classes>
</test> <!-- Test -->
then use another testng.xml file and call these two file. by executing this file, two suite will be executed.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="My test suite" preserve-order="true">
<suite-files>
<suite-file path="Testng1.xml"></suite-file>
<suite-file path="Testng2.xml"></suite-file>
</suite-files>
</suite>
I am executing testng in eclipse and I want generate the report in reportNG. For that I have inlcuded guice-3.0,reportng-1.1.3,velocity-dep-1.4 jar files and added listeners in xml file Also I have disable the default TestNG listener in eclipse.
After all that I am not getting the report in ReportNG. What else I have to do?
This is the xml code....
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Registration" verbose="1" preserve-order="true">
<parameter name="Suitename" value="Registration" />
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
<test name="Search">
<classes>
<class name="com.tcs.medmantra.reg.Search"/>
</classes>
</test>
</suite>
Thanks in advance.....
You have to first run the tests by running the testng.xml as TestNG suite.
Then after that refresh the project.
Now goto the test-output folder -->html-->index.html (Open with Web Browser).