Sunday, June 15, 2008

Testing ASP.NET Ajax autocomplete extender with Watin

Back to our Autocomplete extender example.

One of the biggest reason we hesitate to unleash the ASP.NET Ajax toolkit onto our project is potential performance shortcomings. The load test would be nice addition to the test harness. We do not run Team System (not that we would have Visual Studio Test Edition available anyway) so we can judge TFS load testing suckness from the words of others.

The Watin tool seems to be a very good candidate for the black-box testing. My first attempt to run simple test wasn't any success.

[Test]
public void FirstTest()
{
IE ie=new IE("http://localhost/Prototype.WebUI/TestDataEntry.aspx");
ie.TextField(Find.ByName("ctl00$contentMain$txtManufacturer")).TypeText("n");
Thread.Sleep(200);
ie.TextField(Find.ByName("ctl00$contentMain$txtManufacturer")).TypeText("nis");
Thread.Sleep(200);
ie.Close();
}

When test runs, I could see that active fields are highlighted in a IE window, text being typed without any sign of Ajax. It's either Watin is missing events (which was unlikely knowing Jeroen's thoroughness) or ASP.NET Ajax techniques are too exotic to catch on (which is more than possible with Microsoft's history of lack attention to details).

After lengthy investigation and extensive Reflector code digging I found that Autocomplete extender attaches itself to the KeyDown event of the textbox so from this side we were more or less clear. Then I remembered my own adventures with ASP.NET testing and decided to kick other tires - play with runtime events reanimation. To make long story short - the following line brought my Ajax back to life for the Watin testing:

txtManufacturer.Attributes.Add("onkeydown", "");

That's right - "attach nothing to KeyDown event" - and all will start working as expected. Now we can load test questionable Ajax performance.

I didn't have time to investigate the differences in the generated code but I would start from blaming the ASP.NET Ajax code generation for this glitch. I bet, like with the SQL Data Source Wizard bug, somebody somehow overlooked some possible combinations.

P.S. I can't wait to lay my hands on Component Art components.

2 comments:

Chris Barrow said...

Nice investigation and resolution. Do you recommend WATIN as a test tool? Microsoft just continues to lose its credibility with it's pathetic QA. Quite frankly I think there are far better ajax frameworks out there to use...

Michael Goldobin said...

I would love to see Component Art version which is apparently JSON with Web Services. ASP.NET Ajax looks similar but...
Watin seems like a good tool for the load testing. The NUnit 2.5 supposedly will support parallel distributed testing and if understand it right you would be able to load your pages with Watin.


© 2008-2013 Michael Goldobin. All rights reserved