I'm working in a test suite and I'm currently trying to implement the following design based on the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<parameter name="server" value="http://www.smartdate.com/"/>
<test name="Test" preserve-order="false">
<classes>
<class name="testscripts.SetUp"/>
<class name="testscripts.TestHome"/>
</classes>
</test>
</suite>
In this short example I want the following:
Run SetUp configurations (this class only defines #BeforeSuite, #AfterSuite and may be other annotations like #BeforeClass, #AfterClass, no #Test methods here).
Run all the following classes, in this example just one, "TestHome" but maintaining the previous configurations.
Now the question is, is this possible?
Thank you in advance,
Nahuel
Well, have you tried your proposed design at all? It should work. Try it and report back if something is not working as expected.
Related
I would like all my classes running sequentially. Below is my testng xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="instances" thread-count="1">
<test name="Test">
<classes>
<class name="atk.tests.Printer"/>
<class name="atk.tests.Rejecteur"/>
<class name="atk.tests.Specfeatures"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
I've tried in suite name tag to do :
<suite name="Suite" parallel="instances" thread-count="1"> then
<suite name="Suite" parallel="false" >
And then in classes:
<classes parallel="methods">
No solution is working to make my tests running sequentially. For the moment, they are running in parallel and i would like to avoid that.
Is anyone able to provide a solution for that ? Thanks
By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictable order, set the preserve-order attribute to false
For this ordering, you can use the XML attribute group-by-instances. This attribute is valid either on <suite> or <test>
<suite name="Suite" group-by-instances="true">
or
<test name="Test" group-by-instances="true">
try once with preserver order true and parallel none
<suite name="Suite" parallel="none" preserve-order="true">
Below is the testng.xml code. here I have test name Test1 and I want to include all the scenarios starting with regression tag (tag is present in cucumber feature file).
I want to parameterise "regression.*" value and want to pass as an argument at run time (Runas testng).
<test name="Test1">
<groups>
<run>
<include name="regression.*"/>
</run>
</groups>
Can somebody help me with this scenario.
Thanks in advance.....
You should be able to build the dynamic ability to pick and choose a group at runtime using a beanshell as a method selector.
Here's a sample beanshell powered suite xml. In the below sample, we are making use of a JVM argument -DgroupToRun to pass in the name of the groups which we want to be executed.
For more details on how to work with beanshells in TestNG take a look at
The official documentation here
my blog post here
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
<test name="Test">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
whatGroup = System.getProperty("groupToRun");
groups.containsKey(whatGroup);
]]>
</script>
</method-selector>
</method-selectors>
<classes>
<class name="organized.chaos.GroupsPlayGround" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
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 have created maven project using selenium webdriver in these I have integrate the testng, but when I validate my maven project it displayed "Attribute "parallel" with value "none" must have a value from the list "false methods tests classes instances" in testng-failed.xml and in testng.xml.
Can anyone please help me to resolved this problem.
testng-failed.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Failed suite [Gmail]" parallel="none">
<test name="GmailLoginTest(failed)" parallel="none">
<classes>
<class name="gmailTestcc.LoginTest">
<methods>
<include name="setUp"/>
<include name="mainAndGmailDashboardTest"/>
</methods>
</class> <!-- gmailTestcc.LoginTest -->
</classes>
</test> <!-- GmailLoginTest(failed) -->
</suite> <!-- Failed suite [Gmail] -->
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Gmail" parallel="none">
<test name="GmailLoginTest">
<classes>
<class name="gmailTestcc.LoginTest"/>
</classes>
</test> <!-- GmailLoginTest -->
</suite> <!-- Gmail -->
Based on your error message, I think this problem was caused by this attribute in your testng.xml "parallel="none"". Could you change it to false to have a try?
The issue is not related to Maven, it relates to TestNG itself, you can try solving it either by replacing
parallel="none" by parallel="false"
or changing your TestNG version from (6.9.10) to (6.9.9) because this issue is related to TestNg version 6.9.10.
Please note that if you used the second solution (which is better), you have to change
parallel="none" by parallel="false"
Error: Attribute "parallel" with value "none" must have a value from the list "false methods tests classes instances throws by the testNG if parallel execution is not handling properly in test suite :
if want to handle test execution parallel then use below xml suite:
<suite name="regression" parallel="test" threadcount="10">
Otherwise don't use parallel attribute in test 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