Thursday, November 04, 2010

Using WebDriver and Dynatrace-Ajax to help your Performance test

I have WebDriver Automation test suite in place, So i do not want to create new scripts like Watir or Selenium to do performance test with dynatrace-ajax, just like this post by Watir : http://blog.dynatrace.com/2009/11/04/5-steps-to-automate-browser-performance-analysis-with-watir-and-dynatrace-ajax-edition/

or This one by Selenium 1.0: http://blog.dynatrace.com/2010/05/21/how-to-use-your-selenium-tests-for-automated-javascriptajax-performance-analysis/

I have created Raft which is a Automation fixture by integrating WebDriver with TestNG to help to Automation Test : https://github.com/joychester/Raft/wiki

So I can use WebDriver scripts to help with Performance sanity test now, which save a lot of effort to find out performance problem in early stage and also reuse the scripts already created by QA team :)
First you need to launch Dynatrace-ajax client from : Start-> All Programs-> dynatrace-> dynatrace Ajax Edition

Then you need to add "DT_IE_XXX" Environment Variables to start your test.

This is my Runnner.bat file to start my WebDriver tests:
 @echo off  
 set DT_IE_AGENT_ACTIVE=true  
 set DT_IE_SESSION_NAME=dynaTrace_Automation
 java -cp ..\Classes;..\lib\*; raft.engine.TestEngine > log.txt  

Here is a Sample test script:
 @Test(priority = 4)  
   public void aTest3() throws InterruptedException{  
     WebDriverPlus driver = WebDriverPlus.newWebDriverPlusInstance("IE");  
     //InternetExplorerDriver driver = new InternetExplorerDriver();  
     Thread.sleep(2000);  
     driver.get("http://www.google.com/");  
     Thread.sleep(2000);  
     driver.findElement(By.name("q")).sendKeys("dynatrace");  
     Thread.sleep(2000);  
     JavascriptExecutor js = (JavascriptExecutor) driver;  
     js.executeScript("_dt_addMark(\"start_search\")");  
     driver.findElement(By.name("btnG")).click();  
     js.executeScript("_dt_addMark(\"end_search\")");  
     System.out.println("Its Test3");  
     driver.quit();  
   }  

PS: Here i am using Raft's own method newWebDriverPlusInstance() which can load different browser Type to do your test.
  WebDriverPlus driver = WebDriverPlus.newWebDriverPlusInstance("IE");   
Of course, you can use InternetExplorerDriver directly in sample code which is commented.

Here is a screen shot of Dynatrace-ajax summary generated by my WebDriver test:

Enjoy!

8 comments:

  1. Could you please give me the exact path of the below line and how do we run the batch file

    java -cp ..\Classes;..\lib\*; raft.engine.TestEngine > log.txt

    ReplyDelete
  2. @Uday
    I will update a Sample project on my Github project later(hopefully by the end of this week). So that you can check out that into your local disk, then just write your own tests and run it.
    BTW, it is designed for Windows OS, so if you are using Windows for your testing, then it's for you :)

    ReplyDelete
  3. @Uday,

    I have uploaded the latest sample project on my github: https://github.com/joychester/Raft_Sample_Project
    feel free to download it and try to make it yours.
    Also readme.doc inside, take a look at when you have questions.

    ReplyDelete
  4. Hi, I am using WebDriver driver = new InternetExplorerDriver();
    driver.get(url);
    ..//call for login test
    Adding following lines is not activating the dynatrace plugin.

    set DT_IE_AGENT_ACTIVE=true
    set DT_IE_SESSION_NAME=dynaTrace_Automation

    I also added following two calls but still no luck :( what am I doing wrong?

    set DT_IE_SERVER_HOST=localhost
    set DT_IE_SERVER_PORT=9988

    ReplyDelete
  5. @ndk,

    First you need to launch Dynatrace-ajax application from : Start-> All Programs-> dynatrace-> dynatrace Ajax Edition, then you can run your webDriver test.

    Also, I have upload my sample code on: https://github.com/joychester/Raft_Sample_Project
    you can check it out and run on your local (Windows OS + JDK6 needed)

    ReplyDelete
  6. Hi,
    If you are using eclipse and JUnit to run your tests then set the environment variables in the eclipse ide. So when the script runs the session is automatically captured in the dynaTrace.

    Note: The dynaTrace needs to be running.

    Uday

    ReplyDelete
    Replies
    1. I did the same but the plugin failed to get activated on browser startup. Following is the code I have..


      public class seleniumtest {
      public static void main(String args[]) {
      WebDriver driver = new InternetExplorerDriver();
      driver = DynaTraceWebDriver.forWebdriver(driver);
      dynaTrace = DynaTraceWebDriverHelper.forDriver(driver);
      driver.get("www.google.com");
      driver.findElement(By.name("q"));

      }
      }
      can some one help me out please. I have also set the environment variables as said in the above comments both in the eclipse ide as well as the system environment variables to be on the safer side.

      Delete