Giter Club home page Giter Club logo

webpagetest-ruby's Introduction

Webpagetest Ruby Wrapper

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

  • Run tests with all specified parameters of the API.
  • Check test status
  • Get available test locations

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:

  • Susuwatari uses Rest client to make HTTP requests, but this gem uses Faraday instead, since it's more flexible and extensible in terms of HTTP connection.
  • Susuwatari Client class is focused on test runs, but no general-purpose wrapper has been built so far (for example, locations were missing).

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

require 'webpagetest'

wpt = Webpagetest.new(k: your_api_key)

Run test

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

  • test_id: the id assigned to the submitted test
  • status: the status of the test (nil at the beginning)
  • result: the result object (nil at the beginning)
  • raw: the raw response of the request
  • get_status: makes a test status request, and fetches the result when status is :completed
response = wpt.run_test do |params|
    params.url = 'http://webpagetest.org'
end

# Test is running, so status must be requested
response.get_status # => :running

# When test is completed, status will be updated
response.get_status # => :completed

# Only after knowing that test is completed, the result is set
response.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"
]

response.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.

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

response.test_id # => "131007_FC_WHR"

# Test could be running or completed
response.get_status # => :completed

response.result.average.firstView.domElements # => 714

Locations

locations = wpt.locations
locations.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.

webpagetest-ruby's People

Contributors

sivicencio avatar

Watchers

Chad Westfall avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.