Web Testing TutorialThis tutorial will introduce to many of PesterCat's web testing features and capabilities. The tutorial is intended to be completed in sequence. The following topics are covered:Once you have covered steps in this tutorial check out the PesterCat Ant Automation Tutorial for instructions on using the PesterCat Ant Toolkit with PesterCat DataBox. * NOTE: The screenshots in this tutorial were taken on Windows Vista. RecordingPesterCat contains an integrated proxy server that can be used to record HTTP traffic. The proxy server listens for HTTP traffic on a specific port. By default the proxy server is configured to run on port 8181. This is configurable in the PesterCat preferences editor. You will want to select a port that isn't being used on your machine by another application. Next you will need to configure your web browser to use PesterCat as its HTTP proxy. Instructions for FireFox and IE 7.0 are provided below:
![]()
Instructions for FireFox 3.0.x:
![]()
* NOTE: PesterCat proxy does not record SSL, FTP, Gopher, or SOCKS traffic. Leave settings for any of these fields blank. The PesterCat FireFox Toolbar can however be used to record SSL traffic. Next start the PesterCat application. Once you have opened the application click on the red record button in the toolbar. Now open the web browser you configured above and start browsing the web. Your web requests should be recorded as you browse in the current PesterCat script window. Next clear out the recorded HTTP requests and record a real functional test. You can clear steps for the current script in PesterCat by clicking 'Edit' --> 'Clear All'. Make sure recording is still enabled in PesterCat. Browse to the PesterCat demo application using your web browser http://www./demo.php. This will bring up a login page. Login with the following credentials: Username : pestercat password : demo Next click the yellow stop button to stop recording in PesterCat. You should have the following steps recorded in your PesterCat script: ![]() NOTE: If you are recording this tutorial with FireFox you may have an extra request in the script that ends with 'favicon.ico'. FilteringIn most situations you will want to filter out certain types of web requests from being recorded in scripts. Images, style sheets, and JavaScript are examples of files that you might not want to record in PesterCat scripts. PesterCat contains a configurable filtering system that can be used to keep these types of web requests from being recorded. The following steps will allow you to filter three types of files from your demo script:
First, select: 'Edit' --> 'Preferences' --> 'Filters'This brings up the filters section in the PesterCat preferences editor.
Next click the 'Add' button to create a new filter. Enter the following into the Regular Expressions box: .*\.gifThen click the 'Filter URLs' dialog. The filter should look like this:
Now add two more URL filters with the following Regular Expressions: .*\.css .*\/favicon\.icoWhen you are finished, your filters should look like this:
Now that you now have three URL filters enabled, record your demo script one more time. This time open a new tab by clicking: 'File' --> 'New Tab'Next turn on recording in PesterCat and browse to the PesterCat demo application using your web browser http://www./demo.php. Login and then click stop in your PesterCat recorder. This time your recorded script should look like this:
Notice how the filters prevented script steps for images and style sheets from being recorded. PlaybackYou can playback recorded PesterCat scripts by clicking the green arrow in the toolbar or clicking: 'Actions' --> 'Play'Now run the demo script you created above by clicking one of the 'Play' buttons.
During playback PesterCat uses a lightweight playback engine to run all the steps in the currently selected PesterCat script. When playback is finished a report window will be displayed showing the results. After the script has finished running you should see a results screen that looks something like this: ![]() You can click on links in the playback report to bring up a web browser to view actual page results that were returned during playback. You will notice the results are exactly the same as the ones you receive when you created the demo application. Variables and ConstantsVariables and constants can be used in many of the PesterCat script steps to make execution dynamic and pluggable. In general, anytime you edit something in a text box for a script you can use a variable or a constant. The syntax for using variables and constants is the same. In most cases all you need to do is add a dollar sign in front of the variable or constant name. (see help in PesterCat for more examples)
Here is an example of how variables or constants can be used to create URL's. Here is an example URL: http://my./index.htmlHere is the example URL written using a variables or constants: http://$hostname/index.htmlVariables vs. Constants Constants are generally used for static strings that do not change during script execution. Hostnames and ports are examples of items that may be substituted in scripts as constants. Variables are generally used to make scripts dynamic. When you create variables you can give them default values (which could be blank). At runtime variables can be set using a variety of variable setters. When a variable value is changed during script execution its new value is immediately used in any subsequent script steps. Now you will add a variable to your demo script to see how this works. In the PesterCat script window select and expand the 'demo-page.php' step. This should be the last step in the script. Select: 'Edit' --> 'Add To Request' --> 'Add Param'Create a parameter with the name set to 'username' and the value set to '$username' (a variable). It should look like this:
To add a username variable to your script, click: 'Script' --> 'Variables' --> 'Add'Enter 'username' for the name and 'pestercat' for the value. Then click save. Your variables screen should display the following:
Now run the script by clicking the green script playback button. When the playback report is displayed click the last link in the report to view the demo-page.php link. You should see the following result: ![]() The value for the variable was automatically substituted for the variable string during playback. Variables can be used in any script step in PesterCat that contains a text box. Some of these items include URL's, Parameters, Headers, Validations, and Database queries. Variable SettersIn many cases you will need to make your scripts dynamic. You can use variable setters to capture data from an HTTP response or from a database query to make your PesterCat scripts dynamic. Before you create a variable setter you need to create a new variable. Add a new variable in the PesterCat variable editor called 'timestamp'. You don't need to assign a value to this variable since it will be set dynamically at runtime. The next step is to add a variable setter to your demo script. The login screen for the PesterCat Demo Application displays the current date. In the PesterCat script window select and expand the 'demo.php' step. This should be the first step in the script. Select: 'Edit' --> 'Add To Request' --> 'Add Regex Variable Setter'
Enter the following into the Expression text box: Date\ :\ (.*)<br>Note: the existing of a space after each '\' in the expression above. The variable setter should look like this:
The variable setter you created is using a regular expression to capture the information between the Date : and the <br> tag. How would a tester obtain these tags in order to construct the regular expression? When recording scripts PesterCat will display HTTP response nodes in the script window. You can double or right click these nodes to 'View Source' on the HTML response data. The PesterCat preferences editor even allows you to customize your text editor. Alternately you could just use your web browser view source mechanism to create regular expressions. Next add a comment step to the script to print out your variables value. Select the first step in the script which should be the demo.php. Then Click: 'Edit' --> 'Insert Step' --> 'Insert Comment'Add a comment step that looks like this:
Now run the script by clicking the green script playback button. When the playback report is displayed you should see the following results: ![]() * NOTE: The timestamp value is displayed in step 2 of the playback results above. Replacement RulesReplacement rules can be used to select and replace values within scripts dynamically while recording. Replacement rules are most useful when used in combination with variables and constants. Using replacement rules you can make a request URL like: http://my.:10080/appName/index.htmlautomatically look like this during recording: http://$hostname:$port/$app/index.htmlThe words beginning with $'s above represent variables. By using replacement rules and variables and/or constants you can instantly record a script in one test zone and replay it in another.
Next create a replacement rule to insert a hostname variable into recorded URL's. To create these replacement rules in PesterCat select: 'Edit' --> 'Preferences' --> 'Replacement Rules'This brings up the replacement rules section in the PesterCat preferences editor.
Next click the 'Add' button to create a new rule. Enter the following into the Regular Expressions box: http:\/\/[^\/]*\/Then enter the following into the Replace With box: http://$hostname/Then click the 'Process URLs' checkbox. The rule should look like this:
Now click the save button. Your replacement rules should look like this: ![]() Next turn on recording in PesterCat and browse to the PesterCat demo application using your web browser http://www./demo.php. Login and then click stop in your PesterCat recorder. This time your recorded script URL's should look like this: ![]() The URL's in the script are instantly ready to be used with variables and/or constants as script parameters. ValidationsPesterCat validations can be used to validate HTTP pages and perform backend database validations. There are four main types of validations currently available in PesterCat:
This tutorial will demonstrate how to create a REGEX validation in demo script. In the PesterCat script window select the 'demo-page.php' request step and expand it. Then click: 'Edit' --> 'Add To Request' --> 'Add Regex Validation'Create a validation with the name set to 'Userid Validation' and the expression set to 'username == pestercat' (the text on the page that will be validated). It should look like this:
Click the save button to save the REGEX validation. The script should now look like this: ![]() Now run the script by clicking the green script playback button. When the playback report is displayed you should see the following results: ![]() The validation failed because the page does not contain the 'username == pestercat' string. Next add a parameter to your demo script so that the page will contain the string you are validating. Select and expand the 'demo-page.php' step. This should be the last step in the script. Then click: 'Edit' --> 'Add To Request' --> 'Add Param'Create a parameter with the name set to 'username' and the value set to 'pestercat'. Now click save. The demo script should now look like this:
Now run the script by clicking the green script playback button. When the playback report is displayed you should see the following results: ![]() The validation succeeded this time since the demo application page now contains the correct test string. |
|