This 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:
- Recording
- Filters
- Playback
- Variables and Constants
- Variable Setters
- Replacement Rules
- Validations
* NOTE: Screenshots were taken using PesterCat for OSX.
PesterCat 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. You generally do this in the preferences editor for your
web browser.
In FireFox on Windows, you select:
'Tools' --> 'Options' --> 'General' --> 'Connection Settings'
Sometimes proxy settings are controlled by system wide settings for your
operating system. You will need to set the HTTP proxy host to 'localhost' and
the proxy port to '8181' (or whatever port you designated for PesterCat).
Your settings should look something like this:

* NOTE: PesterCat doesn't do SSL, FTP, Gopher, or SOCKS, so leave these settings blank.
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.pestercat.com/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: You may or may not have the favicon.ico step recorded in your demo script. This tutorial was created with Mozilla Firefox which downloads favicons more aggressively than some other browsers.
In 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 architecture 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:
- Style sheets (.css files)
- GIF images (.gif files)
- Favicons (favicon.ico files)
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:
.*\.gif
Then click the 'Filter URLs' dialog. The filter should look like this:

Now add two more URL filters with the following Regular Expressions:
.*\.css
.*\/favicon\.ico
When 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.pestercat.com/demo.php. Login and then click stop in your PesterCat recorder. This time your recorded script should look like this:

The filters eliminated three of the script steps that contained images and a style sheet.
You 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 these 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 blue 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 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.servername.com/index.html
Here is the example URL written using a variables or constants:
http://$hostname/index.html
Variables 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.
In 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'
Create a variable setter that contains the following:

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 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.servername.com:10080/appName/index.html
automatically look like this during recording:
http://$hostname:$port/$app/index.html
The 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.pestercat.com/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.
PesterCat validations can be used to validate HTTP pages and perform backend database validations. There are four main types of validations currently available
in PesterCat:
- Regular expression (REGEX) validations for HTTP page responses.
- XPath validations for HTTP page responses.
- SQL validations can be used to validate backend databases.
- Script validations can be used to create custom code validations written in Javascript.
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.