---
title: "Web GUI unit testing techniques"
url: "https://osherove.com/blog/2003/10/2/web-gui-unit-testing-techniques.md"
canonical: "https://osherove.com/blog/2003/10/2/web-gui-unit-testing-techniques.html"
published: "2003-10-02T22:59:00"
updated: "2003-10-02T22:59:00"
tags: [".Net Quotations"]
author: "Roy Osherove"
description: "Continuing my Unit testing theme in recent weeks, I've found a very interesting post in reply to a question posted on the XP mailing list . What was so interesting is that the question, and thus the answer, deal with a…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Web GUI unit testing techniques

By Roy Osherove October 2, 2003 In [.Net Quotations](https://osherove.com/blog/category/net-quotations)

**Historical article** · Originally published October 2, 2003; technical details may be outdated.

Continuing my Unit testing theme in recent weeks, I've found a very interesting post in reply to a question posted on the [XP mailing list](http://groups.yahoo.com/group/extremeprogramming/). What was so interesting is that the question, and thus the answer, deal with a side of testing that I never though had clear and obvious testing techniques that enabled true unit testing - testing web GUI. I was wrong. The answer also introduces a couple of unit testing framework tools and techniques I never heard of .How fun it is to discover something new everyday!

**Question:**

\> How does one automate test scripts for GUI's ? Like
\> logging in to a web application, choosing from a menu,
\> keying in data, and retrieving to check if the data is
\> valid, and so forth ?

**Answer:**

Try the [TestFirstUserInterfaces](http://groups.yahoo.com/group/TestFirstUserInterfaces/) mailing list.
One automates tests for those features at three levels:
Test your HTML, before the server sends it. Write XML-compliant HTML, and
use XPath to query out the HTML commands that support your menus and forms.

Use [HttpUnit](http://httpunit.sourceforge.net/) as a "mock browser". It will drive the HTTP protocol, and make
the server think a normal user hits your page. Then write tests that ensure
your page has the controls it says it does.

The third way: Use a scripting language, such as Perl or Ruby, and open
Internet Explorer as a COM server. Drive it to navigate to your page and
download it. Then exploit the same Document Object Model as JavaScript
bunnies use, to inspect the controls as objects, and to click on them.

As usual for much of XP, you can get very far testing as close as possible
to the tested code. Most of the time, prefer the first way. But only the
third way "proves" your Web page does the right thing when clicked.

GUI testing exposes a raft of weird situations. XPath is the best way (I
have found) to test HTML. But most HTML is not XML compliant, under the
naive assumption that permitting programmers to write sloppy HTML will speed
them up. Much attitude readjustments are needed here.

## More in .Net Quotations

[All posts in .Net Quotations](https://osherove.com/blog/category/net-quotations)

- Oct 6, 2003

    ### [Getting a focus on performance - some new pages](https://osherove.com/blog/2003/10/6/getting-a-focus-on-performance-some-new-pages.html)

- Oct 6, 2003

    ### [The "Don box" of windows installer?](https://osherove.com/blog/2003/10/6/the-quotdon-boxquot-of-windows-installer.html)

- Oct 2, 2003

    ### [Real Progress Bars in Web Application](https://osherove.com/blog/2003/10/2/real-progress-bars-in-web-application.html)

- Oct 1, 2003

    ### [Visual Basic Resource Kit (C# developers are not banned!)](https://osherove.com/blog/2003/10/1/visual-basic-resource-kit-c-developers-are-not-banned.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
