Non Static driver and screenshot listener in TestNG

134 views
Skip to first unread message

talon

unread,
Jul 11, 2013, 8:26:09 PM7/11/13
to testng...@googlegroups.com
Hi,

I have a testcase that will invoke the driver as a non static variable. I also have added screenshot listener in my test case. When the test case fails The control is automatically sent to the screenshot listener.. however since my driver is a NON-STATIC variable it could not be accessed in the screenshot listener. So I get nullpointer exception.

Is there a way to globally access the non-static driver in the screenshot listener?

Pls help. Thanks!

Krishnan Mahadevan

unread,
Jul 11, 2013, 10:29:20 PM7/11/13
to testng...@googlegroups.com
Maybe you should take a look at ThreadLocal 
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


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

Praveen Bhasker

unread,
Jul 11, 2013, 10:39:21 PM7/11/13
to testng...@googlegroups.com
Hi Krishnan,

I consider all your solutions in the forum as extremely useful one. If you have any implemented code I kindly request you to pls share it. I did some googling and read something about ThreadLocal. but couldn't figure out much. Pls help me. Thanks a lot!

Thanks,
Praveen


You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/NFZAmNnsSP4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.

Krishnan Mahadevan

unread,
Jul 11, 2013, 11:00:52 PM7/11/13
to testng...@googlegroups.com

Praveen Bhasker

unread,
Jul 11, 2013, 11:28:02 PM7/11/13
to testng...@googlegroups.com
Thanks Krishnan. 

Until today I was having the driver variable as a static one so the screenshot listener worked perfectly during a failure. From today we wanted to implement parallel test execution and I faced problem due to the static driver variable. So when I made the driver as non-static screenshot listener got messed up.

So do you think implementing ThreadLocal will help me resolve both the aforementioned conditions?

Thanks,
Praveen

Krishnan Mahadevan

unread,
Jul 11, 2013, 11:50:27 PM7/11/13
to testng...@googlegroups.com
Yes it would. ThreadLocal gurantees that every thread would get its own copy of an object and there are no race conditions. 

Initialising the ThreadLocal variable can be done in beforeInvocation()

Praveen Bhasker

unread,
Jul 12, 2013, 12:23:22 AM7/12/13
to testng...@googlegroups.com
Awesome. Like always you helped me :)
Reply all
Reply to author
Forward
0 new messages