I'm regularly surprised by the low quality of web pages. The problem may arise from the forgiving nature of Browsers, they allow developers to be unaware of the mess they're making. I ran a quick check on more than 50 pages from my favourites list. 90% were such poor quality that they shouldn't have been released. I'm disappointed. Many of the problems can be fixed in a few minutes. If you care there might be an answer here. I've provided further documentation, source code and the like so that you can roll your own tests.

This article is intended for people who:

  1. Are compiling .NET 2.x assemblies
  2. Are using a test framework like NUnit or MBUnit (the example uses the latter)
  3. Are producing programs that write web pages OR are writing web pages OR simply want to check web page quality.

Improving the quality of web pages

Last edited 2006-05-30

Seagulls over St Heliers Bay

I regularly check the quality of markup on web pages. Most are surprisingly poor.

By spending a few minutes per page any developer, can often fix all problems. Even when he can't he is, at least, aware of them.

This article was prepared to help those who want to check page quality, as a normal part of their work.

To illustrate the consequences: If a company has a particularly bad site I often go elsewhere however good the pages might look in the browser. I don't believe many others currently do that. But it could become popular, it's very easy!

To run the checks, as you develop, you need:

  1. A commercial tool available in several versions including a free one. This is the CSE HTMLValidator from AI Internet solutions. A copy of the free version can be downloaded from this site, see bottom of page. (I'd really like you to use this version as I get something back if you later convert it to a paid version!)
  2. An installed copy of the .NET framework version 2.0.
  3. A kit which I've put together, see link at bottom of page. It includes compiled assemblies and the code you need to extend them further!
  4. A development environment that will compile the tests.
  5. A list of the web pages you want to check.
  6. Some time.

The tests can be very simple and a natural part of the development cycle. Two assemblies are provided in the kit one for the free Lite DLL the other for the Standard or Pro DLL. The following code fragment uses the MBUnit framework, with VB.NET (version 8), to test 3 pages. It would be scarcely longer if it tested a dozen pages.

Imports MbUnit.Framework

Imports Com.Decisionz.WebPageEvaluationLite1


''' <summary>

''' Validates miscellaneous HTML pages.

''' </summary>

''' <remarks>

''' This is setup against a customised validator and can be calibrated in the manual/desktop interface. Should be calibrated for any changes in the configuration, and also for different versions of the validator assembly/dll. Should the test pages change check the calibration.

''' </remarks>

<TestFixture(), FixtureCategory("Web Page Validation"), Importance(TestImportance.Critical)> Public Class TestPages


 Dim ValidationTool As Manager = New Manager


 <TestFixtureSetUp()> Public Sub FixtureSetUp()

  ValidationTool.CheckLinks = False


 End Sub


 <RowTest(), Row("http://localhost/ValidateWeb/BaseHTML.htm", 0, 0),_

 Row("http://localhost/ValidateWeb/ErrorXHTML.htm", 20, 20),_

 Row("http://localhost/ValidateWeb/ExtraBackslashHTML.htm", 0, 0)>_

 Public Sub TestPage(ByVal PageUri As String, ByVal ErrorLimit As Integer, ByVal WarningLimit As Integer)

 ' Remove line continuations above to make code work!



  Assert.LowerEqualThan(ValidationTool.Validator.CseResultNumErrors, ErrorLimit, "There are not " & ErrorLimit.ToString & " or less errors... " & PageUri & ".")

  Assert.LowerEqualThan(ValidationTool.Validator.CseResultNumWarnings, WarningLimit, "There are not " & WarningLimit.ToString & " or less errors... " & PageUri & ".")


 End Sub


 <TestFixtureTearDown()> Public Sub FixtureTearDown()


 End Sub


End Class


I encourage those who like to test their code regularly to add tests like this.

For those who are regularly testing large numbers of pages on a web site, say, before and after publication, this technique might also fit in.


Related information

Related Topics