如何配置selenium webdriver以使用自定义firefox设置进行测试?
我正在使用Ubuntu 11.04和selenium 2.9.0以下是我在root pom中的配置方式:
org.seleniumhq.selenium selenium-java 2.9.0 test
在准备运行测试时,我得到一个例外:
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二进制文件的路径? 我想知道是否还需要其他东西。
**编辑
我正在使用配置属性来初始化正确的webdriver:
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() { } ... }
"selenium.webDriverClass"
属性可由pom.xml管理,因此不同的配置文件可以具有不同的值。 目前,它是要实例化的驱动程序类的FQN。
只要我知道java命令
WebDriver driver = new FirefoxDriver();
将在您的计算机上运行已安装的Firefox浏览器。
但是在http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html上阅读JavaDoc我意识到可以有办法覆盖它:
FirefoxBinary binary = new FirefoxBinary(new File("path/to/binary")); FirefoxProfile profile = new FirefoxProfile(); WebDriver driver = new FirefoxDriver(binary, profile);
- Spring Error – java.lang.NoSuchMethodError:> org.springframework.beans.factory.annotation.InjectionMetadata。
- Java Oracleexception – “列表中的最大表达式数为1000”
- 从整数数组中删除重复项
- java swing关闭窗口没有退出应用程序
- 用于从运行JVM收集统计信息的API
- 从java中的方法返回不同类型的数据?
- 如何在JTextField中删除文本?
- 在一次调用中将ArrayList.toString()转换回ArrayList
- 调用unmocked方法时抛出RuntimeException