Page-specific actions in Selenium NUnit crawler

In my previous posts on Selenium and NUnit I described how to crawl your web application by following all the links on every page, and hashing the visited addresses.

My crawler can optionally reduce a page’s URL to a kind of signature consisting of the address and the names of its parameters. For example, the URL


would be reduced to


If we want to add page-specific actions, the simplest approach is a huge switch/case statement which finds us the actions to be performed depending on the current address (and thus, depending on the signature of the current URL). Let’s define

delegate void PageTest();


string sUrlPattern = sUrl.Substring(sUrl.LastIndexOf("/") + 1);
if (sUrlPattern.Contains("?"))
    sUrlPattern = Regex.Replace(sUrlPattern, "=.+?&", "&");  // non-greedy
    sUrlPattern = Regex.Replace(sUrlPattern, "=.+", "");
List<PageTest> lifnTests = new List<PageTest>();

We can then add page tests to the list:

    case "mypage.aspx?page&section":
      lifnTests.Add(delegate() { TestMyPageWithPageAndSection(); });

The List<PageTest> now contains all the test functions that can be called because of the parameters of the current page.

foreach(PageTest pt in lifnTests)

An action consists of the usual Selenium commands:

private void TestMyPageWithPageAndSection()

Of course, the necessary try/catch blocks, logging, etc need to be added to let NUnit run through an application test in case of an error.

1 thought on “Page-specific actions in Selenium NUnit crawler

  1. HI

    I am Naveen.I had learnt ,how to run selenium IDE & selenium RC.The main thing is how to generate a Test Report after the running the test Succesfully.I am using the Selenium RC and NUNIT for the testing .How to get the Test actions and descriptions in a Report.And another thing is How to run Selenium Core and when it is useful .And suggest some more open source tools for testing .Net and Java Projects ………………………..

    Try to help me…..


Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.