Slide 1

Slide 1 text

Using WebPageTest @AndyDavies London Web Performance, May 2016

Slide 2

Slide 2 text

http://webpagetest.org

Slide 3

Slide 3 text

@patmeenan ▪ Web performance – Browser and OS activity ▪ Open source – Patrick Meenan – AOL 2008 ▪ webpagetest.org – Public instance – Global infrastructure

Slide 4

Slide 4 text

http://usingwpt.com Aimed at Novices and Power Users Includes: Basics Getting started, running tests, understanding waterfall charts and the metrics WebPageTest captures Intermediate Picking the right test parameters, scripting multi-page tests and using your existing analytics data to help the decisions Advanced Using the API, integrating WebPageTest into build and CI processes, and setting up your own private instances

Slide 5

Slide 5 text

How it works (simplified) Poll for work, measure load and return results to server Load page / pages

Slide 6

Slide 6 text

Mobile is a bit more involved

Slide 7

Slide 7 text

http://man.gl/1PnErR2 Video and filmstrip of page loading Waterfall Summary metrics

Slide 8

Slide 8 text

Repeat View - check for effective caching

Slide 9

Slide 9 text

But what can it do beyond that?

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Advanced Settings…

Slide 12

Slide 12 text

Shape network connection …is a whole another world Choose at least 3 runs

Slide 13

Slide 13 text

Create pcap for Wireshark etc. Inject custom headers e.g. Akamai debug Make tests run for longer e.g catch slow XHR requests http://man.gl/1UxalBe

Slide 14

Slide 14 text

Emulate mobile browsers Capture Chrome debugging info from remote browser Add command-line options - great for comparing HTTP/1.1 vs HTTP/2 Chrome only options http://man.gl/1UxetBe

Slide 15

Slide 15 text

What happens when a 3rd Party Breaks?

Slide 16

Slide 16 text

Site to check Host to ‘blackhole’

Slide 17

Slide 17 text

http://man.gl/1PEz4Au

Slide 18

Slide 18 text

What’s the impact of 3rd Parties?

Slide 19

Slide 19 text

Convert the list of domains into a space separated list (copy ‘n’ paste plus text editor) http://man.gl/1OcK1FM

Slide 20

Slide 20 text

curl 'http://www.webpagetest.org/domains.php? test=160429_5W_cbb3cdebf94050c7b08e49e596d89103&run=1&cached=0& f=json' | jq -rj '.domains.firstView[].domain + " "' | pbcopy Or grab domains in json and pipe through jq Copy to clipboard Extract domain names Get domain breakdown in JSON

Slide 21

Slide 21 text

Paste list of domains / urls to remove (Don’t forget to remove the site you’re testing from the block list)

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Doesn’t always go to plan! http://man.gl/1XGNjGi

Slide 24

Slide 24 text

But switching to Firefox With a bit of patience, and by adjusting the block list we can get there http://man.gl/1nLwRZe

Slide 25

Slide 25 text

Custom Metrics https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/custom-metrics Query DOM using JavaScript to create custom measurement (runs at very end of test)

Slide 26

Slide 26 text

http://man.gl/1PnD9FE

Slide 27

Slide 27 text

Beyond simple single page tests

Slide 28

Slide 28 text

Scripting

Slide 29

Slide 29 text

Searching Google

Slide 30

Slide 30 text

logData 0 navigate http://google.co.uk setvalue id=lst-ib London Web Performance logData 1 submitform id=tsf Searching Google

Slide 31

Slide 31 text

Results page only - http://man.gl/1PEEwn4 Search and results page - http://man.gl/1PEEBak Waterfall for results page only Searching Google

Slide 32

Slide 32 text

Use DevTools to identify elements

Slide 33

Slide 33 text

How can we target this link? Sometimes there’s no obvious hook…

Slide 34

Slide 34 text

document.querySelector('.orb-nav-news a') JavaScript to the rescue! http://man.gl/1UxgOfy

Slide 35

Slide 35 text

JavaScript to the Rescue! http://man.gl/1PEGQdL logData 0 navigate http://www.bbc.co.uk/ logData 1 execAndWait document.querySelector('.orb-nav-newsdotcom a').click(); execAndWait - execute JS and wait for browser to complete activity exec - execute JS and don’t wait

