【发布时间】:2016-04-23 15:38:31
【问题描述】:
在运行 Selenium 2 时,在 Firefox 中激活 Firebug 的最佳方法是什么?
编辑:好的,我意识到“最佳”是可以解释的,但是基于配置文件的解决方案在 selenium 1.0 中确实很痛苦。因此,在被证明更糟之前,任何替代方案都被认为是更好的;)
【问题讨论】:
标签: java firebug selenium-webdriver
在运行 Selenium 2 时,在 Firefox 中激活 Firebug 的最佳方法是什么?
编辑:好的,我意识到“最佳”是可以解释的,但是基于配置文件的解决方案在 selenium 1.0 中确实很痛苦。因此,在被证明更糟之前,任何替代方案都被认为是更好的;)
【问题讨论】:
标签: java firebug selenium-webdriver
您可以在代码中创建您的个人资料并动态添加所需的插件。假设您将 Firebug XPI 作为 firebug.xpi 保存到 C:\FF_Profile 文件夹中(转到 Firebug download page,右键单击“添加到 Firefox”并另存为 C:\FF_Profile\firebug.xpi)。
在代码中:
final String firebugPath = "C:\\FF_Profile\\firebug.xpi";
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(firebugPath));
// Add more if needed
WebDriver driver = new FirefoxDriver(profile);
这在WebDriver FAQ中有描述
【讨论】:
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1")(或您使用的任何版本),以便抑制 FireBug 启动屏幕。
您的意思是在 webdriver 启动的浏览器实例中安装了 firebug 吗?如果是这样,您可以在实例化驱动程序时传递扩展名,但最简单的方法是创建一个安装了 firebug 的 firefox 配置文件,然后在实例化驱动程序之前使用以下代码:
System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");
【讨论】:
只需按名称引用您的个人资料。 Ruby 中的示例:
@driver = Selenium::WebDriver.for :firefox, :profile => "default"
然后,正常加载 Firefox,并添加所需的扩展。它们现在将显示在您的 Selenium 测试运行中。
【讨论】:
显然,在 Selenium WebDriver 中使用 firefox-profile 选项的方式发生了变化。
旧的命令行(Selenium RC):
java -jar selenium-2.28.0.jar -firefoxProfileTemplate ~/.mozilla/firefox/3knu5vz0.selenium
为 WebDriver 更新:(注意它需要配置文件 name 而不是目录)
java -jar selenium-2.28.0.jar -Dwebdriver.firefox.profile=selenium
【讨论】:
将您的 Firefox 位置修改为类似 C:\Users\用户名\AppData\Roaming\Mozilla\Firefox\Profiles\sgmqi7hy.default 从 selenium / webdriver 启动你的 Firefox 进行所有需要的设置 从 selenium / webdriver 关闭并重新启动 firefox 浏览器 就是这样,它解决了你的问题!
【讨论】:
我在 ~/.mozialla/firefox/ 中找到了一个profiles.ini。里面有一个名为 default 的配置文件,我指定了一个如下所示的配置文件,然后在测试中打开了 firefox,就像我定期打开它一样(使用所有插件等)。
java -jar selenium.jar -Dwebdriver.firefox.profile=default
【讨论】:
如果上述选项均无效。然后试试这个。
火狐-p
5) 现在通过 selenium 加载这个新配置文件,在 java 下面使用 声明。
ProfilesIni 配置文件 = 新 ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver 驱动 = 新的 FirefoxDriver(ffprofile);
6) 完成。享受吧。
【讨论】:
我观察到 firebug 正在添加到浏览器中,默认情况下它被禁用并且未启用,当我在运行时使用 webdriver 将 firebug 添加到 firefox 时。因此,要启用它,我们可能需要在配置文件中添加以下行。
profile.setEnableNativeEvents(true);
【讨论】:
假设已安装 Firebug。您的目标是运行 Firebug。 Firebug 可以通过按 F12 键运行/执行。所以 Firebug 可以通过 Selenium WebDriver with Java 的以下命令运行:
Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();
【讨论】: