简体   繁体   English

如何配置selenium webdriver以使用自定义firefox设置进行测试?

[英]How can I configure selenium webdriver to use custom firefox setup for tests?

I am using Ubuntu 11.04 and selenium 2.9.0 Here is how it is configured in my root pom: 我正在使用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>

When attemting to run a test, I get an exception: 在准备运行测试时,我得到一个例外:

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)
    ....

As far as I have googled it, the issue is that the firefox driver that selenium uses is incompatible with the version of the browser. 据我搜索它,问题是selenium使用的firefox驱动程序与浏览器的版本不兼容。 Having in mind the frequent updates firefox releases, it will be difficult to maintain my local test environment. 考虑到firefox发布的频繁更新,维护我的本地测试环境将很困难。

Therefore, I have decided to install a static firefox with the latest known to me compatible version and to use selenium with it, while preserving my default firefox (I must not remove it). 因此,我决定安装一个静态firefox与我最新的兼容版本并使用selenium,同时保留我的默认firefox(我不能删除它)。

So, I am not sure how to setup my selenium configuration in order to make it work with the static firefox. 所以,我不知道如何设置我的selenium配置,以使其与静态Firefox一起使用。 Probably I must configure my app to receive the path to the firefox binary for the driver to use? 可能我必须配置我的应用程序以接收驱动程序使用的firefox二进制文件的路径? I'd like to know if anything else is also needed. 我想知道是否还需要其他东西。

** Edit **编辑

I am using configuration properties to initialize the proper webdriver: 我正在使用配置属性来初始化正确的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() {
    }

    ...
}

The "selenium.webDriverClass" property is manageable by the pom.xml therefore different profiles can have different value. "selenium.webDriverClass"属性可由pom.xml管理,因此不同的配置文件可以具有不同的值。 Currently it is the FQN of the driver class to be instantiated. 目前,它是要实例化的驱动程序类的FQN。

As long as I know that the java command 只要我知道java命令

WebDriver driver = new FirefoxDriver();

will run the installed Firefox browser on your computer. 将在您的计算机上运行已安装的Firefox浏览器。

but reading the JavaDoc at http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html I realised that there can be way how to override it: 但是在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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Selenium WebDriver 中使用断言? - How can I use assert in Selenium WebDriver? Selenium WebDriver(Java):如何嵌套这些NoSuchElement异常测试? - Selenium WebDriver (Java): How can I nest these NoSuchElement Exception tests? 如何禁用Selenium Webdriver和Firefox浏览器的ProPro浏览? - How can I disable provate browsing with selenium webdriver, and firefox browser? 如何在Selenium Webdriver 3中为Firefox驱动程序设置默认配置文件? - How can I set a default profile for the Firefox driver in Selenium Webdriver 3? 如何使用Selenium Webdriver取消在Firefox中的下载? - How can i cancel a download in firefox by using Selenium Webdriver? WebDriver Selenium 套件中的测试用于设置进一步的测试。 有什么方法可以让我的测试不那么依赖以前的“设置”测试? - Tests in WebDriver Selenium suite are used to setup further tests. Is there some way I can make my tests not so dependent on previous 'setup' tests? 当我在Firefox上运行测试时,Selenium WebDriver,UnreachableBrowserException - Selenium WebDriver, UnreachableBrowserException when I run tests on Firefox Selenium WebDriver + Java-如何为Firefox配置代理设置? - Selenium WebDriver + Java - How to configure proxy settings for Firefox? Selenium Webdriver如何启用Firefox插件? - How selenium webdriver can enable the Firefox addons? 如何使用 Java 设置 Selenium WebDriver? - How do I setup Selenium WebDriver with Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM