declaration of Webdriver object(variable)

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

declaration of Webdriver object(variable)

illusion0reality
I have seen Webdriver driver with - Protected.

If I declare outside of method (within the class) - Public static Webdriver driver - Will this be advantage or problematic.

I still have to test this. Just a thought.

As it is static, only one webdriver object will be created when driver = new FireFoxDriver();
Please let me know
Reply | Threaded
Open this post in threaded view
|

Re: declaration of Webdriver object(variable)

softwaretestingforum
Administrator
This is going to be real PITA if you use -

Public static Webdriver driver

Problem is the word "static" For the obvious reasons you already mentioned.
If you run your tests in parallel using testng and have two different tests each instantiating firefox and ie then
the one which instantiates after is going to change the state of first instantiation of driver object.

like this -

first driver object of FF driver is created
now same driver object becomes the ie driver (since it is marked as static hence it can have only one value)

Now old ff driver which has become ie driver tries to run your tests in FF browser and gives up.
So you could safely use -

protected Webdriver driver

and parallel execution of test will not have such issues.
 
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: declaration of Webdriver object(variable)

Illusion0Reality
Thanks for the replay.

Yes, you are correct.

I thought if I use Grid sort of functionality, I would get problem - as you said, the same object will be interacted with. And numerous problems I will see.

As long as it is just 1 machine and 1 browser, there won't be any problem. Am I correct.
Reply | Threaded
Open this post in threaded view
|

Re: declaration of Webdriver object(variable)

softwaretestingforum
Administrator
Exactly, one machine -  one browser will work but not the parallel execution.
~ seleniumtests.com