Gathering page load performance metrics using Selenium

Performance measure using selenium : http://www.slideshare.net/watsonmw/performance-monitoring-in-a-day

Advertisements

Automating YSlow score using webpagetest, yslow command line and node js

The following is the sequence to generate the YSLOW score using script.

1. Create the environment

  • Install node js on RHEL :
    wget http://nodejs.tchol.org/repocfg/el/nodejs-stable-release.noarch.rpm
    sudo yum localinstall --nogpgcheck nodejs-stable-release.noarch.rpm
    sudo yum install nodejs-compat-symlinks npm
  • Install YSlow commandline as explained in http://developer.yahoo.com/yslow/commandline/
    sudo npm install yslow -g

    The following error is OK

    > contextify@0.1.2 install /usr/lib/node_modules/yslow/node_modules/jsdom/node_modules/contextify
    > node-gyp rebuild
    node.js:201
            throw e; // process.nextTick error, or 'error' event on first tick
                  ^
    Error: Cannot find module '/usr/lib/nodejs/npm/node_modules/node-gyp/bin/node-gyp.js'
        at Function._resolveFilename (module.js:332:11)
        at Function._load (module.js:279:25)
        at Array.0 (module.js:479:10)
        at EventEmitter._tickCallback (node.js:192:40)
    npm WARN optional dependency failed, continuing contextify@0.1.2
    /usr/bin/yslow -> /usr/lib/node_modules/yslow/bin/yslow
    yslow@3.1.0 /usr/lib/node_modules/yslow
    ├── commander@0.5.2
    └── jsdom@0.2.13

2. Get Key for accessing the webpagetest.org REST apis

  • Send mail to pmeenan@webpagetest.org with the following details
    • Purpose of the use
    • Number of API calls/day

3. Write script to get the HAR file from webpagetest.org and generate the Yslow file

Notes :

Automating the YSLOW score and HAR using Firefox plugins(NetExport,YSlow)

I have used the following url as source for my experiment.

http://tech.groups.yahoo.com/group/exceptional-performance/message/822

Goal : To automate the following

1. To get YSLOW score of  a webpage

2. To get the Http Archive (HAR) of a webpage

Steps followed

1. Setup firefox with a new profile ‘PerformanceTest’.

  • Create a new profile(In Mac) : /Applications/Firefox.app/Contents/MacOS/firefox -P

2. Install the firebug, yslow and netexport plugins into this profile.

3. Create a web application URL to accept the YSLOW and HAR data

  • On mac(using default apache webserver) , create the Perl CGI scripts  under folder /Library/WebServer/CGI-Executables
  • get_yslow_data.pl Scrpt
  • #!/usr/bin/perl -wprint "Content-type: text/html\n\n";
    open FILE, '>/tmp/yslow.txt';
    #print "<pre>\n";if ($ENV{'REQUEST_METHOD'} eq "GET") {$request = $ENV{'QUERY_STRING'};} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    read(STDIN, $request,$ENV{'CONTENT_LENGTH'})
    || die "Could not get query\n";
    
    }
    foreach $key (sort keys(%ENV)) {
    print FILE "$key = $ENV{$key}\n";
    }
    print FILE $request;
    close FILE;

     

  • get_har_data.pl script
  • #!/usr/bin/perl -wprint "Content-type: text/html\n\n";
    open FILE, '>/tmp/har.txt';
    #print "<pre>\n";if ($ENV{'REQUEST_METHOD'} eq "GET") {$request = $ENV{'QUERY_STRING'};} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    read(STDIN, $request,$ENV{'CONTENT_LENGTH'})
    || die "Could not get query\n";
    
    }
    foreach $key (sort keys(%ENV)) {
    # print FILE "$key = $ENV{$key}\n";
    }
    print FILE $request;
    close FILE;

4. In firefox set the following plugin values

  • extensions.yslow.beaconUrl=http://127.0.0.1/cgi-bin/get_yslow_data.pl
  • extensions.yslow.autorun=true
  • extensions.firebug.netexport.beaconServerURL=http://127.0.0.1/cgi-bin/get_har_data.pl
  • extensions.firebug.netexport.autoExportToServer=true
  • extensions.firebug.netexport.alwaysEnableAutoExport=true
  • In the browser firebug panel, set the ‘AutoExport’ to on.
  • You can also set the send to URL using this panel , in the screenshot you could see that the data is sent to http://www.shwoslow.com

5. Run the firefox from the command line as following. This will generate the files ‘/tmp/yslow.txt’ and ‘/tmp/har.txt’ containing YSLOW and HAR data for that page.

6. Now you can keep this command in your shell/perl script for executing as automated. For example the following script

  • #!/bin/bashFIREFOX="/cygdrive/c/Program Files/Mozilla Firefox/"
    export PATH=$PATH:$FIREFOXURLS="http://www.yahoo.com http://www.google.com"
    for link in `echo $URLS`;
    do
    firefox.exe -P yslow -no-remote $link &
    PID=$!
    sleep 20
    kill $PID
    done

6. Thanks.