Add Scripts to Your WebPageTest Tests

The WebPageTest blog contains numerous posts to guide users through the site, but it can also be a bit overwhelming…

To help you conduct a basic performance test, we have created the walk-through below.


Add Scripts to your Test

  1. Create a basic test as you normally would.
    (For help getting started with a basic test, please refer to my Getting to Know… WebPageTest article.)
  2. Once you have a basic test ready to run, in the Advanced Configuration panel, click the Scripts tab:
  3. You should now see a panel like this:

    1. This is where you script will go, but this is not for JavaScript or any other standard coding language! We will get more into this in a bit.
    2. If you find yourself wanting to repeatedly use similar scripts, you may want to save them somewhere as files, which you can then easily “import” using this link.
      Note: The phrase “text file” is not limited to a .txt file, it just means a text-based file; a .js file will upload just fine as well.
    3. If you have to add username, passwords, or anything else that you deem sensitive, checking this will remove the Script info from the results so no one else can see it, and it will not be stored on any WPT server or system.
    4. Similarly, checking this removes the HTTP headers from the results of this test.
    5. Their documentation link is extremely helpful in getting to know the basic commands you can use in here. Scroll through the entire page or choose from the options in the Recommended Commands panel on the right. Also see the Shared Recipes section below for more example scripts.
  4. A common script you might want to run would be adding a cookie before page load in order to force a modernized version of a page or prevent a popover from loading. Such a script would look something like this:
    //    set a cookie before opening the page (name and value)
    setCookie    %ORIGIN%    name=value
    //    navigate to page
    navigate    %URL%

    Note the final navigate command. This is required for any test that uses anything in the Script panel.
    Also note the %URL% variable being used here. There are several variables available to you to help make your scripts more flexible for use across multiple pages, locales and even brands.

  5. Other common script uses would be performing multi-page tests, or interacting with the UI in some way, such as a checkout flow.
  6. Once you have your Script as you want it, continue building the rest of your test as you want, then run that test.
  7. Once the test has completed, you can review the results as you normally would any other test.
  8. And don’t forget that, you can share any test you run with others, and, provided you were logged in before running this test, you can also revisit previous tests and even re-run it.

Shared Recipes

In addition to the Sample Scripts provided in the WPT Scripting documentation, many others have created lists of “recipes” that you can easily copy, paste and edit to fit your needs.

  1. Speedcurve Recipes:
    • Although specifically created by Speedcurve, there is a lot of useful options provided here.
    • Once you find an interesting recipe, click it to view step-by-step, detailed explanations, and even copy the code:
  2. WebPageTest API:
    • If you happen to be using the WebPageTest API, you can choose from among these helpful recipes.
    • From within Github, you can copy or download specific files for use within your API testing.

Happy scripting,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.