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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3421793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 23:10:30  来源:igfitidea点击:

How do I run Firebug within Selenium WebDriver (Selenium 2)?

javafirebugselenium-webdriver

提问by krosenvold

What's the best way to activate Firebug in Firefox when running Selenium 2?

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

Edit: Ok, I realize "best" is open to interpretation, but the profile-based solution really used to be a pain with selenium 1.0. So any alternative is considered better until proved worse ;)

编辑:好的,我意识到“最佳”可以解释,但基于配置文件的解决方案在使用 selenium 1.0 时确实很痛苦。因此,任何替代方案都被认为更好,直到证明更糟;)

采纳答案by Sergii Pozharov

You can create your profile in code and dynamically add required add-ons. Let's assume that you saved Firebug XPI into the C:\FF_Profile folder as firebug.xpi (go to Firebug download page, right-click on the "Add To Firefox" and save as C:\FF_Profile\firebug.xpi).

您可以在代码中创建您的配置文件并动态添加所需的附加组件。假设您将 Firebug XPI 作为 firebug.xpi 保存到 C:\FF_Profile 文件夹中(转到Firebug 下载页面,右键单击“添加到 Firefox”并另存为 C:\FF_Profile\firebug.xpi)。

In code:

在代码中:

   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);

This is described in WebDriver FAQ

这在WebDriver 常见问题解答中有所描述

回答by Bill

Do you mean having firebug installed in the browser instance that webdriver launches? If so, you can pass an extension when you instantiate the driver, but the eaisest way is to create a firefox profile with firebug installed and then use the following code before you instantiate the driver:

您的意思是在 webdriver 启动的浏览器实例中安装了 firebug 吗?如果是这样,您可以在实例化驱动程序时传递扩展名,但最简单的方法是创建一个安装了 firebug 的 firefox 配置文件,然后在实例化驱动程序之前使用以下代码:

System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");

System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");

回答by Aaron Fi

Just reference your profile by name. Example in Ruby:

只需按名称引用您的个人资料。Ruby 中的示例:

@driver = Selenium::WebDriver.for :firefox, :profile => "default"

Then, load Firefox normally, and add your desired extensions. They will now show up in your Selenium test runs.

然后,正常加载 Firefox,并添加您想要的扩展。它们现在将显示在您的 Selenium 测试运行中。

回答by bukzor

Apparently the way the firefox-profile options are consumed has changed in Selenium WebDriver.

显然,在 Selenium WebDriver 中使用 firefox-profile 选项的方式已经改变。

The old commandline (Selenium RC):

旧命令行(Selenium RC):

java -jar selenium-2.28.0.jar -firefoxProfileTemplate ~/.mozilla/firefox/3knu5vz0.selenium

Updated for WebDriver: (note that it wants the profile namerather than the directory)

为 WebDriver 更新:(注意它需要配置文件名称而不是目录)

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

回答by Ripon Al Wasim

Assuming that, Firebug is installed. Your objective is to run Firebug. Firebug can be run/execute by pressing F12 key. So Firebug can be run by following command of Selenium WebDriver with Java:

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

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

回答by Srichandar Karpuram

modify your firefox location to something like C:\Users\user-name\AppData\Roaming\Mozilla\Firefox\Profiles\sgmqi7hy.default launch your firefox from selenium / webdriver make all your required settings close and restart firefox browser from selenium / webdriver that's it, it solves your problem !!

将您的 firefox 位置修改为 C:\Users\user-name\AppData\Roaming\Mozilla\Firefox\Profiles\sgmqi7hy.default 从 selenium / webdriver 启动您的 firefox 关闭所有所需的设置并从 selenium / webdriver 重新启动 firefox 浏览器就是这样,它解决了你的问题!!

回答by rethab

I found a profiles.ini in ~/.mozialla/firefox/. In there was a profile named default, which I specified a like the following and then firefox was opened in test just like I opened it regularly (with all plugins etc).

我在 ~/.mozialla/firefox/ 中找到了一个profiles.ini。在有一个名为 default 的配置文件中,我指定了一个如下所示的配置文件,然后在测试中打开了 Firefox,就像我经常打开它一样(使用所有插件等)。

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

回答by Rohit Naik

If none of the above option works. Then try this.

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

  • 1) Open terminal and type below command (close all existing firefox sessions first)
  • 1)打开终端并输入以下命令(首先关闭所有现有的firefox会话)

firefox -p

火狐 -p

  • 2) This will open an option to create a new Firefox profile.
  • 3) Create a profile lets say "SELENIUM".
  • 4) Once the firefox is open straight away install firebug or any other plugins extension that you want. once done close the window.
  • 5) Now load this new profile via selenium , use below java statements.

    ProfilesIni profile = new ProfilesIni();

    FirefoxProfile ffprofile = profile.getProfile("SELENIUM");

    WebDriver driver = new FirefoxDriver(ffprofile);

  • 6) Done. Enjoy.

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

    ProfilesIni profile = new ProfilesIni();

    FirefoxProfile ffprofile = profile.getProfile("硒");

    WebDriver 驱动程序 = 新的 FirefoxDriver(ffprofile);

  • 6)完成。享受。

回答by Vittal Manikonda

I have observed that the firebug is adding to browser and it is disabled by default and not enabled ,when i add firebug to firefox at runtime by using webdriver. So to make it enable we may need to add the below line to profile.

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

profile.setEnableNativeEvents(true);