如何在Selenium WebDriver(Selenium 2)中运行Firebug?

在运行Selenium 2时,在Firefox中激活Firebug的最佳方法是什么?

编辑:好的,我意识到“最佳”是开放的解释,但基于配置文件的解决方案真的曾经是selenium 1.0的痛苦。 所以任何替代方案都被认为更好,直到certificate更糟;

您可以在代码中创建配置文件并动态添加所需的附加组件。 假设您将Firebug XPI作为firebug.xpi保存到C:\ FF_Profile文件夹中(转到Firebug下载页面 ,右键单击“添加到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中有所描述

你的意思是在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进行了更新:(请注意,它需要配置文件名称而不是目录)

 java -jar selenium-2.28.0.jar -Dwebdriver.firefox.profile=selenium 

将你的firefox位置修改为C:\ Users \ user-name \ 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 

如果以上选项都不起作用。 然后尝试这个。

  • 1)打开终端并输入以下命令(首先关闭所有现有的firefox会话)

firefox -p

  • 2)这将打开一个创建新Firefox配置文件的选项。
  • 3)创建一个配置文件,让我们说“SELENIUM”。
  • 4)一旦firefox立即打开,安装firebug或任何其他你想要的插件扩展。 一旦完成关闭窗口。
  • 5)现在通过selenium加载这个新的配置文件,使用下面的java语句。

    ProfilesIni profile = new ProfilesIni();

    FirefoxProfile ffprofile = profile.getProfile(“SELENIUM”);

    WebDriver driver = new FirefoxDriver(ffprofile);

  • 6)完成。 请享用。

我观察到firebug正在添加到浏览器中,默认情况下禁用它并且未启用,当我在运行时使用webdriver将firebug添加到firefox时。 因此,要使其启用,我们可能需要将以下行添加到配置文件中。

 profile.setEnableNativeEvents(true); 

假设已经安装了Firebug。 你的目标是运行Firebug。 按F12键可以运行/执行Firebug。 所以Firebug可以通过以下命令运行Selenium WebDriver和Java来运行:

 Actions action = new Actions(driver); action.sendKeys(Keys.F12).build().perform();