0.0
No commit activity in last 3 years
No release in over 3 years
This Rubygem is CLI interface to check network traffic using HAR. It will generate HAR file preview in browser and YAML
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 2.4.0, ~> 2.3
~> 1.0
>= 2.6.2, ~> 2.1
>= 2.4.3, ~> 2.0
~> 1.5.1
~> 10.0
>= 0
~> 0.17.0
 Project Readme

BrowserMob CLI

BrowserMob CLI os Rubygem to generate HAR files from command line. This will preview HAR files in the Browser as well as parse it in YAML. It works well for FirefoxDriver and ChromeDriver/GhostDriver are WIP.

If you are new to HAR(HTTP Archive) & BrowserMob Proxy then please read these couple of links

HAR file can be used for

  • Calculate Load time.
  • Set/Get HTTP Headers during your tests
  • Capture performance data with HAR files.
  • Simulate network traffic and latency
  • Rewrite HTTP requests and response

##BrowserMob CLI can do following things:

  • Download Browsermobproxy programatically and save it in /tmp

  • Genarate and Preview Har file from command line by passing URL

  • Genarate and Preview Har file from command line by passing URL and adding user actions

  • List out request urls

Installation

Before we start, please make sure you got following packages installed

  • wget

  • Java version > 1.7 and JAVA_HOME set in .bashrc or .zshrc. This is important otherwise browsermob proxy server won't start. OSX Mac user can set it using

                export JAVA_HOME=$(/usr/libexec/java_home)
    
  • Ruby > 1.9.3

  • Bundler

  • Install Har gem

        $ gem install har
    

Add this line to your application's Gemfile:

gem 'browsermob-cli'

And then execute:

$ bundle

Or install it yourself as:

$ gem install browsermob-cli

Usage

Download BrowserMob Proxy

Assuming that you don't have BrowserMob Proxy downloaded, then first thing we probaly need to download it and save it to your /tmp directory (Assuming /tmp has write access). Just run following command.

    $ browsermob-cli setup

Now, you should have browsermob-proxy binary downloaded in the /tmp directory itself.

If that does't work, feel free to manually download BrowserMob proxy from official website Or from Github. Save it to /tmp/browsermob-proxy

Generate HAR file for any URL

We can generate HAR data for any url e.g (AOL website) by running

     $ browsermob-cli show_har http://www.aol.co.uk

After running this command, you should see following

  • Firefox Opened up with AOL homepage within BrowserMob proxy
  • All request URLS printed on console
  • HAR file saved to /tmp/traffic.har
  • HAR data parsed in YAML format and saved to /tmp/traffic.yml
  • WEBrick server starts and open up HAR data to preview

Generate HAR file for any URL when user clicks on the page

We can generate HAR data for any url e.g (BBC website) and passing CSS Selector where you want to click

     $ browsermob-cli show_har_click http://www.bbc.co.uk/blogs --locator ".rsp-img"

After running this command, you should see following

  • Firefox Opened up with BBC blog homepage within BrowserMob proxy and clicked on image
  • All request URLS printed on console
  • HAR file saved to /tmp/traffic.har
  • HAR data parsed in YAML format and saved to /tmp/traffic.yml
  • WEBrick server starts and open up HAR data to preview

View YAML File Or Preview in Browser

You can view generated YAML file with HAR data.

    $ browsermob-cli view_har_in_YAML
    $ browsermob-cli view_har_in_browser

Usage command

    $ browsermob-cli
    Commands:
     browsermob-cli help [COMMAND]       # Describe available commands or one specific command
     browsermob-cli setup                # Get Browsermob Proxy from Internet
     browsermob-cli show_har URL         # Get list of all requests
     browsermob-cli show_har_click URL   # Get list of all requests when clicked on Locator
     browsermob-cli version              # Get the current version number
     browsermob-cli view_har_in_YAML     # Display HAR file in YML in your Editor
     browsermob-cli view_har_in_browser  # Open up browser and Preview HAR file. Press Ctl+C Once DONE...

Common issues

  • Server won't start Issue: Error message

          unable to launch the server (rerun with :log => true to see process output) (BrowserMob::Proxy::Server::ServerDiedError)
    

There may be few reason.

1] It uses port 7676. It may be in use. Clear the port by running following command

       $ kill -9 $(lsof -i tcp:3000 -t)

It works for Mac OSX.

2] Java version is below 1.7. Update your JAVA version.

3] Make sure $JAVA_HOME set correctly, for mac, it’s “export JAVA_HOME=$(/usr/libexec/java_home)”.