Reputation: 337
I am working with a TestNG xml file like the one copied at the bottom of this post. In order to parameterize the tests by browser, I have broken down each class into a separate node.
As part of our integration with our reporting software, we store a piece of data provided by each test method in an arraylist that is handled by the ITestContext object. In the @afterSuite method, that objects uploads that information to our reporting software
In other suites, where the classes all exist in the same node this works fine. However, in this suite, we only get data for the very last node. It appears to be overwriting the previous three by creating a new instance of ITestContext with each . Unfortunately I cannot consolidate this suite into a singe because we will lose the ability to parameterize the tests.
I need to know if there is an accepted way to pass information between test methods contained in different nodes. I've tried using static variables in the common parent (unsuccessfully), and can't find anything in the testNG docs about setting a global variable.
<suite name="UL" parallel="tests" thread-count="1" verbose="10">
<parameter name="env" value="jobcaseStaging6"/>
<parameter name="recordTests" value="1"/>
<listeners>
</listeners>
<test name="UL Tests firefox">
<classes>
<class name="tests.selenium_tests.ULTests">
<parameter name="browser" value="firefox"/>
</class>
</classes>
</test>
<test name="UL Tests chrome">
<classes>
<class name="tests.selenium_tests.ULTests">
<parameter name="browser" value="chrome"/>
</class>
</classes>
</test>
<test name="UL Tests safari">
<classes>
<class name="tests.selenium_tests.ULTests">
<parameter name="browser" value="bs_safari"/>
</class>
</classes>
</test>
<test name="UL Tests edge">
<classes>
<class name="tests.selenium_tests.ULTests">
<parameter name="browser" value="bs_edge"/>
</class>
</classes>
</test>
</suite>
Upvotes: 1
Views: 240
Reputation: 14746
So basically there are two scenarios here and for each of the scenario TestNG provides a proper way of sharing data:
@Test
methods) reside in the same <test>
tag and would like to share data amongst themselves. In this scenario you should make use of the ITestContext
object and share data via attributes of the ITestContext
object.
<test>
tag and would like to share data amongst themselves.In this scenario you should make use of the ISuite
object and share data via attributes of the ITestContext
object.
Basically :
ITestContext
represents a <test>
tag and ISuite
represents a <suite>
tagUpvotes: 1