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

一笑奈何 提交于 2019-12-07 07:35:15

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13057423/selenium-grid-how-to-utilize-webdriver-with-threadsafeseleniumsessionstorage-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!