O'Reilly logo

PHP Hacks by Jack D. Herrington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #82. Test Your Application with Simulated Users

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?

Particularly with JavaScript-heavy applications, you need something that will actually click on buttons to ensure that your application does what it should.

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.

The test agent driving the browser

Figure 8-2. The test agent driving the browser

The Code

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required