How to share variables between two classes when using TestNG.xml

845 views
Skip to first unread message

NAiyappa

unread,
Feb 12, 2014, 5:24:30 PM2/12/14
to testng...@googlegroups.com
Hello,

 In this particular project (web service test) I need to send email notifications to user after the user is authenticated. There are 2 APIs(endpoints) so, I have created two test classes. The first class AuthToken.java validates the user (here, i am using both @DataProvider and TestNG.Xml to pass user and API information). Here the method testAuthToken() returns a token upon success. The second class Notification.java needs the token  from the first class.  

I am using testng.xml to run my tests... something like this - 

<classes><class name="AuthToken" /><class name="Notification" /></classes>

So, my question is how to share variables between two classes here? Is there any parameter or interface to do this. 

I, checked http://testng.org/doc/documentation-main.html#dependent-methods, it says - "Any @AfterMethod method can declare a parameter of type ITestResult, which will reflect the result of the test method that was just run". But this is not clear to me and how to do this. 

Can someone please help?

Krishnan Mahadevan

unread,
Feb 12, 2014, 10:56:56 PM2/12/14
to testng...@googlegroups.com
I just now wrote up a blog post on how this can be done :



Thanks and Regards
Krishnan Mahadevan

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


--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages