Since YSlow can generate a performance report from the HAR input file, I would use a proxy server to record performance data when navigating the site using Selenium. This way you can independently measure performance on a real browser (Chrome, Firefox, Safari ...) or on a headless one such as PhantomJS.
To continue, first download the browser proxy and unzip it:
https://github.com/lightbody/browsermob-proxy/releases
Then write code to start the proxy server and run the script with the Selenium client. This example was written in Python, but you can write it in the same way with some Java, Ruby, Javascript or PHP.
from browsermobproxy import Server from selenium import webdriver import json, sys # setup the proxy server server = Server(r"C:\Download\browsermob-proxy-2.1.0-beta-5\bin\browsermob-proxy") server.start() proxy = server.create_proxy() try: # setup the browser profile = webdriver.FirefoxProfile() profile.set_proxy(proxy.selenium_proxy()) driver = webdriver.Firefox(firefox_profile=profile) # start collecting the data proxy.new_har("google") # login to a twitter account driver.get("https://twitter.com/login?lang=en") driver.find_element_by_css_selector(".js-username-field").send_keys("my name") driver.find_element_by_css_selector(".js-password-field").send_keys("my password") driver.find_element_by_css_selector("button.submit").click() # save the collected data to a file with open(sys.argv[1], 'w') as file: file.write(json.dumps(proxy.har, indent=2)) finally: driver.quit() server.stop()
Finally, to run the script and generate a performance report using the command line:
python perf-login.py perf-login.har yslow perf-login.har
Florent B.
source share