5 Steps to Automate Browser Performance Analysis with Watir and dynaTrace AJAX Edition
I’ve recently been working with several clients to analyze their web site 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
- Follow the installation steps of Watir
- Download and install dynaTrace AJAX Edition
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 4: 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.
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:
Conclusion
Related posts:
- Automate Testing and Root-Cause Analysis with PushToTest and dynaTrace Testing, Test Automation and Load Testing are critical tasks in the...
- A Step-by-Step Guide to dynaTrace Ajax Edition, available today for public download The dynaTrace AJAX Edition has been out there as an...
- Why Web 2.0 requires End-To-End Performance Analysis and How to Do It Web Site Performance is impacted by many factors and it...
- dynaTrace AJAX Edition 1.5 available – the Rocket Turtle in its next version Just in time for Christmas dynaTrace Labs releases the next...
- dynaTrace AJAX Edition 1.6 available for public download Existing users of the dynaTrace AJAX Edition receive the update...








Hi,
Upto now, All are said Watir is a function test tool. But this article damages that and proves watir & dynaTrace AJAX Edition supports Performance test too..
Really nice article.
Hi raveendran. Glad that you like the article. I want to point out though that Watir is not a performance or load-testing tool. The combination of Watir and dynaTrace allows Performance Analysis of the client activities in the Browser (with dynaTrace AJAX Edition) as well as the execution path on the server (with dynaTrace APM).
[...] This post was mentioned on Twitter by kohlerm, dynaTrace software, Franz See, Gavin Blair, Sean Sandy and others. Sean Sandy said: Use watir to test ajax, then use dynatrace to measure the performance http://bit.ly/44ML0M [...]
Hi Andi, very nice blog – straight forward to implenment. It would be even nicer, if I could download the scripts shown in your screenshots instead of re-typing them.
Attached the script to the blog post – http://blog.dynatrace.com/wp-content/testie.zip
I really like the marker functionality, helps a lot. Thanks
[...] performance information for every browser session that is driven by these test tools. Check out the 5 Steps to Automate Performance Analysis Blog that shows AJAX Edition’s automation capabilities with [...]
This is a great article and there’s quite a bit of potential for using this to extend the usefulness of automated testing even further.
I am trying to integrate this into our existing Selenium tests and am running into an issue. The HTA instance that Selenium invokes by default (using *iexplore or *iehta) doesn’t actually have the dynaTrace tool available so it’s not possible to start a session.
Has anyone been able to work around this issue? I’ve tried starting IE as a custom browser without any success.
Any help is appreciated.
Thanks.
This is a helpful example. Would you help with this error? It seems to have trouble with the submit step. In the IE8 browser, I see the word ‘Watir’ and Google’s proposed list of search terms in a drop-down list below it.
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/form.rb:79:in `assert_exist
s’: Unable to locate a form using id and sfrm (Watir::Exception::UnknownFormException)
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.6.5/lib/watir/form.rb:86:in
`submit’
from C:/ruby_code/testie.rb:18
@Bill:I would post your question in a Watir Forum. I am sure you will get help by the Watir User Community for this error as it is related to Watir and not to dynaTrace. Let us know when you get a positive response so that others can learn from it to.
Happy New Year
Great post Andreas. Is it possible to integrate Dynatrae Ajax markers in Microsoft VSTS web/load test? If yes, do you have example of it anywhere?
@Sujit: VSTS Web/Load-Testing does not “drive” the browser – it is testing your web application by sending HTTP Requests without an instance of Internet Explorer. Check out following posts that describe how to integration VSTS with dynaTrace for Application Performance Management: Visual Studio Team System for Unit-, Web- and Load-Testing with dynaTrace & How to extend Visual Studio 2010 Web- and Load-Testing with Transactional Tracing
Is there a way to export the data out in a CSV/txt or any standard format to preserve for historical purposes.
With the following function can we access other elements/window objects say for eg say ‘Summary Tabs’/text fields etc.
window=b.ie.Document.parentWindow
@Anant: Good Question – and the answer is YES!
First of all – you can keep the recorded sessions in dynaTrace AJAX Edition – so you can always analyze them in the future.
Additionally – every Table/Tree Control has a Copy to Clipboard feature which actually copies an XML Representation of the Table/Tree Selection into the Clipboard. Try selecting multiple entries in either of the Lists, e.g: HotSpots or PurePath. Via the Context Menu call “Copy”. Check out what has been copied to the clipboard
hope that helps
Is it possible to capture the high-level stats like network time, JavaScript execution time, rendering time, and total page load time for each request and automatically export it so that those can be saved in a database for reporting purposes. Sounds like execution can be automated but the results can only be analyzed in the dynaTrace AJAX client. I need to run these daily and be able to show a report of historical performance. Is it possible to extend the tool through some sort of a listener to export/save some high-level page load time info? Thanks.