voxmedia/webpagetest-ruby

Name: webpagetest-ruby

Owner: Vox Media

Description: null

Created: 2015-10-27 20:09:05.0

Updated: 2017-08-29 15:01:50.0

Pushed: 2015-11-05 20:39:47.0

Homepage: null

Size: 112

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Webpagetest Ruby Wrapper

This gem is a Ruby wrapper for the main features of Webpagetest REST API. Features included so far:

This gem is inspired by Susuwatari gem, so several ideas were taken from there (it's like a rewrite with some modifications). There were two main reasons to create a new Webpagetest gem:

Installation

Add this line to your application's Gemfile:

gem 'webpagetest'

And then execute:

$ bundle

Or install it yourself as:

$ gem install webpagetest
Usage

All you require to use the gem is a Webpagetest API key in order to run tests. You can ask your own by emailing Patrick Meenan, like he explains in Webpagetest docs.

Basically, you need to instantiate an object of Webpagetest class, and then use it to interact with the API.

Instantiate WPT object
ire 'webpagetest'

= Webpagetest.new(k: your_api_key)
Run test

When running a test, a Response object is returned, with the following available methods:

onse = wpt.run_test do |params|
params.url = 'http://webpagetest.org'


st is running, so status must be requested
onse.get_status # => :running

en test is completed, status will be updated
onse.get_status # => :completed

ly after knowing that test is completed, the result is set
onse.result.keys

[ 0] "id",
[ 1] "url",
[ 2] "summary",
[ 3] "testUrl",
[ 4] "location",
[ 5] "from",
[ 6] "connectivity",
[ 7] "bwDown",
[ 8] "bwUp",
[ 9] "latency",
[10] "plr",
[11] "completed",
[12] "testerDNS",
[13] "runs",
[14] "fvonly",
[15] "successfulFVRuns",
[16] "successfulRVRuns",
[17] "average",
[18] "standardDeviation",
[19] "median",
[20] "status_code",
[21] "status_text"


onse.result.runs[1].firstView.loadTime # => 2051
Get test result

In order to get a result based on a test id, the same procedure as above must be done.

 = wpt.test_result("some_test_id") # test is a Response object

onse.test_id # => "131007_FC_WHR"

st could be running or completed
onse.get_status # => :completed

onse.result.average.firstView.domElements # => 714
Locations
tions = wpt.locations
tions.keys

[  0] "Dulles_IE6",
[  1] "Dulles_IE10",
[  2] "Dulles:Chrome",
[  3] "Dulles:Canary",
[  4] "Dulles:Firefox",
[  5] "Dulles_iOS",
[  6] "Dulles_Android",
[  7] "Dulles_Thinkpad:Chrome",
[  8] "Dulles_Thinkpad:Canary",
[  9] "Asheville_IE",
[ 10] "Miami_IE8",
[ 11] "Miami:Chrome",
[ 12] "Miami:Firefox",
...

Contribution

This gem is just a starting point wrapper, so much work can be done from here.

Any contribution is appreciated. Just fork this repository and submit the appropriate pull request if you want to add features to this gem.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.