Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when tried to get the page load time #13

Closed
pr4bh4sh opened this issue Mar 28, 2016 · 7 comments
Closed

Error when tried to get the page load time #13

pr4bh4sh opened this issue Mar 28, 2016 · 7 comments

Comments

@pr4bh4sh
Copy link

Source code

import json

from browsermobproxy import Server
from haralyzer import MultiHarParser

server = Server(
    "/home/gblp090/Downloads/browsermob-proxy-2.1.0-beta-5/bin/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("http://www.google.com")
result = json.dumps(proxy.har, ensure_ascii=False)
file = open('CHARLIE_HAR.har', 'w+')
file.write(result)
file.close()
driver.quit()
# print result
test_runs = []
with open('CHARLIE_HAR.har', 'r') as f1:
    test_runs.append((json.loads(f1.read())))
multi_har_parser = MultiHarParser(har_data=test_runs)
print multi_har_parser.page_load_time
server.stop()

error

Traceback (most recent call last):
  File "tests/dummy_test.py", line 29, in <module>
    print multi_har_parser.page_load_time
  File "/home/gblp090/automation/CFMobileAutomation/env/local/lib/python2.7/site-packages/cached_property.py", line 26, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/home/gblp090/automation/CFMobileAutomation/env/local/lib/python2.7/site-packages/haralyzer/multihar.py", line 141, in page_load_time
    load_times = self.get_load_times('page')
  File "/home/gblp090/automation/CFMobileAutomation/env/local/lib/python2.7/site-packages/haralyzer/multihar.py", line 76, in get_load_times
    val = getattr(har_page, search_str, None)
  File "/home/gblp090/automation/CFMobileAutomation/env/local/lib/python2.7/site-packages/cached_property.py", line 26, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/home/gblp090/automation/CFMobileAutomation/env/local/lib/python2.7/site-packages/haralyzer/assets.py", line 460, in page_load_time
    return self._get_asset_load('page')
  File "/home/gblp090/automation/CFMobileAutomation/env/local/lib/python2.7/site-packages/haralyzer/assets.py", line 239, in _get_asset_load
    return self.pageTimings['onLoad']
KeyError: 'onLoad'

pip list

apipkg (1.4)
Appium-Python-Client (0.22)
backports.statistics (0.1.0)
browsermob-proxy (0.7.1)
cached-property (1.3.0)
execnet (1.4.1)
haralyzer (1.4.5)
pip (8.1.1)
py (1.4.31)
pytest (2.9.1)
pytest-html (1.8.0)
pytest-rerunfailures (1.0.1)
pytest-timeout (1.0.0)
pytest-xdist (1.14)
python-dateutil (2.5.2)
requests (2.9.1)
selenium (2.53.1)
setuptools (18.0.1)
six (1.10.0)
wheel (0.24.0)

If I try to get any other load time it prints "0.0"
Har gist
If i paste the content of har file at http://www.softwareishard.com/har/viewer/ It shows the load time is it possible to do the same with this library.

@mrname
Copy link
Collaborator

mrname commented Mar 28, 2016

It looks like the overall page timings in your HAR file are empty for some reason:

pages: [
{
pageTimings: {
comment: ""
},
comment: "",
title: "google",
id: "google",
startedDateTime: "2016-03-28T18:27:38.940+05:30"
}
],

I will look into a fallback for you, and see if I can get any info on how to make a HAR file with the pageTimings entries.

@mrname
Copy link
Collaborator

mrname commented Mar 30, 2016

Hello @pr4bh4sh, it looks like bmp is not capable of adding full page load timings (which makes sense).

https://groups.google.com/forum/#!topic/browsermob-proxy/iiU2GMr0m2s

I am working on a fallback that would add up the total load time of all elements, and am taking a look into the 0.0 results you are getting, hope to open a pull request soon unless you see something first 😄

@mrname
Copy link
Collaborator

mrname commented Apr 2, 2016

So @pr4bh4sh I have a commit that solves the 0.0 problem.

3b7724c

However, the total page load time is a bit more complicated. As explained in the article I posted, bmp has no concept of an actual "page load" because it does not take things like JS execution into account. Do you think that trying to access the full page load time should issue a warning when the page load timings are not available and return 0 or return the "best guess" which is the total load time of all elements asynchronously?

@pr4bh4sh
Copy link
Author

pr4bh4sh commented Apr 4, 2016

Sorry for delay in response,
Not sure on which would be the best approach, it may differ for other user but in my case I'm fine with best guess.
How about making it optional, and let the user decide

page_load_time(best_guess=True)

@mrname
Copy link
Collaborator

mrname commented Apr 12, 2016

Cool, will work up another PR to address the remainder of the issue, thanks.

@mrname
Copy link
Collaborator

mrname commented May 8, 2016

So sorry for the delay @pr4bh4sh, I have been trying to think of the best way to handle it. What do you think about something like:

load_time = 0
try:
    load_time = multi_har_parser.page_load_time
except PageLoadTimeError:
    load_time = multi_har_parser.asset_load_time

I know it looks a little bit clunkier than a boolean passed to the parser, but I feel like it makes it more obvious that you are dealing with 2 very different statistics, and allows you to always try for the most correct one first (full page load time including JS rendering). Does that work for you?

@pr4bh4sh
Copy link
Author

That's ok with me.
It should be good if this is added in the docs though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants