What is the right way to use WPT for a page behind a login?


WebPageTest(WPT) is super powerful when it comes to automating various user flows either measuring their performance during that flow or after that flow(e.g. after login).

WPT gives you the scripting capability for that. But it is upto the developer to identify the exact scenario he wants to test.

WPT Scripting Page has an example of a snippet which allows you to test a page behind a login. Here is a similar snippet(Snippet-1)

logData    0

// bring up the login screen
navigate    https://example.com/login

logData    1

// log in
setValue    name=loginId    [email protected]
setValue    name=password    mypassword
submitForm    name=login-form

This script navigates to page https://example.com/login and fills up the fields with name attributes equal to loginId and password and then submits the form(with name attribute login-form). It also instructs to log the data in WPT(logData 1) after login only.

The motive here is to measure the performance of the page behind a login. Here that page is the https://example.com(homepage) which is loaded automatically once the login details are filled in.

But would we be measuring the performance in right scenario?

It depends.

Following might be the two simplest scenarios:

  • Scenario-1: You want to measure the performance of a visit when the user is already logged in but he visited after a long time(and thus there is nothing in the Browser Cache).
  • Scenario-2: You want to measure the performance of a visit where he logs in and reaches the homepage(thus when he reaches the homepage he might have certain assets already in cache).

For Scenario-1, Snippet-1 is not the right way to measure as during the login some of the assets might already be in cache. But for Scenario-2, Snippet-1 is what you want.

Scenario-1 is what I had in my mind while doing the audit of a website. But how do you achieve this using WPT Scripting. I immediately thought of a 'Disable Cache' option or a script function to clear the cache after login.

I stumbled upon this thread which suggested a quick and perfect solution for the use case. Here is the script that I used.

logData 1
// Set a cookie to login directly. The cookie can be extracted from your loggedIn session.
setCookie       https://example.com/     session_cookie=session_value
navigate        https://example.com/


Happy Scripting :)

... Loading comments