17

Selenium WebDriver(又名 Selenium 2)在哪里获取它在打开 FirefoxDriver 时使用的匿名配置文件?如果它使用 Firefox 的默认值,%appdata%/roaming/mozilla/firefox/profiles,那么如果我要禁用一个 firefox 插件,它也应该为 Selenium WebDriver 禁用,那为什么不呢?

4

4 回答 4

21

我会回答它,支持来自@twall 的评论:在 Selenium 2 WebDriver 中启动 firefox 时,它会启动新的匿名配置文件。

但是,如果您想更改它,您可以创建新的 Firefox 配置文件并以某种方式命名它,您知道它是什么 - 例如SELENIUM

然后在您的代码中执行以下操作:

 ProfilesIni profile = new ProfilesIni();
 FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
 WebDriver driver = new FirefoxDriver(ffprofile);

这样,Firefox 将始终启动该配置文件。在配置文件中,您进行所需的所有设置

于 2012-08-20T07:33:09.317 回答
5

您可以为每个 Selenium 网格 2 节点分配一个特定的 firefox 配置文件:

java -jar selenium-server-standalone-2.37.0.jar -Dwebdriver.firefox.profile =my-profile -role node -hub http://example-server.org:4444/grid/register

请注意, webdriver.firefox.profile 的值必须是firefox 配置文件名称,而不是位置或文件夹名称

于 2013-11-21T13:31:35.763 回答
2

当在测试服务器上运行 webdriver 而没有在机器上创建配置文件的选项时,您可以通过编程方式创建配置文件:

private FirefoxProfile GetFirefoxProfile()
{
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "http://localhost");
    return firefoxProfile;
}
于 2014-07-30T07:51:45.180 回答
1

获取配置文件没有用,因为它在内部创建了获取的命名配置文件的另一个副本。在以下情况下需要访问原始配置文件:测试覆盖率数据应跨多个调用写入数据存储。

这是通过覆盖 Selenium 的 ProfilesIni 类的可能解决方案

首先使用 firefox -p 创建自定义配置文件,例如“CustomSeleniumProfile”

ProfilesIni profileini = new ProfilesIni() {
    @Override
    public FirefoxProfile getProfile(String profileName) {
            File appData = locateAppDataDirectory(Platform.getCurrent());
            Map<String, File> profiles = readProfiles(appData);
            File profileDir = profiles.get(profileName);
            if (profileDir == null)
              return null;
            return new FirefoxProfile(profileDir);
     }
};
FirefoxProfile profile = profileini.getProfile("CustomSeleniumProfile");
//profile.setEnableNativeEvents(false);

driver = new FirefoxDriver(profile);
//ffDriver.manage().deleteAllCookies();
driver.get("http://www.google.com");
于 2015-03-04T03:09:27.527 回答