Reading the .har file created with browser mob proxy.

890 views
Skip to first unread message

Clayton Sheldon

unread,
May 7, 2015, 6:44:46 AM5/7/15
to browserm...@googlegroups.com
I need to be able to get the .har data from google chrome while running automated tests. I have managed to do this easily on Firefox but not Chrome.

I am able to create a .har file using the below code but when i try and read it using http://www.softwareishard.com/blog/har-viewer/  It wont let me. Looking at the file I think the right information might be there but the format is a mess. 

I have copied my code below and I have attached the .har file I am able to generate.

Any help would be much appreciated.

Thanks. 


from browsermobproxy import Server
server = Server("C:\\browsermob-proxy-2.0.0\\bin\\browsermob-proxy")
server.start()
proxy = server.create_proxy()

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy))
driver = webdriver.Chrome("c:\\webits\\chromedriver.exe", chrome_options = chrome_options)

proxy.new_har("google")
proxy.har # returns a HAR JSON blob

text_file = open('c:\\browsermob-proxy-2.0.0\\webpage.har', 'w')
text_file.write(str(proxy.har.values()))
text_file.close()

server.stop()
driver.quit()




webpage.har

Arie Hoenel

unread,
May 7, 2015, 8:54:03 AM5/7/15
to browserm...@googlegroups.com
I'm reading har file like this


import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.core.har.HarEntry;
import net.lightbody.bmp.core.har.HarLog;
Har harLog = getProxy().getHar();



        List<HarEntry> results = harLog.getLog().getEntries();

        for (HarEntry result : results) {
            if (result.getRequest().getUrl().contains("fictivious")) {
                for (int i = 0; i < result.getRequest().getQueryString().size(); i++) {
                    if (result.getRequest().getQueryString().get(i).getName().contentEquals("action")) {
                        System.out.println("action value: " + result.getRequest().getQueryString().get(i).getValue());
                       

--

---
You received this message because you are subscribed to the Google Groups "BrowserMob Proxy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to browsermob-pro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Clayton Sheldon

unread,
May 7, 2015, 9:28:39 AM5/7/15
to browserm...@googlegroups.com
Sorry, Should of said I need this in python.

Suraj Ray

unread,
May 11, 2015, 2:39:50 AM5/11/15
to browserm...@googlegroups.com
Hi Arie,

Are you forming any kind of UI report after reading the HAR files?

Regards,
Suraj

Arie Hoenel

unread,
May 11, 2015, 2:47:46 AM5/11/15
to browserm...@googlegroups.com
I'm checking a HTML5 video player that report actions to the network, so I'm going thru Har file to check that all is reported.
Reply all
Reply to author
Forward
0 new messages