After week of running UI tests as a part of continuous integration build without modifications in SUT code I realized that significant part of tests runs is failed! I know that UI tests are erratic by their nature, because they have a lot of dependencies, which you can’t control, but 40% of failures is too much. Also, when i run this tests on local without Selenium Grid cluster, all tests always pass.
This needs to be fixed. Lets check error messages:
1) Test CheckNameOnLoginPage: ERROR: Element xpath=/html/body/form[@id='form1']/div[3]/table/tbody/tr[2]/td[2]/input[@id='txtUser'] not found
2) Test CheckCurrentUserName: System.Exception: Error while executing command AssertUserName ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Selenium.SeleniumException: Timed out after 20000ms
3) Test NewlyAddedUserAppearsInUsersList: Selenium.SeleniumException: Timed out after 20000ms
Notice that always appears in random tests and always connected to absence elements. I observed test runs and found out that sometimes IIS error page with message “403.9 Access Forbidden Too many users are connected” appears in browser.

Here is it. IIS in windows of “professional” version has a limit of 10 users and therefore sometimes whole page is not loaded or just several JavaScript files and this breaks whole client side application. Here is the IIS log:
08:51:30 10.6.9.180 POST /SampleApplication/Login.aspx 403
08:51:30 10.6.9.180 GET /SampleApplication/Login.aspx 403
….
15:10:57 10.6.24.72 POST /SampleApplication/Login.aspx 302
15:10:57 10.6.24.72 POST /SampleApplication/Login.aspx 302
15:10:57 10.6.24.72 GET /SampleApplication/Home.aspx 200
15:10:57 10.6.24.72 GET /SampleApplication/Home.aspx 200
15:10:57 10.6.24.72 GET /SampleApplication/js/Frameworks/jquery-1.3.1.js 200
…
15:10:57 10.6.24.72 GET /SampleApplication/js/Services/Services.js 403
…
It is only needed to upgrade to IIS 7 to fix it. But i already spent a lot of time (about 5 hours) to find out what happened and do not want to deal with this problem in future.
First let’s learn tests to recognize IIS error pages:
private static void AssertErrorPage<TT>(TT target) where TT : PageBase, new()
{
var bodyText = target.Selenium.GetBodyText();
if (bodyText.Contains("Server Error in "))
{
Assert.Fail("Server error while navigating\r\n\r\n {0}.", bodyText);
}
if (bodyText.Contains("Internet Information Services") && bodyText.Contains("Microsoft Support"))
{
Assert.Fail("IIS error while navigating\r\n\r\n {0}.", bodyText);
}
}
And include iis log analysis in continuous report. LogParser application can be used for this purposes – it supports SQL – like queries to logs. Here is sql to select log items from time to time into xml:
SELECT *
FROM %logdir%\ex%today%.log
TO %reportsdir%\extracted_iis_log.xml
WHERE TO_TIME(time) BETWEEN TIMESTAMP('%starttime%', 'hh:mm:ss') AND TIMESTAMP('%endtime%', 'hh:mm:ss')
All details how to run logparser in nant script can be found here: http://code.google.com/p/design-of-selenium-tests-for-asp-net/source/browse/trunk/_build/scripts/continuous/main.build
Xsl to integrate iis logs in CCNET report is here: http://code.google.com/p/design-of-selenium-tests-for-asp-net/source/browse/trunk/_build/ccnet/iisloganalyser.xsl
After this modifications we can review reports for bugs mentioned above:
An assertion failed.
IIS error while navigating
The page cannot be displayed There are too many people accessing the Web site at this time. Please try the following:
Click the Refresh button, or try again later.
Open the epbyminw0115.minsk.epam.com home page, and then look for links to the information you want. HTTP 403.9 - Access Forbidden: Too many users are connected
Internet Information Services
Technical Information (for support personnel)
Background:
This error can occur if the Web server is busy and cannot process your request due to heavy traffic.
More information:
Microsoft Support.
And IIS logs are saved for us right in the CCNET report:

Now it is possible to identify where the problem is without deep investigation – all tips and keys to solution are available in report, and if problem will appear in future – it most likely will be resolved with low efforts.
So, the moral is: if you experienced the problem in SUT or tests, first learn your tests to find and alarm about this problem, and only after that fix it. This will help you and your colleagues in future.
Actually here we started to implement analysis of how system behaves in run time, and this is only beginning. In future posts i want to describe now to get statistics from memory dumps and performance probes. This will give developers priceless statistics which will help to understand problems with concurrency, performance troubles, memory leaks, “hard to reproduce” bugs.
All sources are available in
design-of-selenium-tests-for-asp-net solution.