Pass Argument across <test> Tag in tesNG

43 views
Skip to first unread message

Anurag Gupta

unread,
Aug 9, 2017, 7:52:19 AM8/9/17
to testng-users
Hi ,

I am stuck to pass parameter obtained in one test to other . ItestContext only passes if it is in the same tag within testng.xml . For example.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Test1Suite">
         
</test>  
<test name="Test For Demo">
    <classes>
    <class name="testUtility.TestClass"/>      
                 <class name="testUtility.TestClass1"/>     
    </classes>  
</test> 
</test>  
<test name="Test For Demo2">
    <classes>
      <class name="testUtility.TestClass2"/>                        
     </classes>  
</test> 
</suite> 

By ITestContext we can only pass value from  testUtility.TestClass to testUtility.TestClass1 , but cannot pass from testUtility.TestClass to testUtility.TestClass2 . Is there any method to do so ?

Krishnan Mahadevan

unread,
Aug 9, 2017, 8:05:02 AM8/9/17
to testng...@googlegroups.com

Why not make use of ISuite for sharing data between <test> ?

 

At any point in time from within a @Test method, you can do something like this:

 

org.testng.ISuite suite =  Reporter.getCurrentTestResult().getTestContext().getSuite();

//To set an attribute use

suite.setAttribute("foo", "bar");

//To read a set attribute use

suite.getAttribute("foo");

 

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages