5 Steps to Automate Browser Performance Analysis with Watir and dynaTrace AJAX Edition
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:
Step 3: Preparing your test machine
Before running a script you have to
- Start the dynaTrace AJAX Edition Client (from the Start Menu -> Programs -> dynaTrace -> dynaTrace AJAX Edition)
- 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.
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:
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.
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.