Slide 36

Slide 36 text

Type ahead searches?

Slide 37

Slide 37 text

JQuery FTW! Honestly! logData 0 navigate http://www.thetrainline.com exec document.getElementById('originStation').value='Cheltenham'; exec $('#originStation').keydown(); exec document.querySelectorAll('#originStation + div + ul > li > a')[0].click(); Use JQuery’s keydown method JQuery must be already on the page

Slide 38

Slide 38 text

Debugging scripts can be hard! logData 0 navigate http://www.thetrainline.com exec document.getElementById('originStation').value='Cheltenham'; exec $('#originStation').keydown(); exec document.querySelectorAll('#originStation + div + ul > li > a')[0].click(); exec document.getElementById('destinationStation').value='Leeds'; exec $('#destinationStation').keydown(); exec document.querySelectorAll('#destinationStation + div + ul > li > a')[0].click(); exec document.getElementById('isOneWay').checked='checked'; logData 1 execAndWait document.getElementById('submitButton').click(); Script fails due to timing issues

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

execAndWait to the rescue! navigate http://www.thetrainline.com logData 0 exec document.getElementById('originStation').value='Cheltenham'; execAndWait $('#originStation').keydown(); exec document.querySelectorAll('#originStation + div + ul > li > a')[0].click(); exec document.getElementById('destinationStation').value='Leeds'; execAndWait $('#destinationStation').keydown(); exec document.querySelectorAll('#destinationStation + div + ul > li > a')[0].click(); exec document.getElementById('isOneWay').checked='checked'; logData 1 execAndWait document.getElementById('submitButton').click();

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Authentication Basic Auth setHeader Authorization: Basic dGVzdDp0ZXN0 navigate http://browserspy.dk/password-ok.php Set a Cookie setCookie http://www.example.com session=286755fad04869ca523320acce0dc6a4 navigate http://www.example.com/ Fill in a form (as per earlier form examples) base64(username + “:” + password)

Slide 44

Slide 44 text

Lots more detail on scripting in the docs: https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/scripting Debugging: - Use DevTools to check any DOM queries - Save response bodies in WPT (advanced tab) and manually inspect - Watch test execute on Private Instance - Adding sleep or switching to execAndWait can help

Slide 45

Slide 45 text

Using the API

Slide 46

Slide 46 text

http://www.webpagetest.org/getkey.php

Slide 47

Slide 47 text

Dulles_IE9 Dulles_IE10 Dulles_IE11 Dulles:Chrome Dulles:Canary Dulles:Firefox Dulles:Firefox Nightly Dulles:Safari Dulles_Chrome40 Dulles_MotoG:Motorola G - Chrome Dulles_MotoG:Motorola G - Chrome Beta Dulles_MotoG:Motorola G - Chrome Dev ec2-us-east-1:Chrome ec2-us-east-1:IE 11 ec2-us-east-1:Firefox ec2-us-east-1:Safari ec2-us-west-1:Chrome ec2-us-west-1:IE 11 ec2-us-west-1:Firefox ec2-us-west-1:Safari ec2-us-west-2:Chrome ec2-us-west-2:IE 11 ec2-us-west-2:Firefox ec2-us-west-2:Safari ec2-eu-west-1:Chrome ec2-eu-west-1:IE 11 ec2-eu-west-1:Firefox ec2-eu-west-1:Safari ec2-eu-central-1:Chrome ec2-eu-central-1:IE 11 ec2-eu-central-1:Firefox ec2-eu-central-1:Safari ec2-ap-northeast-1:Chrome ec2-ap-northeast-1:IE 11 ec2-ap-northeast-1:Firefox ec2-ap-northeast-1:Safari ec2-ap-southeast-1:Chrome ec2-ap-southeast-1:IE 11 ec2-ap-southeast-1:Firefox ec2-ap-southeast-1:Safari ec2-ap-southeast-2:Chrome ec2-ap-southeast-2:IE 11 ec2-ap-southeast-2:Firefox ec2-ap-southeast-2:Safari ec2-sa-east-1:Chrome ec2-sa-east-1:IE 11 ec2-sa-east-1:Firefox ec2-sa-east-1:Safari Works with these public locations

Slide 48

Slide 48 text

