Google WebPageTest API – A Practical Example

In a recent article, I described how to use Selenium and the Javascript Navigation API to quickly collect customized client-side performance metrics. In this article, I’ve covered the specifics of the most useful features as well as how to put up a NodeJS wrapper for the Webpage Test API and run a programmed test.

WebPageTest API

This is merely a REST API (provided by several businesses including AKAMAI, NewRelic, GoDaddy, etc., and sponsored by Google) that allows us to obtain client-side performance measurements with the ability to simulate from a certain device, location, network bandwidth, and other factors. You can see what we are capable of doing at a high level in the image below. Using a website like www.example.com, for instance, we can obtain client-side performance data with user inputs.

Link: https://www.webpagetest.org/

figure:01

Looking at the www.webpagetest.org home page You are not alone if you believe that this tool can only be used to test a website’s front page or landing page. By reading the sections below, I hope you’ll reconsider your presumption.

Essential Skills

  1. Comprehensive client-side performance analysis and suggestions
  2. Results of tests performed on real devices are published.
  3. Waterfall
  4. Trade HAR
  5. Information about the device’s resource utilization
  6.  Simulation of Network Bandwidth/Latency
  7. View the video to compare two tests.
  8.  Automated tests [In addition to the home page, we may also access information about the page that follows the login page/second page]
  9. Getting an email with the test results.
  10. To test internal websites, the full tool can be installed in AWS or as a private instance.
  11. SPOF test [You can test how your website behaves when a specific third-party service or server is unavailable, e.g., a CDN]
  12. To obtain an audit report from a performance and accessibility perspective, use the Lighthouse test (which is a component of the Chrome developer tools).
  13. Using a NodeJS wrapper for continuous integration.

In the end, if configured correctly, you can receive the report via email. When an automated test was run and a report was delivered to my inbox, I was overjoyed to see it. Receiving such a lot of information about your website from an open-source application is fantastic!

I have telepathic powers. You would have seen the documentation page and are now considering how to use this product right now. I’ve listed the procedures for configuring the NodeJS wrapper and a sample test that I was able to run in the sections below.

WebPageTest API: How do I use it?

Step 1:

http://www.webpagetest.org. to access the public WebPageTest instance. Try different things by running some tests on the website you like. You would like it [You can select Browser, device (mobile/desktop), bandwidth, location, etc.].

Step 2:

Ask for a key.

Visit this link to acquire the key: http://www.webpagetest.org/getkey.php

Note: Occasionally, it could take some time.

Step 3:

Recognize that using the public instance has limitations. [With your key, you can only run 200 tests per day] Expect the test results to take some time. Your test would be queued and conducted in a methodical manner if there are other tests running on the device/location you selected.

Step 4:

Explore the next level of scenarios, or scripted tests, if you are comfortable with the fundamental functions. Please see the link below for more information.

Visit this website at:  https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/scripting

Due to the nature of REST API, if we attempt to run a test for a page that needs session information (for example, a page that can be accessible after logging in), we must write a script to access that page by adhering to the instructions provided in the aforementioned URL. The DOM properties may be used to perform almost any user interaction, such as entering text, clicking buttons, and submitting forms. (Name, innerText, etc.), Id, etc. Please refer to the scripted exam sample below.

Figure 02: Sample scripted test 

To run a scripted test, go to the front end’s Advanced Testing -> Script tab and insert the test in that test section. Keep in mind that tabs should be used to separate these commands.

Figure 03

Note: Please be cautious when using sensitive data. (Passwords/PII data)

Wrapper for NodeJS – setup

Explore the NodeJS wrapper created by MarcelDuran once you have mastered the scripted tests that you are capable of doing. (https://github.com/marcelduran/webpagetest-api).

This really is a great feature! Don’t be concerned that you won’t be able to use this functionality if you don’t have a thorough understanding of NodeJS. You shouldn’t have any major issues learning and putting it into practice.

Should I have a solid understanding of NodeJS to run tests?

Both yes and no apply. It is better to have some in-depth understanding if you want to make more adjustments to the outcomes or how you obtain them. Otherwise, I believe you could get by with only the very minimum of und understanding if you know how to set it up and use it.

What is the benefit of using this NodeJS wrapper?

As a Javascript runtime environment, NodeJS

  1. Instead of using Webpagetest’s problematic UI to write script tests, you can write your tests in Javascript. (Making sure the key-value pairs are separated by tabs is a big job.)
  2. Use the command prompt to run them.
  3. Continuous integration support is provided.

How do I set up NodeJS on Windows 10?

Choose the latest Windows 10 MSI and follow the instructions on the screen. Once successfully installed, you should be able to verify as shown below.

Node.js.org/en/download is the URL.

Figure 04: NodeJS Verification

Please see the NodeJS test that I was able to complete below.

Figure 05: NodeJS Test

Reminder: Save the NodeJS code into a.js file and run it at the command prompt as shown.

Node: C: Path: Demo1.js

What does the above NodeJS code accomplish?

  1. This program loads the WebPageTest Javascript module so that the methods can be used.
  2. creates an instance or object of WebpageTest that points to www.webpagetest.org, a public instance. You can submit the information below if you have a private instance installed.)
  3. var wpt = new WebPageTest(‘http://private instance IP: port>/’, ‘private instance key>’); testSettings – Defines the testSettings on which the test will run. (Depending on location, device, bandwidth, etc. depending on your needs)
  4. script – Choose which pages you want to visit and what data the web page test should record. The aforementioned script first loads a page, clicks a specific button to go to another page and then runs the test using that page’s criteria.
  5. <wpt.runTest- It’s a method that you can use to invoke WebpageTest’s runTest method.

If configured correctly, the results of a successful run will be sent to the email address provided after the run. What we’ve seen so far is extremely basic usage, which you can explore and put to use as needed.

Scroll to Top