I’ve recently been working with several clients to analyze their website performance with the dynaTrace AJAX Edition. Based on our findings their JavaScript code, usage of 3rd party frameworks, use of AJAX, embedded objects, and caching strategies have been changed over multiple iterations. After each iteration, it is good practice to verify if the changes improved overall performance and also didn’t break the functionality of the page. Instead of executing the main use cases manually while running a performance analysis tool like dynaTrace it makes sense to automate this whole process.

There are several test automation tools out there that actively drive the browser – like Selenium, Watir, WebAii, QTP, SilkTest, … – Key is to not only to automate test execution but also automate performance analysis. The dynaTrace AJAX Edition enables this by automatically collecting and storing performance data for each browser session. With that integration you can run your automated tests to verify your functionality as well as capturing the data for performance analysis. Here are 5 quick steps to automate test execution and performance analysis with Watir and dynaTrace AJAX Edition.

Step 1: Installation

Step 2: Watir Script Generation

As an example we create a Watir script that opens a new browser, opens the google.com search page and searches for Watir. As a setup step we have to define several environment variables that activate the dynaTrace AJAX Agent in IE. By default – the dynaTrace AJAX Agent is not activated when launching a browser from outside the dynaTrace AJAX Edition Client. With the following environment variables you can control the dynaTrace AJAX Agent:

  • DT_IE_AGENT_ACTIVE: true or false to activate or deactivate the agent
  • DT_IE_SESSION_NAME: name of the captured performance session. If you have a test run # or test suite name I would use the name here. This is great to identify a captured performance session by its logical name
  • (optional) DT_IE_SERVER_HOST: The machine where the dynaTrace AJAX Edition Client runs
  • (optional) DT_IE_SERVER_PORT: The port of the dynaTrace AJAX Edition Client
  • (optional) DT_IE_CLEAR_CACHE: If true – the dynaTrace AJAX Agent will first clear the browser’s file cache before starting with any execution

Here is the script (Watir Sample Script) that first sets the env-variables and then executes the test steps:

Watir Script testing Google with enabled dynaTrace AJAX Agent
Watir Script testing Google with enabled dynaTrace AJAX Agent

Step 3: Preparing your test machine

Before running a script you have to

  1. Start the dynaTrace AJAX Edition Client (from the Start Menu -> Programs -> dynaTrace -> dynaTrace AJAX Edition)
  2. Close all current browsers

Its recommended to have the AJAX Edition Client running on your local machine where you also execute your test scripts. You can however run it on a separate machine. In this case you would need to specify the DT_IE_SERVER_HOST environment variable to the hostname that runs the dynaTrace AJAX Edition Client.

dynaTrace AJAX Edition after Startup

Closing all browsers is necessary as Watir reuses a running iexplorer process. The changed environment variable from the script would not affect any running browser instances and would therefore not activate the dynaTrace AJAX Agent. Closing all browsers will force Watir to open a new browser instance.

Step 4: Script Execution

Script execution is straight forward. You can either load your .rb file in SciTE and hit F5 to run the script or you launch it via the command prompt:

c:\> ruby mytestfile.rb

Step 5: Analysis

After the script has been executed you can analyse the output of Watir as well as the captured performance data in the dynaTrace AJAX Edition Client. If you switch to the client you can see a new stored session with the name specified in the DT_IE_SESSION_NAME Environment-Variable:

dynaTrace AJAX Session from Watir Script Execution
dynaTrace AJAX Session from Watir Script Execution

Advanced Step – adding custom markers

The dynaTrace AJAX Edition allows you to add custom markers while recording a performance session in IE. You get a nice toolbar that allows you to specify a Marker with a name that will later show up in the PurePath view at the time where you set the marker.

dynaTrace AJAX Edition Toolbar in IE
dynaTrace AJAX Edition Toolbar in IE

As an example – you can use this while testing an online purchase transaction and you can set markers for e.g.: “Search for Product”, “Place Order”, “Confirm Purchase”, … Having these markers in a large performance session makes it easier to find specific activities.

Not only can these markers be set via the toolbar – they can also be set via JavaScript. Once the dynaTrace AJAX Agent is enabled you can use the _dt_addMark(markname) method to define markers. Watir allows you to execute JavaScript in the browser which allows us to take advantage of the marker feature. Here is an extended version of the original script. As you can see I set markers after my script actions using the execScript method of the browser window:

Watir Script calling dynaTrace Marker Method
Watir Script calling dynaTrace Marker Method

After running this test you can see the marks in the dynaTrace PurePath View as well as in the Timeline Chart:

Markers in dynaTrace AJAX PurePath View

Conclusion

This is one example of how you can automate test execution and performance analysis. Existing tools provide the interfaces and automation features to achieve a higher degree of automation – so let’s use it. I’ve also recently posted about how we can get more out of functional testing. This example actually fits that gap as the dynaTrace AJAX Edition automatically tags each Network Request so that it can be picked up by a server-side Application Performance Management Solution like dynaTrace allowing you to correlate each individual test step with server-side performance data.As always – let me know what your thoughts on this topic are and how you achieve a higher degree of test and analysis automation in your environment.