Pass Argument across <test> Tag in tesNG

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pass Argument across <test> Tag in tesNG

Anurag Gupta
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 ?

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pass Argument across <test> Tag in tesNG

Krishnan Mahadevan

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/

 

From: <[hidden email]> on behalf of Anurag Gupta <[hidden email]>
Reply-To: <[hidden email]>
Date: Wednesday, August 9, 2017 at 3:34 PM
To: testng-users <[hidden email]>
Subject: [testng-users] Pass Argument across <test> Tag in tesNG

 

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 ?

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.