Accessing Body from WatiN

We have added many WatiN tests over the last few weeks. Performance is becoming more important every day. Several of our tests must ensure that a class is present in a body tag.

protected void AssertSiteModeEquals(string mode){    StringAssert.EndsWith(mode, ie.Element("body").ClassName);}

This block of code took several seconds to execute. Accessing ie.Element is a very slow operation in WatiN. Below is a much faster way of performing the same assert.

protected void AssertSiteModeEquals(string mode){    StringAssert.EndsWith(mode, ie.HtmlDocument.body.className);}
Advertisements

One Response

  1. […] All Element methods are slow. Always be as specific as possible (even when accessing the body element). […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: