Web Page Example


We will look around the fit website.

Oops. This doesn't work yet because the java HTTP object doesn't seem to send along the Host field on a HTTP GET so c2.com's web server can route the request to the correct virtual server. Bummer.

http:run.cgi

For now we look around Google instead.

fit.ActionFixture
start eg.Page  
enter location http://google.com
check title Google
enter link Jobs
check title About Google
enter link Press
enter link Review
check title Google Press Room

Here is what this page is suppose to look like.

See the source.


Java gurus suggest that the problem is related to weak libraries in the kaffe implementation and that either sun or ibm jvm will make problems go away.

Testing server side java ...

fit.ActionFixture
start eg.Page  
enter location http://fit.c2.com
check title Wiki: Welcome Visitors


I wrote this example to help get WilkesJoiner and JimWeaver started with our framework. They didn't seem to need it. While I'm still debuging they are distributing a similar fixture exploiting their jwebunit facade to HttpUnit. Nice work guys. -- WardCunningham


In this example we will use a fixture to look around the web. Developers of web applications often get the idea that this is a good universal interface to their programs. We don't think so. You are far better off testing your server site objects from fixturing running on the server. But you will probably want to do some testing over http so we show here how it can be done.

You can run this test on the fit.c2.com server with the usual run.cgi command. This will have c2.com acting as a client on your behalf.

http:run.cgi

We use actions to start eg.Page, our web browser like fixture. We can enter location, a web address, or link, which follows a link on the page to a new location. When we enter a link, the fixture searches the current page for an anchor that starts with the entered text. You only have to enter enough to be unique. Then it retrieves that page.

fit.ActionFixture
start eg.Page  
enter location http://fit.c2.com
check title Wiki: Welcome Visitors
enter link Example
check title Wiki: Example Tests
enter link Simple
check title Wiki: Simple Example

The eg.Page fixture is also a row fixture. Here we use it that way to check on the rows of the SimpleExample.

eg.Page
numerator() denominator()
1000 10
1000 7
1000 0
1000 .001
-1000 10
0 0

We left out the pentium bug values on purpose just so you would know we really are reading from that page. We will follow the pentium bug reference just to show that we can read from other servers.

fit.ActionFixture
enter link http://www.cs.earlham
check title Bugs in the Intel Microprocessors
enter link Main
enter link Dusko
enter link web
check title WebDB - Version 3.1

There are a couple of things that are not quite right about this example.

  • It seems odd to say | enter | link | foo | when we want to click a link. The reflection that ActionFixture is doing for us isn't really helping us out much.

  • Our fixture only knows one query and that assumes we are on a page with a very specific table.

See source.


It would be neat to see some tests of an XML interface. Google has one.

 

Last edited November 13, 2002
Return to WelcomeVisitors