How to create Thread Local object using TestNG before and after methods

137 views
Skip to first unread message

mukil

unread,
May 24, 2012, 8:25:55 AM5/24/12
to testng-users

How do i create and destroy thread local object using TestNG.

Scenario :-

I have browser object created for every test method , i do
not want to create explicitly inside test methods, instead i want to
create & destroy using BEFOREMETHOD and AFTERMETHOD how do i achieve
this. Below code works fine in a Single thread , but when i execute as
parallel-method it fails


@BeforeMethod()
public void bm(ITestContext context){
context.setAttribute("BROWSER",new Browser());
}

@Test
piblic void mytest(ITestContext context){
....
.... access browser obj
}

@BeforeMethod()
public void bm(ITestContext context){
context.setAttribute("BROWSER",null);
}

Krishnan Mahadevan

unread,
May 24, 2012, 2:03:54 PM5/24/12
to testng...@googlegroups.com
You might want to read a bit About ThreasLocal variables in Java. That should help you answer your own qn. 
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.



--
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/
Reply all
Reply to author
Forward
0 new messages