ABOUT US

|

SUPPORT

|

BLOGS

 

 

DEVELOPER BLOG

 

 

 

 

 

 

 

Testing complex Ajax content

 

Anthony Scotney

 

 

 

 

 

One of the biggest pains when testing web applications is hitting the wall with Ajax and client-side dynamic content. The big problem from an architectural standpoint is that at a DOM level it is incredibly difficult to determine a significant action from an insignificant action. If one were to record every minor browser DOM mutation, the output Test Case would be hundreds of lines long, which whilst amusing for about 5 seconds, is completely unmaintainable.

The Ajax page:

Why Google Finance: because it has an Ajax push model and it is not a “soft target”. Ajax is utilized when one enters text into the textfield (an Ajax powered drop-down is shown with many different stocks). The Ajax powered textfield is below in all its glory;

The test-steps..

We recorded a Test Case with LiquidTest using the Firefox browser with the following actions;

  1. Load http://finance.google.com
  2. Click in textfield and type BH
  3. Click second BHP response in Ajax drop-down
  4. When page loads assert that ASX:BHP is in the textfield

What we got:

The Test Case that LiquidTest generated is below (notice the concise actions):

	
	@Test
	@Browsers("Firefox2.0")
	public void testMethod()
	{
		browser.load("finance.google.com");
		browser.click("searchbox", 0);
		browser.type("B");
		browser.expectingModificationsTo("ac-list").type("H");
		browser.expectingLoad().click("id('ac-list')/DIV[2]/DIV/SPAN[2]");
		assertEquals("ASX:BHP", browser.getValue("searchbox"));
	}

And?

What is the big deal? Well, it replays the actions exactly as described above. But the more interesting question is why? LiquidTest is built upon an Expectation Model. An Expectation model is a model that “expects” significant actions before proceeding. There are no random sleeps involved. If LiquidTest does not get the Expected Event it does not proceed. What this means is that with Expectations test cases are robust. How? LiquidTest has deep hooks into the target browser and a complex rules engine. We keep the complexities internal to LiquidTest to provide you, the user with robust and succinct (if they are not succinct they are difficult to maintain!) Test Cases.

In the example above, you can clearly see that as the user types significant events occur (Ajax) and LiquidTest records an expectingModificationsTo on the relevant element;

browser.expectingModificationsTo("ac-list").type("H");

Next an expectation (expectingLoad) is set on the Drop-down selector. This expectation states that when the click is sent, a page is expected to load (note: If you enable URL validation, you will see the full URL of the expected page in the expectingLoad(“http://www.google.com/finance”)).

browser.expectingLoad().click("id('ac-list')/DIV[2]/DIV/SPAN[2]");

Then finally there is the assert to ensure the content is present.

DONE!

LiquidTest has been a long time in development. We could have released the product 12 months ago. In-fact submitted a JavaOne paper covering LiquidTest over 12 months ago. We decided to hold back the LiquidTest release a year to improve the internal rules engine (it is not perfect, but you can bet your backside we are doing our best to get it there).

 

 

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • DZone
  • TwitThis
  • email
 Comments (4)

 

 


 

 

Comments:

  1. very very nice~

    Comment by Seven on March 18, 2009 at 1:27 am

  2. This was a problem I faced with script execution within browsers a few years ago, some hooks are easier to get than others! You say this test case is robust but what happens if the second item in the list changes for whatever reason? Wouldn’t it be ideal to hook the text or an identifier for the text rather than simply click the “second item in list”?

    Comment by Jason on April 30, 2009 at 11:51 pm

  3. Thanks for the feedback Jason. If the second item in the list changes, there is not issue at all, the change will be picked up in the assert (the purpose of the assert). If we were to reference the item as “ASX:BHP” it would be more granular and would fail on a step where textual content changes may not be relevant.

    That said, LiquidTest is a flexible framework and address referencing can be customized in any way you like.

    Comment by Anthony Scotney on May 1, 2009 at 12:14 am

  4. Hi Anthony, yeah the assert would pick it up, it is just that the recorder didn’t seem to give any distinction between clicking on the second item and what that second item actually contained (or pointed at), which might be an area of weakness. A user would click on something that they want, whether it was placed 3rd in the list or 6th. Is there any advantage in being able to detect what they wanted in the recorder and playing it back so that list order (or other minor things) doesn’t affect it? Maybe it is too much hassle for the payoff since it is just for a test case.

    Comment by Jason on May 1, 2009 at 12:32 am

Add Comment..

 

 

About this blog..

 

This is an informal place for the team at JadeLiquid to discuss software, the rotation of the earth and other things usually discussed in the JadeLiquid corridors.

 

 

 

Subscribe: By Feed  By Email

 

 

 

 

 

Categories

 

 

JadeLiquid

LiquidTest

 

 

Software Testing

 

 

WebRenderer

 

 

 

 

Recent Posts

 

 

Selenium 2 / WebDriver support coming soon to LiquidTest..
Running Selenium Tests from the Command Line
LiquidTest 3.0 with Selenium support ships!
Setting up Atlassian Bamboo to run automated Web 2.0 tests
888 installer builds and 7469 code checkins later LiquidTest 2.0 ships!

 

 

 

 

 

Popular Posts

 

 

Testing complex Ajax content
Setting up LiquidTest with Subversion and Hudson (Continuous Integration) - part 1
Creating Data-Driven Functional Tests with LiquidTest
One tool to rule them all - Reducing team division
Setting up LiquidTest with Subversion and Hudson (Continuous Integration) part 2
Is manual testing crippling your development project?
Eclipse and LiquidTest UI Introduction
Protecting investment: Tests that do not break with page changes
Testing Dynamic Elements – Having a Plan B
Running Selenium Tests from the Command Line

 

 

 

 

 

Archives

 

 

May 2011 (2) April 2011 (1) November 2010 (2) March 2010 (1) February 2010 (1) November 2009 (1) October 2009 (1) September 2009 (2) August 2009 (1) July 2009 (1) June 2009 (1) April 2009 (1) March 2009 (1)

 

 

 

 

 
   News / Events

 

 > LiquidTest EOL Announcement - Info
 > LiquidTest Release 3.0! - Available
 > Visual Studio Plugin Released! - Release
 > Cruise Control .NET Integration - Info
 > Automate your Dev/Test Process - Webinar
 > Is manual testing crippling your project? - Blog
 > Testing complex Ajax content - Blog
 
 
   Recently Added Content  
 
 > Run LiquidTest's on Selenium RC/Server - Info
 > Setting up LiquidTest with Maven - Blog
 > Officially Supported Ajax Frameworks - Info
 > Atlassian Bamboo Integration - Tech
 > Setting up LiquidTest with SVN and Hudson - Blog
 > Creating Data-Driven Functional Tests - Blog
 > Reducing Test Maintenance - Blog
 
 
  Copyright JadeLiquid Software - 2013