Complex Testdata in Squish

Complex Testdata in Squish

Squish has support for testdata: you can specify a tab (or comma) separated list of data, store it in an external file and iterate over each line of it with its scripting API (and access the fields of each line). Squish also has a builtin editor to edit such testdata.

So with Squish it is easy to have testdata you can store in a table. However, when I write a test I have the need to have more complex testdata; testdata that can’t be easily represented in a table (e.g. data where one field would be a list again). Am I lost? No.

What I do in these circumstances is to use the script’s language feature to write down the testdata in script statements. I typically use Python, so here is an example of a dataset I recently used for a Squish test (I am testing the recording of the new to come Squish for Mac editon):

{
    'action': 'recordKeyboardEvent(":Squish Application Test Window", "a", "a", 0)',
    'log': [],
},
{
    'action': 'recordKeyboardEvent(":Squish Application Test Window", "b", "b", 0)',
    'log': [],
},
{
    'action': 'recordMouseButtonEventOnTarget(":Button 1", 0, 0)',
    'log': [
        {
            'method': 'type',
            'arguments': [
                'qualifiedName(":Line Edit 1")',
                'ab',
            ],
        },
        {
            'method': 'clickButton',
            'arguments': [
                'qualifiedName(":Button 1")',
            ],
        },
    ]
},
{
    'action': 'flushCachedEvents()',
    'log': [],
},

So this one dataset is a list of dicts. Each dictonary has two fields action and log. The action is what the actions the test should carry out and log is the result we expect after the action was done (the log itself is a list of dictionaries again).

I stored the above script fragment in the testcase’s testdata directory with the name cocoaTextFollowedByMouseClick.py. This is one of many datasets I have. In my testcase, I have then the following code to iterate through the testdata:

def main():
    dataSets = (
        ...
        'cocoaTextFollowedByMouseClick',
        ...
    )
    for setName in dataSets:
        data = open(findFile('testdata', setName + '.py')).read()
        dataSet = eval('(%s)' % data)
        executeOneDataSet(setName, dataSet)

As you can see, I have a list of all the datasets I want to test. For each of these, I load the file from the testcase’s testdata directory and call eval() on the string. Now I have the data in a Python data set and I can easily use the Python methods to iterate through lists or access the elements of a dict.

So after all, it is not hard to use more testdata that is more complex than just a table in Squish. But what I would ask you as the reader and user of Squish: do you also have the need for more complex testdata? And do you wish that Squish has more support for this than the way I just described (if you think so, what would be your wishes for it)?

PS: In the above dataset I posted, you can also see how to do keyword-driven with Squish: the action entry in the dict, e.g. is a script statement that is later evaluated in the test script with Python’s eval() to carry out the action (a function call to recordKeyboardEvent(), e.g.).