retain value of one variable through complete TestNG run

35 views
Skip to first unread message

garvitag...@gmail.com

unread,
Jun 15, 2017, 11:56:14 PM6/15/17
to Selenium Users
Hi,

I am using testng and maven to create a framework.  Folder structure has 4 classes .

1. In first class createclient,  there is filed that accepts unique name. So i am inputting name in input field like : sendKeys("TestProject"+randomname(3)), where randomname() is function that creates random text and appends to TestProject.

2. I get this  value in string . String s1= driver.findElementBy.id("requestername").getAttribute("value")

3. Now second class is create project. In this class, there is dropdown that selects client name. I want this to be the name created in earlier class. As its random so cant hardcode it. If i use string s1 in this class by creating createclient class object, it gives me null.


Is there any way in which value of variable can be stored for one complete test run.

Thanks !

project_structure.PNG

Krishnan Mahadevan

unread,
Jun 16, 2017, 12:07:23 AM6/16/17
to seleniu...@googlegroups.com

One way in which you can do this is to add the value of s1 as an attribute into your ITestContext (You can get access to it from within a @Test annotated TestNG method using org.testng.Reporter.getCurrentTestResult().getTestContext()) and then read it from your second class.

One caveat would be that you need to ensure that the classes are never run in parallel by TestNG.

 

PS : This forum is intended only for Selenium/WebDriver related queries. Since your question is more to do with “How do I share data between tests in TestNG” I would suggest that you please post these questions on the TestNG forum (testng-users testng...@googlegroups.com)

 

 

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 "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/34a2edbb-e510-4d5e-aa89-544d6f9d7345%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

garvitag...@gmail.com

unread,
Jun 16, 2017, 4:56:42 AM6/16/17
to Selenium Users
iTestContext worked for me. Thanks !
Reply all
Reply to author
Forward
0 new messages