Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 593
Douglas Schuster Avatar asked Nov 04 '22 13:11

Douglas Schuster


1 Answers

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.

like image 134
haroonzone Avatar answered Nov 12 '22 17:11

haroonzone