Register an application through a test script

Register an application through a test script

Motivation

I am asked fairly frequently, “The path to my application changes on a daily basis. How can I automatically update the path to the squishserver?”

This article will show how to change the path to the Application Under Test via a test script. I will use Squish for Java, JavaScript, and the Swing addressbook example application to demonstrate this. I will refer to the ‘Application Under Test’ simply as the ‘AUT’ from now on.

Example

I start with the squishserver command to register an application. This leads to a changed path for already registered applications.

function registerAut(autName, pathToAut){
    cmd = 'squishserver --config addAUT "' + autName + '" "' + pathToAut + '"';
    capture = OS.capture(cmd);
}

To execute the function shown above, the path to the AUT has to be determined. To do so for this example, I created the following function:

function getPathToAut(autName) {
    pathToAut = OS.getenv("SQUISH_PREFIX") + "\\examples\\java\\addressbook\\";
    return pathToAut
}

The last missing step is to start the AUT after the registration. The complete code looks like this:

function main() {
    registerAndStartMyAut("AddressBookSwing.jar");
    snooze(1)
}

function registerAndStartMyAut(autName) {
    pathToAut = getPathToAut();
    registerAut(autName, pathToAut);
    return startAut(autName)
}

function getPathToAut() {
    pathToAut = OS.getenv("SQUISH_PREFIX") + "\\examples\\java\\addressbook\\";
    return pathToAut
}

function registerAut(autName, pathToAut){
    cmd = 'squishserver --config addAUT "' + autName + '" "' + pathToAut + '"';
    capture = OS.capture(cmd);
}

function startAut(autName) {
    return startApplication('"' + autName + '"')
}

As you saw above, to register an application through a test case isn’t a big deal. The more complicated part is to determine the path to the AUT correctly.

The given code is transferable to all other Squish editions or scripting languages without any problem.

Christian Franke started as a support engineer in 2017 right after finishing his Bachelor's degree. Since then, he's taken over sales-relevant tasks as well as conducting trainings and offering consulting from time to time.

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*