26

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

Ripon Al Wasim
  • 34,088
  • 37
  • 146
  • 165
krosenvold
  • 70,511
  • 27
  • 141
  • 205

9 Answers9

47

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

Ripon Al Wasim
  • 34,088
  • 37
  • 146
  • 165
Sergii Pozharov
  • 15,845
  • 3
  • 26
  • 27
  • This is totally awesome +100 if I could. Makes migrating to selenium2 worth it by itself – krosenvold Aug 06 '10 at 16:26
  • There are many things is Selenium2 that payoff the time spend for migration. Personally I found that Page Objects pattern is very convenient and makes testing of dynamic/AJAX web apps much easier. So I am really in love with WebDriver :) – Sergii Pozharov Aug 09 '10 at 08:12
  • 5
    You also want to add `firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1")` (or whatever version you use) so that the FireBug startup screen is suppressed. – Gone Coding Mar 19 '12 at 14:45
  • 1
    When I ran the above code, another tab was opened containing the URL https://getfirebug.com/firstrun#Firebug%202.0.1 But I want to open Firebug Inspector in same browser window to get the data from Net section/tab – Ripon Al Wasim Aug 28 '15 at 12:32
10

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

Bill
  • 429
  • 2
  • 4
  • This is more or less the way it was done in 1.0 and it always turned out to be a hassle when firefox was upgraded. I'd really like to pass in the extension.... – krosenvold Aug 06 '10 at 10:00
1

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
bukzor
  • 34,859
  • 10
  • 67
  • 104
1

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.

Aaron Fi
  • 9,410
  • 13
  • 61
  • 90
0

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 !!

0

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
rethab
  • 3,547
  • 19
  • 36
0

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.

Rohit Naik
  • 19
  • 4
0

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

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();
Ripon Al Wasim
  • 34,088
  • 37
  • 146
  • 165