Selenium Grid, how to utilize WebDriver with ThreadSafeSeleniumSessionStorage.session()
Asked Answered
R

2

5

I am working on a project that involves using the Selenium WebDriver and a specific Firefox Profile heavily to find elements and manage the page.

For example,
driver.findElement(By.xpath("//*[@id='foobar']"));
and
driver.manage().refresh();

I am trying to implement Selenium Grid into my project; however, with the extensive use of Selenium WebDriver, is there a way to start the ThreadSafeSeleniumSessionStorage.session() static object with a specific WebDriver?

As far as I have researched, it is possible to get the WebDriver from the Selenium object by:

startSeleniumSession(seleniumHost, seleniumPort, browser, webSite); //Create and start the session() object
//TODO: insert a specific WebDriver into the session() object
WebDriver driver = ((WebDriverBackedSelenium) session()).getWrappedDriver(); //Get the WebDriver from the session() object
Racehorse answered 24/10, 2012 at 20:43 Comment(0)
M
2

I have not tried this code but if it works then you would have an object that holds Selenium based WebDriver. As per my understanding this feature is there for migration from Selenium 1 to Selenium 2. This is not the recommended way to make web driver thread safe.

WebDriver by default is not thread safe. I would recommend to instantiate one WebDriver instance for each thread.

Muddy answered 24/10, 2012 at 22:3 Comment(2)
Could you give a little insight on how to go about doing this?Racehorse
eg if you want to parallelize your testclasses, you can get one WebDriver per class...Pantisocracy
B
0

You can look into the implementation of ThreadSafeSeleniumSessionStorage class and use the same logic to create a new ThreadSafeWebdriverSessionStorage. Can't you? Source is here

It uses the ThreadLocal class. Shouldn't be difficult to implement.

Beano answered 25/10, 2012 at 14:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.