Pagetest has a scripting capability that lets you automate a multi-step test (for example, logging into a site or sending an e-mail message). The scripts are contained in files where a single file constitutes a browser session (the browser will be closed after the script is complete). The files are plain text files and can be edited by any text editor. You can test a script in the desktop version by selecting "Run Script" from the File menu. Each line of the script file contains a command and any necessary parameters and is tab-delimited (i.e. the command is followed by a tab then the first parameter then a tab and the second parameter etc until the end of the line). The number of parameters and what they control is dependent on the command.
<input type="text" class="tabInputFields" id="lgnId1" value="" tabindex="1" maxlength="97" name="loginId"/>you could identify it as id=lgnId1 , name=loginId or tabindex=1 For form fields it is usually best to use the name attribute when it is available since that is what will be uploaded to the server but any attribute is fair game. The class attribute is special and is referenced as className instead of class. In addition to the DOM element attribute matching, there are two special attributes that you can use to match on the contents. innerText and innerHtml both of which will match the contents of the DOM element instead of it's attributes. For example: <div dojoattachpoint="containerNode" class="label">Delete</div> Can be identified by innerText=Delete. The matching is case sensitive and matches the full string. Hosted Scripting (WebPagetest)The hosted version of pagetest supports executing uploaded scripts with a few limitations:
In order to suppress intermediate steps you need to make sure that data logging is disabled for the steps up to the one you want to record. For example: logData 0 // put any urls you want to navigate navigate www.aol.com navigate news.aol.com logData 1 // this step will get recorded navigate news.aol.com/world The script above will navigate to the main aol portal, then to the news page and then finally to the world-news specific page (logging results for just the world news page). This lets you test the impact of a given path to a site on it's performance (shared css and js caching for example). Another significant use case is if you want to test a site that requires authentication. Here is what an authentication script would look like: logData 0 // bring up the login screen navigate http://webmail.aol.com logData 1 // log in setValue name=loginId [email protected] setValue name=password somepassword submitForm name=AOLLoginForm You won't get a lot of feedback as to why a script failed so make sure to test your scripts locally with the desktop version of pagetest (file->Run Script) before uploading them for hosted testing. You can probably get away with a simple navigation path without testing but not the fancier scripts. Command ReferenceNavigation/DOM InteractionnavigateNavigates the browser to the provided URL and waits for it to complete. usage: navigate <url> example: navigate http://webmail.aol.com <url> - URL to provide the browser for navigation (same as you would enter into the address bar) clickTriggers a click event for the identified DOM element. This version does not have an implied wait and the script will continue running after the event is submitted (see clickAndWait for the wait version). usage: click <attribute=value> example: click title=Delete (del) <attribute'value> - DOM element to click on clickAndWaitTriggers a click event for the identified DOM element and subsequently waits for browser activity to complete. usage: clickAndWait <attribute=value> example: clickAndWait innerText=Send <attribute'value> - DOM element to click on selectValueSelects a value from a dropdown list of the given DOM element. usage: selectValue <attribute=value> <value> example: selectValue id=country usa <attribute=value> - DOM element to select the value of <value> - value to use sendClick / sendClickAndWaitCreates a javascript OnClick event and sends it to the indicated element. usage: sendClickAndWait <attribute=value> example: sendClickAndWait innerText=Send <attribute=value> - DOM element to send the click event to sendKeyDown / sendKeyUp / sendKeyPress (AndWait)Creates a javascript keyboard event (OnKeyDown, OnKeyUp, OnKeyPress) and sends it to the indicated element. usage: sendKeyDownAndWait <attribute=value> <key> example: sendKeyDownAndWait name=user x <attribute=value> - DOM element to send the click event to <key> - Key command to send (special values are ENTER, DEL, DELETE, BACKSPACE, TAB, ESCAPE, PAGEUP, PAGEDOWN) setInnerHTMLSets the innerHTML of the given DOM element to the provided value. This is usually used for filling in something like an editable HTML panel (like the message body in webmail). Use this if you want to include HTML formatting. usage: setInnerHTML <attribute=value> <value> example: setInnerHTML contentEditable'true %MSG% <attribute=value> - DOM element to set the innerText of <value> - value to use setInnerTextSets the innerText of the given DOM element to the provided value. This is usually used for filling in something like an editable HTML panel (like the message body in webmail). Use this if you don't want to include any HTML formatting. usage: setInnerText <attribute=value> <value> example: setInnerText contentEditable'true %MSG% <attribute=value> - DOM element to set the innerText of <value> - value to use setValueSets the value attribute of the given DOM element to the provided value. This is usually used for filling in text elements on a page (forms or otherwise). Currently only "input" and "textArea" element types are supported. usage: setValue <attribute=value> <value> example: setValue name'loginId userName <attribute=value> - DOM element to set the value of <value> - value to use submitFormTriggers a submit event for the identified form. usage: submitForm <attribute=value> example: submitForm name'AOLLoginForm <attribute=value> - Form element to submit execExecutes javascript. usage: exec <javascript code>
example: exec window.setInterval('window.scrollBy(0,600)', 1000);execAndWaitExecutes javascript and waits for the browser to complete any activity generated from the action. usage: execAndWait <javascript code>
example: execAndWait window.setInterval('window.scrollBy(0,600)', 1000);fileDialogClicks on the identified button to act on a local file, specifies the file provided and then closes the local file browsing dialog. This is primarily used for uploading local files (attaching to mail, uploading pictures, etc). usage: fileDialog <attribute=value> <file> example: fileDialog type=file msg.gif <attribute=value> - DOM element to click on. <file> - file to attach/upload. Unless a page has more that one button for attaching files (highly unlikely) you should be able to always use type'file for the DOM element. End ConditionsrequiredRequestForces the test to wait for the given request before completing. usage: requiredRequest <url substring> example: requiredRequest adsWrapper.js <url substring> - Part of the request URL to match (case-sensitive substring match) You can specify multiple requests by repeating the command for each new request: requiredRequest www.aol.com requiredRequest www.google.com navigate www.google.com setABMSets the "Activity Based Measurement" mode. The valid values are: usage: setABM <mode> example: setABM 0 <mode> - ABM mode to use setActivityTimeoutOverrides the timeout value for the time after the last network activity before a test is considered complete (defaults to 2000 which is 2 seconds). usage: setActivityTimeout <timeout in milliseconds> example: setActivityTimeout 5000 <timeout in milliseconds> - Number of milliseconds after the last network activity (after onload) before calling a test done. setDOMElementSets the attribute of a DOM element that is required for the next event to complete successfully. The measurement will not complete until the DOM element appears or the action times out. Additionally, the time when the DOM element appears will be recorded in the results. usage: setDOMElement <attribute=value> example: setDOMElement name'loginId <attribute=value> - DOM element to wait for setDOMRequestSets the substring of a Http Request that is required for the next event to complete successfully. The measurement will not complete until that particular Http Request finishes or the action times out. Additionally, the time when the Http Request happens will be recorded in the results. usage: setDOMRequest <target> <value> example: setDOMRequest www.google.com/images <target> - Http Request to wait for <value> - It is optional. It can be TTFB or START. If it is not present, the time till the END of the Http Request will be recorded in the results setTimeoutOverrides the timeout value for the individual script steps. usage: setTimeout <timeout in seconds> example: setTimeout 240 <timeout in seconds> - Number of seconds to allow for the navigation/step to complete. waitForCompleteWaits for measurement of the current activity to finish. This is usually not needed since most of the commands that initiate activity either implicitly wait or have a version of the command that includes a wait. This should only be used if none of those are suitable for the action being measured. usage: waitforComplete example: waitforComplete waitForJSDoneWaits for code on the page to explicitly indicate it is finished by calling window.webpagetest.done() usage: waitForJSDone example: waitForJSDone The javascript on the page would look like: if( window.webpagetest )
window.webpagetest.done();Request ManipulationblockBlocks individual requests from loading (useful for blocking content like ads). The command matches the list of things to block against the full url of each request (including host name). usage: block <block strings> example: block adswrapper.js addthis.com <block strings> - space-delimited list of substrings to block setCookieStores a browser cookie to be used while navigating. usage: setCookie <path> <value> example: setCookie http://www.aol.com zip=20166 example: setCookie http://www.aol.com TestData = Test; expires = Sat,01-Jan-2000 00:00:00 GMT <path> - Path where the cookie should be used/stored <value> - Cookie value (if expiration information isn't included it will be stored as a session cookie) setDnsAllows for overriding the IP address to be used for a host name. The original name will still be looked up so that accurate timings will be recorded but the address will be replaced by the one specified. usage: setDns <host name> <IP Address> example: setDns www.aol.com 127.0.0.1 <host name> - Host name for the DNS entry to override <IP Address> - IP Address for the host name to resolve to setDNSNameAllows for overriding a host name (creating a fake CNAME). usage: setDnsName <name to override> <real name> example: setDnsName pat.aol.com www.aol.com <name to override> - Host name to replace <real name> - Real name to lookup instead setUserAgentOverrides the User Agent string sent by the browser CAUTION : You will still be using the same browser engine so you are still limited by the capabilities and behavior of that browser even if you are spoofing another browser usage: setUserAgent <user agent string> example: setUserAgent Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3 <user agent string> - User agent string to use. overrideHostReplaces the value of the Host: HTTP header for the given host with the provided replacement. It also adds a new header (x-Host:) with the original value. usage: overrideHost <host> <new host> example: overrideHost www.aol.com www.notaol.com <host> - host for which you want to override the Host: HTTP header <new host> - value to set for the Host header overrideHostUrlFor all requests to the given host, rewrite the requests to go to a different server and include the original host in the new URI. usage: overrideHostUrl <host> <new host> example: overrideHostUrl www.webpagetest.org staging.webpagetest.org <host> - host for which you want to redirect requests <new host> - target server to receive the redirected requests In this example, http://www.webpagetest.org/index.php will get rewritten to actually request http://staging.webpagetest.org/www.webpagetest.org/index.php addHeaderAdds the specified header to every http request (in addition to the headers that exist, does not overwrite an existing header). usage: addHeader <header> {filter}
example: addHeader Pragma: akamai-x-cache-on
<header> - Full header entry to add (including label)
{filter} - (optional) regex match for host names where the header should be addedsetHeaderAdds the specified header to every http request, overriding the header if it already exists. usage: setHeader <header> {filter}
example: setHeader UA-CPU: none-ya
<header> - Full header entry to set (including label)
{filter} - (optional) regex match for host names where the header should be set
resetHeadersClears any headers that were specified through addHeaders or setHeaders (in case you want to only override headers for part of a script). usage: resetHeaders example: resetHeaders MisccombineStepsCauses multiple script steps to be combined into a single "step" in the results usage: combineSteps [count] example: combineSteps [count] - Number of script steps to merge (optional, defaults to 0 which is ALL) Sample Script: combineSteps navigate www.google.com navigate www.yahoo.com navigate www.aol.com if/else/endifConditionally execute a block of script code based on run number or cached state for the test. Conditional blocks can be nested. usage: if [cached|run] <value> else endif example: if run 1 if cached 0 <do something for first view of first run> endif else <do something else for everything but first run> endif [cached|run] - Compare against run number or cached state <value> - matching run number or cached state to execute block ignoreErrorsContinues running the script regardless of any errors. This is particularly useful if you expect a certain part of the script to intermittently fail but want to continue executing the script anyway. The default is for it to be disabled and any error in processing the script will stop the test. usage: ignoreErrors <ignore> example: ignoreErrors 1 <ignore> - set to 1 to turn on error ignoring and 0 to disable it logErrorsEnables or disables the logging of script errors to the error log. The default is for it to be enabled. usage: logErrors <log> example: logErrors 0 <log> - set to 0 to turn off error logging and 1 to re-enable it loadFilePopulates the provided variable name with the contents of the supplied file (contents are expected to be text, not binary). usage: loadFile <file> <variable> example: loadFile msg.txt %MSG% <file> - file contents that are to be loaded into the provided variable name. <variable> - variable name to associate with the file contents. The path search order for the file is to first check the same directory the script is running in, then the directory that pagetest was installed to and then finally try the file as an absolute path. loadVariablesPopulates a set of variables from the provided file. The file is expected to be a flat text file with each variable on a line in the format "variable=value". %AOLSN%=username
%AOLPW%=password
{noformat}
The script engine will automatically replace all occurrences of any variable in the value parameter field (3rd parameter). There is no restriction on how the variables are named but it is strongly recommended that you use a convention of %variable% or $variable$ or something similar so that you don't accidentally substitute variables where you did not expect it to happen.
There is no limit on the number of variables you can use or the number of variable files you can load. Each new variable file just adds to the existing variable list. If there is a collision in variable names between two files, the one that is loaded last replaces all previous versions.
<code><pre>
usage: loadVariables <variable file>
example: loadVariables accounts.txt
<variable file> - file that includes the variable/value pairs (see format above).The path search order for the file is to first check the same directory the script is running in, then the directory that pagetest was installed to and then finally try the file as an absolute path. minIntervalSpecifies a minimum interval that the following portion of the script can be run (in minutes). For example, if you only want to test sending of mail no more frequently than every 60 minutes (on a single machine) then you would insert a minInterval command at the point in the script where the mail is going to be sent. If the interval has not expired yet then the script will exit. You can also use it to make sure the same action is not being performed at the same time by multiple browsers by specifying an interval of 0 (which will allow the test to run but will pause the second script until the first script has finished). usage: minInterval <key> <interval> example: minInterval AOLSendMail 60 <key> - Unique event name that will be restricted to the interval <interval> - Minimum time in minutes to allow between allowing the event to run endIntervalEnds the block of code that is protected by a minInterval block. This is useful if the part of the script you want to protect with an interval is in the middle of the script and you always want to execute the remainder of the script (like logging out). usage: endInterval example: endInterval expireCacheExpires any cache entries that will expire within the specified number of seconds. This can be used to simulate a repeat view after a certain amount of time (for example, what it would be like to browse the page the next day). It doesn't help with simulating content changes but any resources with a short expiration will end up being checked with if-modified-since requests. usage: expireCache <seconds> example: expireCache 86400 <seconds> - Any resources with a cache lifetime less than this amount of time will be forced to expire. firefoxPrefAllows you to specify arbitrary preferences that will be configured before launching the browser. usage: firefoxPref <pref> <value> examples: firefoxPref network.http.pipelining false firefoxPref network.http.pipelining.maxrequests 5 firefoxPref general.useragent.override "Some User Agent String" <pref> - The preference that is to be modified <value> - The value to use. String values should be enclosed in quotes like the example. setEventNameSets the name of the event for the next measurable operation. It is important to only set this right before the action that will generate the activity you want to measure so that you don't inadvertently measure other page activity. Without explicit event names each step will be automatically named Step_1, Step_2, etc. usage: setEventName <event name> example: setEventName loadWebmail <event name> - Name to use for the event about to occur (in resulting log files) setViewportSizeChanges the size of the visible browser window so that the page viewport matches the given dimensions. If you get black areas on your screen shots then the viewport is larger than the desktop. usage: setViewportSize <width> <height> example: setViewportSize 320 365 <width> - Viewport Width <height> - Viewport Height sleepPauses the script operation for a given number of seconds. usage: sleep <seconds to sleep> example: sleep 5 <seconds to sleep> - An integer indicating how long to sleep. The allowable range is 1-30. Sample scriptsMail test// load the account name and password loadVariables accounts.txt // bring up the login screen setEventName launch setDOMElement name=loginId navigate http://webmail.aol.com // ignore any errors from here on (in case the mailbox is empty or we get image challenged) ignoreErrors 1 // log in setValue name=loginId %AOLSN% setValue name=password %AOLPW% setDOMElement className=turbogrid-row setEventName load submitForm name=AOLLoginForm // only read and send a mail once an hour minInterval AOLMail 60 // close the today curtain click className=backdrop sleep 5 // Open the first message with a subject of "test" setDOMElement className=msgBody setEventName read clickAndWait innerText=test // delete the message click title=Delete (del) sleep 5 // open the compose mail form setDOMElement contentEditable=true setEventName compose clickAndWait title=Write mail (Alt + w) // send a test message to myself sleep 1 setValue tabindex=100 %AOLSN% setValue name=Subject test loadFile msg.txt %MSG% setInnerText contentEditable=true %MSG% fileDialog type=file msg.gif sleep 1 setDOMElement className=confirmMessage setEventName send clickAndWait innerText=Send endInterval // sign off setEventName logout clickAndWait className=signOutLink MyAOL Authenticated profile// load the account name and password loadVariables accounts.txt // bring up the login screen setDOMElement name=loginId navigate https://my.screenname.aol.com/_cqr/login/login.psp?mcState=initialized&sitedomain=my.aol.com&authLev=0&siteState=OrigUrl%3Dhttp%3A%2F%2Fmy.aol.com%2F // log in setValue name=loginId %AOLSN% setValue name=password %AOLPW% setDOMElement className=more_pics submitForm name=AOLLoginForm DNS OverrideThis script will:
setDnsName www1.aol.com www.aol.com setDns www.aol.com 127.0.0.1 setCookie http://www.aol.com zip=20166 navigate http://www.aol.com iPhone SpoofingThis script will:
setUserAgent Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 setViewportSize 320 356 navigate http://www.aol.com |
Using WebPagetest >
