Use the Internet Explorer automation interface to test your application through the UI.
You can test the back end of an application by using unit tests for the database and business logic code. You can test a portion of the frontend of your application by using robots [Hack #83] that request pages from the server and submit data. But how do you actually test what users would do? How do you simulate the buttons pushed and the boxes filled in by a typical user?
On Windows, you can use Internet Explorer COM objects to tell the IE browser to navigate to your site and even to hit the appropriate buttons. Figure 8-2 illustrates the relationships among the different PHP files used in this hack. test.php and print.php are standard PHP web pages. The testagent.php script is run on the command line and drives the browser to visit these pages, fill in the forms, and check the results.
Figure 8-2. The test agent driving the browser
Save the code in Example 8-7 as test.php. This simple web page is used for testing the agent.
Example 8-7. The first page of the test code
<html> <head> <title>Automated test agent test page</title> <head> <body> <form id="inp_form" action="print.php"> <table ...