Page Load time using Firebug and Selenium

Firebug is a well known tool for debugging and page load time.It provides detailed timing information about Http traffic initiated by the page. The NetĀ panelĀ which collects all the data can be used to export it into HAR file.

Prerequisites

  1. Firebug – a Firefox plugin
  2. NetExport – Firebug extension for exporting data collected by the Net panel.
  3. Selenium 2 – Selenium is a suite of tools specifically for automating web browsers.

The sample test is developed using Java language. You can use any other language supported by Selenium.

Steps

  1. Download and install Firebug and NetExport. Also, make sure that both the files are kept in the same folder.
  2. Download Selenium selenium-server-standalone-X.XX.X.jar.

Below is the sample code.

import java.io.*;
import java.lang.InterruptedException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class FirebugPerf {
public static void main(String[] args) {
FirefoxProfile profile = new FirefoxProfile();
File firebug = new File(“firebug-1.11.2-fx.xpi”);
File netExport = new File(“netExport-0.8.xpi”);
try
{
profile.addExtension(firebug);
profile.addExtension(netExport);
}
catch (IOException err)
{
System.out.println(err);
}
// Set default Firefox preferences
profile.setPreference(“app.update.enabled”, false);
String domain = “extensions.firebug.”;
// Set default Firebug preferences
profile.setPreference(domain + “currentVersion”, “2.0”);
profile.setPreference(domain + “allPagesActivation”, “on”);
profile.setPreference(domain + “defaultPanelName”, “net”);
profile.setPreference(domain + “net.enableSites”, true);
// Set default NetExport preferences
profile.setPreference(domain + “netexport.alwaysEnableAutoExport”, true);
profile.setPreference(domain + “netexport.showPreview”, false);
profile.setPreference(domain + “netexport.defaultLogDir”, “C:\\Firebug_Automation\\output\\”);
WebDriver driver = new FirefoxDriver(profile);

try
{
// Wait till Firebug is loaded
Thread.sleep(5000);

// Load test page
// You can add more scenarios and pages as required
driver.get(“http://google.com”);

// Wait till HAR is exported
Thread.sleep(60000);
}
catch (InterruptedException err)
{
System.out.println(err);
}

driver.quit();

}

}

Compile it and run it. You will get the .har file in output folder as defined in the preference.

profile.setPreference(domain + “netexport.defaultLogDir”, “C:\\Firebug_Automation\\output\\”);

Note: If you are using Selenium for functional automation you can modify above code and integrate it with your existing functional test.
Limitations

  1. This code is dependent on Firebug and hence will run only in FireFox
  2. The output is in .har file and to view this you need har file viewer.

For more info on this visit
http://www.softwareishard.com/blog/firebug/automate-page-load-performance-testing-with-firebug-and-selenium/

7 Replies to “Page Load time using Firebug and Selenium”

  1. How to get report of a Particular page…suppose I have to click few links then final target link and I want Page load time of this particular page only.

    1. I have not done this earlier but you could try the following.
      profile.setPreference(domain + “netexport.alwaysEnableAutoExport”, true);

      make this false and use netexport when you are at the specific page or enable after you reach at the specific page.

      1. Hi,

        Could you please help on this..

        Trying to change NetExport preferences after the page is loaded but not working. Below is the code iam using.

        import java.io.*;
        import java.util.concurrent.TimeUnit;
        import java.util.concurrent.*;
        import java.lang.InterruptedException;

        import org.openqa.selenium.By;
        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.WebElement;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import org.openqa.selenium.firefox.FirefoxProfile;
        import org.openqa.selenium.support.ui.Wait;
        import org.openqa.selenium.support.ui.WebDriverWait;

        public class Example_Logon{
        public static void main(String[] args) {

        FirefoxProfile profile = new FirefoxProfile();
        File firebug = new File(“firebug-1.12.0.xpi”);
        File netExport = new File(“netExport-0.9b6.xpi”);

        try
        {
        profile.addExtension(firebug);
        profile.addExtension(netExport);
        }
        catch (IOException err)
        {
        System.out.println(err);
        }

        // Set default Firefox preferences
        profile.setPreference(“app.update.enabled”, false);

        String domain = “extensions.firebug.”;

        // Set default Firebug preferences
        profile.setPreference(domain + “currentVersion”, “2.0”);
        profile.setPreference(domain + “allPagesActivation”, “on”);
        profile.setPreference(domain + “defaultPanelName”, “net”);
        profile.setPreference(domain + “net.enableSites”, true);

        /********************************************************************************************************* Set default NetExport preferences*********************/

        profile.setPreference(domain + “netexport.alwaysEnableAutoExport”, false);
        profile.setPreference(domain + “netexport.showPreview”, false);

        WebDriver driver = new FirefoxDriver(profile);

        try
        {
        // Wait till Firebug is loaded
        // Thread.sleep(5000);
        // Load test page
        driver.get(“https://www.gmail.com”);
        Thread.sleep(20000);

        WebElement element = driver.findElement(By.cssSelector(“input#USERNAME”));
        element.sendKeys(“Username”);

        WebElement pwd = driver.findElement(By.id(“PASSWORD”));
        pwd.sendKeys(“pwd123”);

        WebElement Signon = driver.findElement(By.cssSelector(“div.btn > input[type=\”image\”]”));
        Signon.click();

        profile.setPreference(domain + “netexport.defaultLogDir”, “C:\\Downloads\\Logon\\”);
        profile.setPreference(domain + “netexport.alwaysEnableAutoExport”, true);

        // Wait till HAR is exported
        Thread.sleep(20000);
        }
        catch (InterruptedException err)
        {
        System.out.println(err);
        }

        driver.quit();
        }
        }

          1. Thanks for your interest .. I am not getting any error.. It is getting executed but still the AutoExport option is not getting enabled and DefaultLogDir not getting updated.

  2. Hi, Thanks for the post. This really helpful but i have one issue i.e. I want to capture web analytics call from network traffic and with this code i am able to capture the network traffic but it does not capture the web analytics calls(Web Analytics calls arefired from some third party servers), how ever when i tried it manually i was able to see the calls under Images tab in firebug Net panel. can you please help me out on how to capture the network traffic calls which are being captured under images tab.

    Thanks!

Leave a Reply