Login | Register
My pages Projects Community openCollabNet
[ Installation ] [ Recording and Running ] [ Editing ] [ Recipes ] [ Command Line ]

Compact Script Generator

Standard MaxQ scripts contain several lines of code for each web page fetched. This makes them easy to edit and easy to understand, but it means that you must extensively modify your scripts if you want to change the way they work. For example, you might want to automatically verify that the URL provided in the response for a redirection matches the next request in the script.

MaxQ's "compact" script generator gets around this problem by recording all the information about each request in a single function call. You can override these calls to change their behaviour.

Anatomy of a Compact Test Script

Compact scripts look like this:

 1: # Generated by MaxQ [com.bitmechanic.maxq.generator.CompactGenerator]
 2: from CompactTest import CompactTest
 4: class MaxQTest(CompactTest):
 5:     # Recorded test actions.
 6:     def runTest(self):
 7:         self.get('http://macslash.org/', None, 200)
 8:         self.post('http://macslash.org/search.pl', [
 9:                   ('query', 'Steve Jobs'),
10:                   ], 200)
12:     # ^^^ Insert new recordings here.  (Do not remove this line.)
14: # Code to load and run the test
15: if __name__ == 'main':
16:     MaxQTest('MaxQTest').Run()
1 A comment. The class name (in square brackets) allows MaxQ to work out that this is a compact script. This is necessary if you reload a script you saved earlier and restart recording.
2 Imports the base class.
4 Declares our test class and tells Jython that it is derived from CompactTest. CompactTest is written in Jython and is itself derived from HttpTestCase, the base class for all MaxQ tests.
6 HttpTestCase.Run() calls our runTest() to perform any tests. You could break your tests up into multiple functions called from here.
7 A GET request without parameters. "200" is the response code we expect from the server.
8..10 A POST request with a single parameter. Each parameter is two element tuple (tuples sequences surrounded by round brackets) in a list (lists are surrounded by square brackets).
12 A special comment that MaxQ uses to work our where to insert new lines while recording.
15..16 Creates the test and calls HttpTestCase.Run() when our script is executed. (If you were running the script within a JUnit test harness this would not get called because JUnit would create and run the test.)

Customising Compact Scripts

You can customise compact test scripts by overriding the member function from the base class. (The base class, CompactTest, can be found in MaxQ's jython.) You may want to do this in your test script itself or, if you will be recording many tests with the same needs, create your own base class dervied from CompactTest.

Saving Responses to Files

If you copy this function into your test script then all non-redirection responses will be saved to a file.

Verifying Redirections

This one will check the redirection being returned when the test runs matches the one that was originally recorded.