Selenium Grid,如何将WebDriver与ThreadSafeSeleniumSessionStorage.session()结合使用 [英] Selenium Grid, how to utilize WebDriver with ThreadSafeSeleniumSessionStorage.session()

查看:87
本文介绍了Selenium Grid,如何将WebDriver与ThreadSafeSeleniumSessionStorage.session()结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一个涉及大量使用Selenium WebDriver和特定Firefox Profile来查找元素和管理页面的项目.

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.

例如,
driver.findElement(By.xpath("//*[@id='foobar']"));

driver.manage().refresh();

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

我正在尝试在我的项目中实现Selenium Grid;但是,随着Selenium WebDriver的广泛使用,是否有一种方法可以使用特定的WebDriver启动ThreadSafeSeleniumSessionStorage.session()静态对象?

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?

据我研究,可以通过以下方式从Selenium对象获取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

推荐答案

我没有尝试过此代码,但是如果它可以工作,那么您将拥有一个对象,该对象包含基于Selenium的WebDriver.据我了解,此功能可用于从Selenium 1迁移到Selenium2.这不是使Web驱动程序线程安全的推荐方法.

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默认情况下不是线程安全的.我建议为每个线程实例化一个WebDriver实例.

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

这篇关于Selenium Grid,如何将WebDriver与ThreadSafeSeleniumSessionStorage.session()结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