运行Selenium 2时,在Firefox中激活Firebug的最佳方式是什么?如何在Selenium WebDriver(Selenium 2)中运行Firebug?
编辑:好的,我意识到“最好”是可以解释的,但基于配置文件的解决方案真的用于硒1.0。所以任何替代方案都被认为更好,直到证明情况更糟;)
运行Selenium 2时,在Firefox中激活Firebug的最佳方式是什么?如何在Selenium WebDriver(Selenium 2)中运行Firebug?
编辑:好的,我意识到“最好”是可以解释的,但基于配置文件的解决方案真的用于硒1.0。所以任何替代方案都被认为更好,直到证明情况更糟;)
你可以在代码中创建您的配置文件并动态添加所需的加载项。假设您将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启动的浏览器实例中安装了firebug?如果是这样,您可以在实例化驱动程序通过一个扩展,但eaisest方法是创建安装萤火火狐配置文件,然后使用下面的代码实例化驱动程序之前:
System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");
这或多或少是它在1.0中完成的方式,当Firefox升级时它总是变得很麻烦。我真的很想通过扩展.... – krosenvold 2010-08-06 10:00:22
描述只是通过名称来引用您的个人资料。 Ruby中的示例:
@driver = Selenium::WebDriver.for :firefox, :profile => "default"
然后,正常加载Firefox并添加所需的扩展。他们现在将出现在您的Selenium测试运行中。
Selenium WebDriver显然改变了firefox-profile选项的使用方式。
旧的命令行(硒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
假设,Firebug是安装。你的目标是运行Firebug。按F12键可以运行/执行Firebug。所以,萤火虫可以通过硒的webdriver的下面的命令与Java运行:
Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();
修改Firefox的位置,像 C:\用户\用户名\ AppData \漫游\ Mozilla的\火狐\ Profiles文件\ sgmqi7hy。默认 从selenium/webdriver启动你的Firefox 使所有您需要的设置 关闭,并从硒/ webdriver重新启动Firefox浏览器 就是这样,它解决了您的问题!
我在〜/ .mozialla/firefox /中找到了一个profiles.ini文件。在那里有一个名为default的配置文件,我指定了一个类似于下面的配置文件,然后firefox在测试中打开,就像我经常打开它(使用所有插件等)。
java -jar selenium.jar -Dwebdriver.firefox.profile=default
如果以上选项均不起作用。然后试试这个。
火狐-p
5)现在通过selenium加载这个新的配置文件,使用下面的java 声明。
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile(“SELENIUM”);
WebDriver driver = new FirefoxDriver(ffprofile);
6)完成。请享用。
我观察到的萤火虫被添加到浏览器,它是默认禁用,未启用,当我使用webdriver的在运行时添加萤火到Firefox。所以为了使它启用,我们可能需要将下面的行添加到配置文件中。
profile.setEnableNativeEvents(true);
你的实例比常见问题好一些,谢谢! – krosenvold 2010-08-06 12:54:12
如果可以的话,这完全是真棒+100。使迁移到硒2本身值得它 – krosenvold 2010-08-06 16:26:02
有很多事情是Selenium2支付迁移的时间花费。就我个人而言,我发现页面对象模式非常方便,使得动态/ AJAX网络应用程序的测试更容易。所以我真的爱上了WebDriver :) – 2010-08-09 08:12:29