Test suite result dependency in testNG - testing

I have test suite xml file that contains other test suites in the following format:
<suite-files>
<suite-file path="debug1.xml" />
<suite-file path="debug2.xml"/>
</suite-files>
Is there a way to add a dependency between the two sub suites? Meaning if debug1.xml fails, then debug2.xml should not be executed at all.
TestNG does not provide any dependency on the <suite-files> level. Can this be done, perhaps, through some listener?

You can define TestNG groups in your test code and arrange the dependencieslike:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="test">
<groups>
<dependencies>
<group name="debug1" depends-on=""/>
<group name="debug2" depends-on="debug1"/>
</dependencies>
</groups>
<suite-files>
<suite-file path="debug1.xml"/>
<suite-file path="debug2.xml"/>
</suite-files>
</suite>
References:
TestNG XML
TestNG

Related

Is it possible to have mutiple test suites in TestNG?

I know that we can have multiple tests in a single suite. But if I want to run more than one suite in a go, is there any way?. There were couple of questions already asked but the solution given doesn't seem to be clear.
You can create an XML file for each suite and after that, you can add them in testng.xml file like this
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestNG All Suites" >
<!-- suite name="Suite Name" -->
<suite-files>
<suite-file path="./firstSuite.xml" />
<suite-file path="./secondSuite.xml" />
<suite-file path="./thirdSuite.xml" />
</suite-files>
</suite>
./ - means that the file is located in the same directory as the testng.xml file

Extent Report no generating for multiple suites

I am trying to execute a suite of suite xml file .But extent report is generating only for first suite
<suite name="allSuites">
<suite-files>
<suite-file path="suite1.xml" />
<suite-file path="suite2.xml" />
<suite-file path="suite3.xml" />
<suite-file path="suite4.xml" />
</suite-files>
</suite>
Ideally if you have put the initialisation of the report in #BeforeSuite and flush() call in the #AfterSuite , then individual reports will be generated for all the suites.
Incase you followed the same and still its not as expected then please share more details.

How to configure TestNG testng.xml to ensure that one group runs at the end of all the other groups?

I have multiple test groups in my test suite (a,b,c, etc).
If I have to make a group 'z' run at the end of all other groups (the list is not fixed and can grow), how do I do it through testng.xml?
TestNG documentation suggests using the below in testng.xml:
<test name="My suite">
<groups>
<dependencies>
<group name="z" depends-on="a b c" />
</dependencies>
</groups>
</test>
But in my case a,b,c are not fixed. There can be tens of groups which I can't explicitly list in testng.xml everytime a new group is added.
This is how my current testng.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods" thread-count="5">
<test name="App tests">
<groups>
<run>
<exclude name="smoke"/>
<exclude name="rest"/>
</run>
</groups>
<packages>
<package name="apps.webdriver.*"></package>
</packages>
</test>
</suite>
Please let me know if there is a way to achieve this.
I can think of "grouping" tests in terms of classes/packages. Your z group will be in a separate class while a,b,c....will be in different class.

Can you run a suite of suites but exclude certain tests from running?

Is there any way to specify I would like to run a suite of suites but on a particular suite exclude specified tests?
<suite name="allSuites">
<suite-files>
<suite-file path="suite1.xml" />
<suite-file path="suite2.xml" /> <!-- exclude TestX and TestY -->
</suite-files>
</suite>

Not getting report of TestNG in ReportNG

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).