BrowserMob – Proxy for WebPage Load Testing using Selenium
How do you catch performance issues before they reach production?
The solution for such an issue is to repurposing a Selenium script, we can run it through a proxy server and capture the HTTP traffic. With this traffic, we can run some simple checks to see if the application's performance has degraded.
Browsermob Proxy is a useful tool which is closely integrated with Selenium and can be work independently. It is used to capture performance data for webApps. It is used to manage browser behaviors and traffic in HAR (HTTP Archive format) such as blacklist and white-listing of the content, simulating network traffic and latency, and rewriting HTTP requests and responses. Web Performance data can be manually captured by other tools like Firebug or Developers Tools. Using BrowserMob Proxy we can capture performance data in HAR format while running automated tests.
How to use Browsermob Proxy?
1. Download Browsermob Proxy
2. Start Browsermob Proxy
3. Create a new Project and import Browsermob Proxy with Selenium Standalone server Jar
4. Run the script.
5. After running the script, you will see the proxy server is started and respective logs are generated.
6. As the script completed, an HTTP achieve file is also generated with Performance log of the desired web Apps.
7. Now you can import that HAR file and see the results at https://pcapperf.appspot.com/. It will show collected Performance data of that web Apps.
For implementing Browsermob, we have to manage few software:-
? Selenium-web driver
? Browsermob proxy zip file https://opensource.webmetrics.com/browsermob-proxy/
? Mozilla Firefox version supported by Selenium
How to use BrowserMob Proxy using Selenium Web-driver
Manually:-
//From browsermobproxy import Server
server = Server("path/to/browsermob-proxy")
server.start()
proxy = server.create_proxy()
//From selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har("google")
driver.get("https://www.google.co.uk")
proxy.har (# returns a HAR File)
server.stop()
driver.quit()
create_proxy() : Gets a client class that allow to set all the proxy details that you may need to.
Server.start() : This will start the browsermob proxy and then wait until it can interact with it
url : Gets the url that the proxy is running on. This is not the URL clients should connect to.
Server.stop() : This will stop the process running the proxy
What is HAR Format?
HAR stands for HTTP Archive is an online tool visualizing which helps us to collect performance data.
HAR is produced by the HTTP tracking tools, these files captures the details of the client/server
communication and this can be used for analysis like Page Load Performance.
How HAR files looks like?
Fig: HAR Format Data
Advantages:-
? Load the browser
? Capture all requests through the proxy server
? Save the captured requests to a HTTP Archive (HAR) file on disk
? Run the HAR file through YSlow to get a numeric grade
? Assert that the grade is above a certain level
Senior Automation Engineer @Blackberry
8 å¹´Great.