retain value of one variable through complete TestNG run

瀏覽次數:35 次
跳到第一則未讀訊息

garvitag...@gmail.com

未讀,
2017年6月15日 晚上11:56:142017/6/15
收件者: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

未讀,
2017年6月16日 凌晨12:07:232017/6/16
收件者: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

未讀,
2017年6月16日 凌晨4:56:422017/6/16
收件者:Selenium Users
iTestContext worked for me. Thanks !
回覆所有人
回覆作者
轉寄
0 則新訊息