Automating multiple applications with multiple Squish installations or editions (Windows, Web)

Last edited on

Overview

The information below describes the setup for Squish for Windows and Squish for Web, but the instructions are not limited to these Squish editions, but apply to all/most editions of Squish.

Basic setup

Recording

Recording in the Windows application

Example recording:

def main():
    startApplication("AddressBook")
    clickButton(":New_Button")
test.py

Recording in the Web application

Example recording:

def main():
    startBrowser("www.froglogic.com")
    waitForContextExists(":index.html")
    clickLink(waitForObject(":Customer Login_A"))
    clickLink(waitForObject(":Squish_A"))
test.py

This recording has to be integrated into the Squish for Windows test suite now, which is a simple copy & paste operation at first:

def main():
    startApplication("AddressBook")
    clickButton(":New_Button")

    startBrowser("www.froglogic.com")
    waitForContextExists(":index.html")
    clickLink(waitForObject(":Customer Login_A"))
    clickLink(waitForObject(":Squish_A"))
test.py

Then we add these lines (which are the equivalent of “startApplication()” but for the web browser):

testSettings.setWrappersForApplication("__squish__webhook", ("Web"))
ctx_web = startApplication("__squish__webhook", "localhost", 1234)

So the resulting script looks like this:

def main():
    ctx_win = startApplication("AddressBook")
    clickButton(":New_Button")

    testSettings.setWrappersForApplication("__squish__webhook", ("Web"))
    ctx_web = startApplication("__squish__webhook", "localhost", 1234)
    startBrowser("www.froglogic.com")
    waitForContextExists(":index.html")
    clickLink(waitForObject(":Customer Login_A"))
    clickLink(waitForObject(":Squish_A"))
test.py

As you can see we also modified the startApplication() lines to catch the return values, which are the application context of the Windows and web applications. With these application contexts we can switch between automating each application, should it be required, by using the setApplicationContext() function.

Replay

"<squish_for_web>/bin/squishserver" --verbose --port 1234

You can switch between application contexts via setApplicationContext():

def main():
    ctx_win = startApplication("AddressBook")

    ...

    testSettings.setWrappersForApplication("__squish__webhook", ("Web"))
    ctx_web = startApplication("__squish__webhook", "localhost", 1234)

    ...

    setApplicationContext(ctx_win)

    ...
test.py

Further information