Wednesday, July 3, 2013

How to add FireBug extension in FireFox profile.

No need to explain how convinient and useful to have FireBug extension in a browser if you work with tools like Selenium WebDriver. Firebug is a powerfull extension that allows us inspect elements and their properties, find element's Xpath.
Let’s see how to add firebug extension in FireFoxProfile for debugging selenium tests in runtime.

First of all let's download firebug extenson
Depending on what version of FireFox browser you use - need to download equivalent firebug version
Open page
https://getfirebug.com/downloads/

There will be information about firefox versions and equivalent firebug versions

select firebug version

In the bottom of the page, click on thedownloads directory link

download_dirs

I use Firefox 18 so I will download firebug 1.10.6.xpi
But before to download file, create new folder in your project. I will name it “conf
In this folder we will save our extension file firebug-1.10.6.xpi
Now right click on extension file and select “Save link as” and specify the path to <YOUR_PROJECT>/conf folder

Save firebug extension as

.xpi file will appears in your project tree in conf dir

extension in a project tree

Now we have to add your extension in FireFoxProfile object and put this object into FirefoxDriver() constructor.

[code lang="java"]
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;

public class AddFireBugInFireFoxProfile {

@Test
public void startBrowserWithProfile(){
FirefoxDriver firefoxDriver = new FirefoxDriver(getFireFoxProfile());
firefoxDriver.navigate().to("http://amazon.com");
firefoxDriver.close();
}

private FirefoxProfile getFireFoxProfile(){
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("network.proxy.type", 4);
firefoxProfile.setPreference("browser.startup.homepage", "about:blank");
firefoxProfile.setPreference("privacy.popups.showBrowserMessage", false);
firefoxProfile.setPreference("network.cookie.prefsMigrated", true);
firefoxProfile.setPreference("network.cookie.lifetimePolicy", 3);
firefoxProfile.setPreference("network.cookie.lifetime.days", 30);
firefoxProfile.setPreference("app.update.enabled", false);
firefoxProfile.setPreference("app.update.auto", false);

try {
firefoxProfile.addExtension(new File(".//conf//firebug-1.10.6.xpi"));
}catch (IOException e) {
e.printStackTrace();
}
return firefoxProfile;
}
}
[/code]

In line 13 we created method which return FireFoxProfile object, more detailed explanation about this you can
find in the article Creating firefox profile for selenium tests

[code lang="java" firstline="28"]
try {
firefoxProfile.addExtension(new File(".//conf//firebug-1.10.6.xpi"));
}catch (IOException e) {
e.printStackTrace();
}
return firefoxProfile;
}</pre>
<div>[/code]

In line 29 we created new File object and set the path to our extension file ".//conf//firebug-1.10.6.xpi" as argument constructor. Then we set this file to the method addExtension();

When you run your test firefox browser will contain firebug icon
firebug icon

No comments:

Post a Comment