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.
After running this test you can see the marks in the Dynatrace PurePath View as well as in the Timeline Chart:
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.