【问题标题】:How do I run Firebug within Selenium WebDriver (Selenium 2)?如何在 Selenium WebDriver (Selenium 2) 中运行 Firebug?
【发布时间】:2016-04-23 15:38:31
【问题描述】:

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

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

【问题讨论】:

    标签: java firebug selenium-webdriver


    【解决方案1】:

    您可以在代码中创建您的个人资料并动态添加所需的插件。假设您将 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中有描述

    【讨论】:

    • 如果可以的话,这真是太棒了+100。使迁移到 selenium2 本身值得
    • Selenium2 有很多东西可以抵消迁移所花费的时间。就我个人而言,我发现 Page Objects 模式非常方便,并且使动态/AJAX Web 应用程序的测试变得更加容易。所以我真的爱上了 WebDriver :)
    • 您还想添加firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1")(或您使用的任何版本),以便抑制 FireBug 启动屏幕。
    • 当我运行上面的代码时,打开了另一个标签,其中包含 URL getfirebug.com/firstrun#Firebug%202.0.1 但我想在同一个浏览器窗口中打开 Firebug Inspector 以从 Net 部分/标签中获取数据
    【解决方案2】:

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

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

    【讨论】:

    • 这或多或少是在 1.0 中完成的,当 Firefox 升级时它总是很麻烦。我真的很想通过扩展......
    【解决方案3】:

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

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

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

    【讨论】:

      【解决方案4】:

      显然,在 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
      

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          【解决方案6】:

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

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

          【讨论】:

            【解决方案7】:

            如果上述选项均无效。然后试试这个。

            • 1) 打开终端并输入以下命令(关闭所有现有的 firefox 会议第一)

            火狐-p

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

              ProfilesIni 配置文件 = 新 ProfilesIni();

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

              WebDriver 驱动 = 新的 FirefoxDriver(ffprofile);

            • 6) 完成。享受吧。

            【讨论】:

              【解决方案8】:

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

              profile.setEnableNativeEvents(true);
              

              【讨论】:

                【解决方案9】:

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

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

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 2017-01-11
                  • 1970-01-01
                  • 2018-10-25
                  • 1970-01-01
                  • 2018-01-21
                  • 2012-03-30
                  • 2017-06-03
                  相关资源
                  最近更新 更多