如何使用Selenium FirefoxDriver启动多个Firefox Portable实例

本文关键字:Firefox Portable 实例 启动 何使用 Selenium FirefoxDriver | 更新日期: 2023-09-27 18:35:26

我在测试中使用Selenium FirefoxDriver,并并行运行这些测试 - 在每个线程中运行单独的Firefox实例。当我使用普通的 Firefox 时,一切正常,但是如果我想使用 Firefox 便携式运行这些测试,第一个实例启动成功,但第二个、第三个实例等......失败并显示此错误:

您的 Firefox 配置文件无法加载。它可能丢失或无法访问。

这就是我从代码启动 Firefox 的方式:

var profile = new FirefoxProfileManager().GetProfile("default");
var firefoxBinary = new FirefoxBinary("Path to FireFoxPortable.exe");
_driver = new FirefoxDriver(firefoxBinary, profile);

知道我做错了什么吗?谢谢。

如何使用Selenium FirefoxDriver启动多个Firefox Portable实例

Firefox 驱动程序正在尝试使用已在使用的配置文件启动 Firefox。这是不可能的,因为配置文件只能使用一次。之所以在多次手动启动 Firefox 时它似乎可以工作,是因为 Firefox 将使用已经加载的配置文件重用现有的正在运行的 Firefox 进程。

根据这些信息,您问题的解决方案是 1) 让 Firefox 驱动程序使用唯一/新的配置文件启动 Firefox,2) 更改您的代码,以便只需要一个 Firefox 驱动程序实例。

要使用多个实例启动 Firefox,请使用:firefox.exe -P "My Profile" -no-remote。不要将 -no-remote 参数与启动的第一个配置文件一起使用,在您的情况下,该配置文件将是"默认"配置文件。更多关于这方面的信息:http://kb.mozillazine.org/Opening_a_new_instance_of_Firefox_with_another_profile。

要使用不同的配置文件启动 Firefox Portable,如果上述命令不适用于 Firefox Portable,请按照此处的说明操作:http://portableapps.com/support/firefox_portable#second_profile。