by: Helge, published: Dec 4, 2018, updated: Jul 6, 2019, in

PowerShell Script: Test Chrome, Firefox & IE Browser Performance

There is more than one way to test the performance of web browsers like Chrome, Firefox, or IE, but regardless of how you do it, you need a consistent workload that makes the browsers comparable. Unless you are testing with synthetic benchmarks (which come with a plethora of problems of their own) you need a way to automate browsers opening tabs and loading URLs. This article presents a simple solution to do just that.

Purpose of This Browser Test Script

I have written about various aspects of browser performance and privacy before. For those earlier articles, I manually ran the browsers through a series of tests. This quickly proved to be tedious and error-prone. Obviously, automation is the name of the game.

For this year’s session Web App Performance in a Virtual World which I presented at Citrix Technology Exchange and at community meetups I went ahead and finally automated a large part of the test process, and it paid off immediately. I was able to test more configurations in less time with increased accuracy.

Testing is not enough, of course. You need to measure, too. For that, I have been using our uberAgent user experience and application performance monitoring product. uberAgent measures browser page load duration for all major browsers (which was important here) in addition to providing detailed application usage and performance insights for all installed and running applications – Win32, UWP, Java, App-V, etc.

What the Browser Test Script Does

It is really quite simple. I needed a script that would do the following – mind you, for any number of installed browsers and for a list of URLs supplied through a parameter file:

  • Start the browser
  • Open each URL in a new browser tab, waiting 30 s in between
  • Close the browser (gracefully)
  • Repeat the above three times per browser

Techniques Used in the Browser Test Script

I only rarely use PowerShell, my main development work is in C++. Nevertheless, you might find some of the following interesting.

Starting Applications With Their Name Only

Windows has functionality for starting applications by name without requiring them to be part of the PATH environment variable. This is as useful as it is rarely known. I explained the mechanics in my article How the App Paths Registry Key Makes Windows Both Faster and Safer. The thing to note in this context is that App Paths entries can be leveraged from PowerShell with the Start-Process cmdlet. I used it in the script to start browsers by providing simple names like “chrome” or “firefox”.

Closing an Application’s Window Gracefully

When you start an application with the Start-Process cmdlet, it returns a process object. This object has an extremely useful method, CloseMainWindow(). It is equivalent to clicking on the “X” in the window’s upper right corner.

The Browser Test Script

#
# One time setup:
#
# - Open all sites on the list in all browsers
# - Log on the test user UXMetricsGuyA (where applicable)
# - Switch the browser window to full screen
# - Config per site:
#   - Accept cookie popups
#   - Do not accept a site's notifications
#     - Enable "stay signed in" where applicable
# - Config per browser:
#   - Configure browser startup to not open previous tabs
#   - Configure start page: "about:blank"
#   - Do not save passwords in the browser
#   - Disable browser dialogs:
#     - asking about not being the default
#     - asking if you want to close all tabs
#
# Before each test run:
#
# - Empty each browser's cache
#   - Do not delete cookies
# - Close all browsers
# - Restart the machine
# - Log on as test user test01
# - Start a PowerShell console   
# - Wait five minutes
# - Start this script
#

#
# Global variables
#
# How long to wait between open site commands
$waitBetweenSitesS = 30;
# How long to wait after a browser's last site before closing its window
$waitBeforeBrowserClose = 30;
# How long to wait between browsers
$waitBetweenBrowsers = 30;

# Name of the file containing the sites to open
$siteUrlFile = ".\URLs.txt";

# Number of iterations
$iterations = 3;

# Browsers to start
$browsers = @("chrome", "firefox", "iexplore")

#
# Start of the script
#

# Read the sites file
$sites = Get-Content $siteUrlFile;

# Iterations
for ($i = 1; $i -le $iterations; $i++)
{
   Write-Host "Iteration: " $i

   # Browsers
   foreach ($browser in $browsers)
   {
      # Sites
      $siteCount = 0;
      foreach ($site in $sites)
      {
         $siteCount++;
      
         if ($siteCount -eq 1)
         {
            if ($browser -eq "chrome" -or $browser -eq "firefox")
            {
               # Start the browser with an empty tab because the first page load is currently not captured by uberAgent
               $process = Start-Process -PassThru $browser "about:blank"
            }
            else
            {
               # Start the browser with the first site
               $process = Start-Process -PassThru $browser $site
            }
               
            # Store the browser's main process (the first one started)
            $browserProcess = $process;
            
            # Wait for the window to open
            while ($process.MainWindowHandle -eq 0)
            {
               Start-Sleep 1
            }
            
            if ($browser -eq "chrome" -or $browser -eq "firefox")
            {
               # Open the first site in a new tab
               Start-Process $browser $site
            }
         }
         elseif ($browser -eq "iexplore")
         {
            # Additional IE tabs need to be opened differently, or new windows will be created instead
            
            $navOpenInNewTab = 0x800;
            
            # Get running Internet Explorer instances
            $app = New-Object -ComObject shell.application;
            
            # Grab the last opened tab
            $ie = $app.Windows() | Select-Object -Last 1;
            
            # Open the site in a new tab
            $ie.navigate($site, $navOpenInNewTab);
            
            # Release the COM objects
            Remove-Variable ie;
            Remove-Variable app;
         }
         else
         {
            # Addition tabs in Chrome/Firefox
            Start-Process $browser $site
         }
         
         Start-Sleep $waitBetweenSitesS;
      }
      
      Start-Sleep $waitBeforeBrowserClose;
      
      # Close the browser
      $browserProcess.CloseMainWindow();
      $browserProcess = $null;
      
      Start-Sleep $waitBetweenBrowsers;
   }
}

The Script’s URL Input File

The URL input file I used with the script in my 2018 tests looked like this:

https://mail.google.com/mail/u/0/#inbox
https://docs.google.com/document/d/1hOc4bdEQ1-KJ5wOsiCt4kVQB-xaHuciQY6Y4X_I7dYA/edit
https://www.google.com/maps/
https://twitter.com/
https://onedrive.live.com/edit.aspx?cid=740de493111072ca&page=view&resid=740DE493111072CA!108&parId=740DE493111072CA!106&app=PowerPoint
https://outlook.live.com/mail/inbox
https://www.dropbox.com/h
https://www.nytimes.com/
https://www.nbcnews.com/
https://edition.cnn.com/

Previous Article Enabling HTTP/2 in Apache on Ubuntu 18.04
Next Article Upgrading Ubuntu 16.04 to 18.04 & PHP 7.0 to 7.2 for WordPress