Last active
September 21, 2017 06:29
-
-
Save tourdedave/bc4b75fd6cdc1eef7860 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Encoding: utf-8 | |
require 'selenium-webdriver' | |
require 'browsermob/proxy' | |
require 'rspec-expectations' | |
include RSpec::Matchers | |
require 'json' | |
def configure_proxy | |
proxy_binary = BrowserMob::Proxy::Server.new('./browsermob-proxy/bin/browsermob-proxy') | |
proxy_binary.start | |
proxy_binary.create_proxy | |
end | |
def browser_profile | |
browser_profile = Selenium::WebDriver::Firefox::Profile.new | |
browser_profile.proxy = @proxy.selenium_proxy | |
browser_profile | |
end | |
def setup | |
@proxy = configure_proxy | |
@driver = Selenium::WebDriver.for :firefox, profile: browser_profile | |
end | |
def teardown | |
@driver.quit | |
@proxy.close | |
end | |
def capture_traffic | |
@proxy.new_har | |
yield | |
@proxy.har | |
end | |
def run | |
setup | |
har = capture_traffic { yield } | |
@har_file = "./selenium_#{Time.now.strftime("%m%d%y_%H%M%S")}.har" | |
har.save_to @har_file | |
teardown | |
end | |
run do | |
@driver.get 'http://the-internet.herokuapp.com/dynamic_loading/2' | |
@driver.find_element(css: '#start button').click | |
Selenium::WebDriver::Wait.new(timeout: 8).until do | |
@driver.find_element(css: '#finish') | |
end | |
end | |
performance_results = JSON.parse `yslow --info basic --format json #{@har_file}` | |
performance_grade = performance_results["o"] | |
performance_grade.should be > 90 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
Am new to Ruby and Selenium, first of all, this is a very impressive script and thanks for doing this, I need help with generating a report with this script is this something that you can help me with. Thanks