Outdated content

Icon

See Test Automation Samples Library for Selenium Integration Samples

If you are not familiar with what dynaTrace can do in Continuous Integration I recommend reading my post dynaTrace in Continuous Integration - The Big Picture

Why integrating dynaTrace with Selenium?

Modern Web Applications leverage JavaScript and AJAX (XHR) to only download the data that is really needed when users execute different Use Cases on a web site. Instead of navigating to a new page every time a link is clicked it is more common that the Page/URL stays the same and dynamically loaded data, e.g: result of a search gets applied to the current page.

When developing test scripts it is also very common to work Use Case oriented. You end up creating functions such as "Logon", "Search", "Product Details" or "Check out" which can then be called from larger test cases. When integrating dynaTrace with your functional tests dynaTrace analyzes the browser and server activities that belong to a Use Case. In dynaTrace we call them Timers. Timers automatically get analyzed for every test run. dynaTrace will learn the expected behavior within a Timer, e.g.: How many JavaScript files get downloaded for the Login Process. In case of a regression or change of the application dynaTrace will automatically detect the change and notify you, e.g.: We have 20 more images on the Product Page as in the previous test.

clickThroughMenus is a Use Case that has a big change in Server-Time compared to the previous test run

Timer Names

In order for dynaTrace to know the Timer Names for the individual Use Cases the dynaTrace Browser Agent defines a JavaScript function called _dT_setTimerName. Browser Testing Tools typically support injecting JavaScript while running the test. The Timer Name can also be passed as additional URL parameter when browsing to the initial URL. More details on User defined Timer Names, how to set them and how to group and build a hierarchy in the Online Documentation.

The Sample Selenium Script

Let's assume we do have the following Selenium Script that tests our GoSpace Sample Application:

Using the dynaTrace Selenium Runner

The easiest option is to use the dynaTrace Selenium Runner (com.dynatrace.webautomation.DynaTraceSeleniumRunner). This runner will automatically set the test method name as timer name. It does this by capturing the test method name and, when executing the "open" method appends it to the URL. Here is how the script looks like when using the dynaTrace Runner:

If you already have a custom Selenium Runner you can either merge the necessary calls from DynaTraceSeleniumRunner into your Runner or use one of the two other options you have.

Using the dynaTrace Selenium Helper

The DynaTraceSeleniumHelper (com.dynatrace.webautomation.DynaTraceSeleniumHelper) is a class that provides the functionality to set timers from existing scripts without using the dynaTrace Selenium Runner. Here is how to use the DynaTraceSeleniumHelper on the original sample script:

DynaTraceSeleniumHelper.forSelenium returns an instance of the Helper Class encapsulating the passed Selenium instance. The helper class provides an "open" method that automatically sets the current test method name as Timer Name. It also provides addTimerName and removeTimerName for subtimer definition.
The "open" method also allows you to specify a custom timer name. The method setTimerName also allows you to change the current Timer Name at any time.

Here is the Browser Summary Dashlet when executing a set of tests that have been converted to use the DynaTraceSeleniumHelper. You can also see the Subtimer "Do Search" as shown in the Selenium Script:

Using DynaTraceSelenium instead of DefaultSelenium

The third option is to use DynaTraceSelenium (com.dynatrace.webautomation.DynaTraceSelenium) instead of your DefaultSelenium instance. The only thing you have to change is to create an instance of DynaTraceSelenium. It overwrites the open method and also provides timer functions. You can also combine it with the DynaTraceSeleniumHelper class if you want to.

Every open method will automatically start a new timer with the name of the current test method as timer name.

Conclusion and Next Steps

As you can see, it is easy to include dynaTrace into your Selenium Tests. We provide multiple different approaches on how to set the Timer Names.
Download the latest version of our Demo Applications which including a full featured sample or download the Selenium and WebDriver Integration which only includes the Helper classes as described in this article.

 

Selected Topics

Not Logged In? Customers and AJAX Edition Users Login with your Community Account