http://www.webpagetest.org/runtest.php?mv=1& video=0& location=Dulles:Chrome& f=json& fvonly=1& k=A.a69f6e28fc64e15b8d330a700f104977& private=1& url=http://news.bbc.co.uk Submitting a test

Slide 49

Slide 49 text

Postman is handy for experimenting with RESTful APIs http://www.getpostman.com/

Slide 50

Slide 50 text

Get a response… { "statusCode": 200, "statusText": "Ok", "data": { "testId": "160205_N4_d2ea71c14d70c68bb0e3d30a88e59d76", "ownerKey": "b6a596f5ce4165ef9725bb91d9e4cec75e1f1d8c", "jsonUrl": "http://www.webpagetest.org/jsonResult.php?test=160205_N4_d2ea71c14d70c68bb0e3d30a88e59d76", "xmlUrl": "http://www.webpagetest.org/xmlResult/160205_N4_d2ea71c14d70c68bb0e3d30a88e59d76/", "userUrl": "http://www.webpagetest.org/result/160205_N4_d2ea71c14d70c68bb0e3d30a88e59d76/", "summaryCSV": "http://www.webpagetest.org/result/160205_N4_d2ea71c14d70c68bb0e3d30a88e59d76/page_data.csv", "detailCSV": "http://www.webpagetest.org/result/160205_N4_d2ea71c14d70c68bb0e3d30a88e59d76/requests.csv" } }

Slide 51

Slide 51 text

{ "data": { "statusCode":100, "statusText":"Test Started 13 seconds ago", "id":"160205_N4_d2ea71c14d70c68bb0e3d30a88e59d76", "testInfo": { "url":"http:\/\/news.bbc.co.uk", "runs":1, "fvonly":1, . . . }, "statusCode":100, "statusText":"Test Started 15 seconds ago" } Poll the JSON or XML URL

Slide 52

Slide 52 text

{ "data": { "id":"160205_N4_d2ea71c14d70c68bb0e3d30a88e59d76", "url":"http:\/\/news.bbc.co.uk", "summary":"http:\/\/www.webpagetest.org\/results.php?test=160205_N4_d2ea71c14d70c68bb0e3d30a88... "testUrl":"http:\/\/news.bbc.co.uk", "location":"Dulles:Chrome", "from":"Dulles, VA - Chrome<\/b> - Cable<\/b>", "connectivity":"Cable", . . . }, "statusCode":200, "statusText":"Test Complete" } Until the test completes

Slide 53

Slide 53 text

Data Galore! http://man.gl/1octXxj

Slide 54

Slide 54 text

Lots more detail on the API in the docs: https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/scripting Marcel Duran’s NodeJS API wrapper: https://github.com/marcelduran/webpagetest-api

Slide 55

Slide 55 text

Sometimes… Perhaps… You just want a quick and easy solution…

Slide 56

Slide 56 text

https://www.flickr.com/photos/craigmoulding/8399214678

Slide 57

Slide 57 text

https://github.com/andydavies/WPT-Bulk-Tester

Slide 58

Slide 58 text

Demo - http://man.gl/1UxjYjs

Slide 59

Slide 59 text

https://www.flickr.com/photos/beccaplusmolly/3287530838 Bored with waiting for tests to run?

Slide 60

Slide 60 text

Run your own WPT instance (or use one of the commercial services)

Slide 61

Slide 61 text

Preconfigured AMIs = easy way to get started http://man.gl/1THSdot

Slide 62

Slide 62 text

My WPT Instance Mac Mini running VMware ESXi - Ubuntu 14.04 server - Win 7 agents

Slide 63

Slide 63 text

Not quite the same scale as Pat’s basement! https://twitter.com/patmeenan/status/702107267462782976

Slide 64

Slide 64 text

Relay mode Passes test to another WPT server and polls for results Piggyback on others infrastructure e.g. public agents, Useful for keeping results from ephemeral instances e.g. AWS Or to keep final results within firewall etc.

Slide 65

Slide 65 text

WebPageTest is really great tool You can use it for quick and simple testing but… If you take the time to experiment and learn, you can do a whole lot more.

Slide 66

Slide 66 text

Thanks! @AndyDavies [email protected] P.S. Don’t forget to buy a copy of http://usingwpt.com