0

I am trying to collect network traffic data, I have setup a proof of concept, prior to integrating this with our test framework. I can get the har data, and it is coming back as a dictionary, Not really sure what to do with it after that? I assume I need to write it to a file so it can be uploaded, but do I save it as a .har or a .json?

server = Server("C:\\Users\\E003048\\Downloads\\browsermob-proxy-2.0-beta-9\\bin\\browsermob-proxy.bat")
server.start()
proxy = server.create_proxy()

profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)

proxy.new_har("Network Traffic")
driver.get("http://URL GOES HERE")
har_information = proxy.har
target_file = open("har_file.har", 'a')
target_file.write(str(har_information))
sleep(10)
proxy.close()
server.stop()
driver.quit()

I added to my script where it writes the har file, however when I plug it into a har viewer: http://www.softwareishard.com/har/viewer/ I am not getting anything. What else needs to be done?

DarthOpto
  • 1,449
  • 5
  • 27
  • 52

2 Answers2

2

HAR stands for HTTP Archive. This is a common format for recording HTTP tracing information. This file contains a variety of information, but for our purposes, it has a record of each object being loaded by a browser. Each of these objects’ timings is recorded.

You can know more about HAR file specification here: http://www.softwareishard.com/blog/har-12-spec/

And this page below lists many HAR parsing and visualizing tools: http://www.softwareishard.com/blog/har-adopters/

1

Well, saved har file you can use to do next:

  1. You can perform load testing using already saved communication information in har file. E.g. you write test (loggin to site). Then save it to har file. After that you can repeat that action using some of the known frameworks as many times as you want. One of the known frameworks is BrowserMob-Proxy

  2. As the first one, performance testing =) using same framework. Steps almost same. Record your traffic information (e.g. login and wait untill page loaded) then save info to har. After that using another framework (e.g. YSLow it has and command line version) you can gather information about requests, time, size etc.

This is most known (for me) methods of how to use har file. Hope this will help.

Andrey Egorov
  • 1,213
  • 1
  • 12
  • 9