Pass around own reference (multithreading)

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

Pass around own reference (multithreading)

MaC-41
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

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Pass around own reference (multithreading)

Cédric Beust ♔-2
Declare an ITestContext in your method and use setAttribute/getAttribute.


-- 
Cédric




On Thu, Jan 19, 2012 at 3:53 AM, MaC <[hidden email]> wrote:
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

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: Pass around own reference (multithreading)

MaC-41
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 ♔ <[hidden email]> wrote:

> Declare an ITestContext in your method and use setAttribute/getAttribute.
>
> Doc here<http://testng.org/doc/documentation-main.html#native-dependency-injec...>
> .
>
> --
> Cédric
>
>
>
>
>
>
>
> On Thu, Jan 19, 2012 at 3:53 AM, MaC <[hidden email]> wrote:
> > 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
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email].
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Pass around own reference (multithreading)

charris
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 :(

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/B3Cufp3O3N4J.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.