Pass around own reference (multithreading)

68 views
Skip to first unread message

MaC

unread,
Jan 19, 2012, 6:53:42 AM1/19/12
to testng-users
Hi Folks!


I wonder if I can pass my own reference to an object to the testNG
methods. For instance I want to have a reference to a selenium
webdriver inside @AfterMethod ?

This is need for me because I want to be able to run test methods in
parallel but still use webdriver in a thread safe manner.

Anybody can help me on that?


THX!

MaC

Cédric Beust ♔

unread,
Jan 22, 2012, 1:29:28 AM1/22/12
to testng...@googlegroups.com
Declare an ITestContext in your method and use setAttribute/getAttribute.


-- 
Cédric





MaC

--
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.


MaC

unread,
Feb 6, 2012, 11:09:51 AM2/6/12
to testng-users
Dear Cédric!








I have tried this, but this does not seem to be thread safe either :(




If I am having the same test-method running but in different threads,
they still seem to share the same ITestContext :(




The additional problem is that afterMethod runs in a different thread
so I cant even use the ThreadID to much stuff back together :(




THX 4 the support!




MaC

On 22 Jan., 07:29, Cédric Beust ♔ <ced...@beust.com> wrote:
> Declare an ITestContext in your method and use setAttribute/getAttribute.
>
> Doc here<http://testng.org/doc/documentation-main.html#native-dependency-injec...>
> .

charris

unread,
Feb 7, 2012, 2:00:27 PM2/7/12
to testng...@googlegroups.com
I also ran into this problem, ended up solving it by doing the following:

Also pass the method into everywhere you use the ITestContext.
Then instead of just setting an attribute of "webdriver" in the context, set method.getName()+"_webdriver"
Then, in your AfterMethod, get it back the same way.

This won't work if you use , invocationCount=5, threadPoolSize=5 though :(
Reply all
Reply to author
Forward
0 new messages