retain value of one variable through complete TestNG run

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

retain value of one variable through complete TestNG run

garvitagirotraev
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 !

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

project_structure.PNG (62K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: retain value of one variable through complete TestNG run

⇜Krishnan Mahadevan⇝

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 [hidden email]

 

 

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 <[hidden email]>
Reply-To: <[hidden email]>
Date: Thursday, June 15, 2017 at 4:51 PM
To: Selenium Users <[hidden email]>
Subject: [selenium-users] retain value of one variable through complete TestNG run

 

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 !

 

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/F08775F3-CA60-4193-A68A-388CE96C994F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: retain value of one variable through complete TestNG run

garvitagirotraev
In reply to this post by garvitagirotraev
iTestContext worked for me. Thanks !


On Friday, June 16, 2017 at 9:26:14 AM UTC+5:30, [hidden email] wrote:
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= <a href="http://driver.findElementBy.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdriver.findElementBy.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF8yE-M5mGDAzz8DR4h-s_yCNJLDQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdriver.findElementBy.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF8yE-M5mGDAzz8DR4h-s_yCNJLDQ&#39;;return true;">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 !

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/16c4bfea-38a8-437e-80c2-4bba0686fcfe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.