我正在使用 Ubuntu 11.04 和 selenium 2.9.0 以下是它在我的 root pom 中的配置方式:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
当尝试运行测试时,我遇到异常:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
*** LOG addons.xpi: startup
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: > /tmp/anonymous3804893394247066972webdriver-profile/extensions/webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:95)
....
据我谷歌搜索,问题是selenium使用的firefox驱动程序与浏览器版本不兼容。考虑到 Firefox 发布的频繁更新,维护我的本地测试环境将很困难。
因此,我决定安装一个静态的 Firefox 与我所知的最新兼容版本,并使用 selenium ,同时保留我的默认 Firefox (我不能删除它)。
所以,我不知道如何设置我的 selenium 配置以使其与静态 Firefox 一起工作。也许我必须配置我的应用程序以接收 firefox 二进制文件的路径以供驱动程序使用?我想知道是否还需要其他什么。
** Edit
我正在使用配置属性来初始化正确的网络驱动程序:
public abstract class SeleniumTestBase {
...
public final void setUp() throws Exception {
String driverClass = getConfigurationProperty("selenium.webDriverClass");
driver = (WebDriver) Class.forName(driverClass).newInstance();
...
doSetUp();
}
public void doSetUp() {
}
...
}
The "selenium.webDriverClass"
属性可由 pom.xml 管理,因此不同的配置文件可以具有不同的值。目前它是要实例化的驱动程序类的 FQN。
只要我知道java命令
WebDriver driver = new FirefoxDriver();
将在您的计算机上运行已安装的 Firefox 浏览器。
但阅读 JavaDochttp://selenium.googlecode.com/svn/trunk/docs/api/java/index.html我意识到可以有办法覆盖它:
FirefoxBinary binary = new FirefoxBinary(new File("path/to/binary"));
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(binary, profile);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)