30
Dec

Capture request response statistics for site performance

browsermob-proxy is a HTTPArchive tool which allows to capture site statistics while performing Performance / automated tests from a client.  It acts as an interface which collects HTTP Matrices.

Steps to collect client wise metrices:

Step 1.  download the browsermob-proxy from here

Steps 2. unzip and execute browsermob-proxy.bat file (from bin directory) for standalone analysis of http metrices

If the HTTP Metrices needs to be captured during automation run, we can write a simple “Request emulator” which interfaces via browsermob-proxy as follow:

 

import java.io.FileOutputStream;
import org.browsermob.core.har.Har;
import org.browsermob.proxy.ProxyServer;
import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class AutomatedPerfTest {

public static void main(String[] args) throws Exception {

String strFilePath = “”;

// start the proxy
ProxyServer server = new ProxyServer(4444);
server.start();
//captures the moouse movements and navigations
server.setCaptureHeaders(true);
server.setCaptureContent(true);

// get the Selenium proxy object
Proxy proxy = server.seleniumProxy();

// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);

// start the browser up
WebDriver driver = new FirefoxDriver(capabilities);

// create a new HAR with the label “domain.com”
server.newHar(“domain.com”);

// open yahoo.com
driver.get(“http://domain.com”);

driver.get(“http://domain.com/login.html”);

// get the HAR data
Har har = server.getHar();
FileOutputStream fos = new FileOutputStream(strFilePath);
har.writeTo(fos);
server.stop();
driver.quit();

}

}


On running above code, you can see HARFiles folder (under project hierarchy) with .har file

Step 3:  In order to view HTTP Metrices online tool like here can be used.

 


net.lightbody.bmp
browsermob-core
2.1.4
test