I have a web application, on which I would like to run Yslow. The tests would need to be integrated with Jenkins. The application has a login page. If I provide the application's url, if a valid user is not logged in the login page will be displayed. So how do I test performance using YSLow & Jenkins? Is it possible to automate the login part?
Since YSlow can generate a performance report from an input HAR file, I would use a proxy server to record the performance data while navigating the web-site with Selenium. This way, you can independently measure the performance on a real browser (Chrome, Firefox, Safari...) or on a headless one like PhantomJS.
To proceed, first download browsermob proxy and unzip it:
https://github.com/lightbody/browsermob-proxy/releases
Then write the code to launch the proxy server and to run your scenario with a Selenium client. This example was written in Python, but you could write it 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 the performance report with a command line:
python perf-login.py perf-login.har
yslow perf-login.har
yes you can, but you still miss this automated part. You need something more than a YSlow & Jenkins. It's highly depended on application's network architecture - if you run tests locally, or remotely.
Robotframework + Selenium Server
With Robotframework's selenium2library can use Selenium Server bindings to manipulate with browsers DOM. In other words, you can create very simple automated login tests and actions. Afterwards the SSHLibrary or Terminal library can run YSlow commands and you just need to provide output files to Jenkins readable location. It's pretty complex solution suitable for advanced network architecture with many dependencies.
PhantomJS + CasperJs
If you need to run your performance tests locally, you can use advantage of headless browser PhantomJS. In combination with CasperJS you are able to manipulate with DOM to create automated login processes. PhantomJS is also compatible with YSlow, so once again, you just need to define the output files location for Jenkins.
For both solutions (or any other) you will need additional jenkins plugins to read output files generated by YSlow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With