简体   繁体   中英

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

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

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

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

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

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:

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

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

The old commandline (Selenium RC):

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

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

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

Just reference your profile by name. Example in 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位置修改为C:\\ Users \\ user-name \\ AppData \\ Roaming \\ Mozilla \\ Firefox \\ Profiles \\ sgmqi7hy.default从selenium / webdriver启动你的firefox使所有你需要的设置关闭并从selenium / webdriver重新启动firefox浏览器就是这样,它解决了你的问题!!

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

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

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

  • 1) Open terminal and type below command (close all existing firefox sessions first)

firefox -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.

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.

profile.setEnableNativeEvents(true);

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM