Automating multiple applications with multiple Squish installations (iOS, Web)

Last edited on

Overview

The information below describes the setup for Squish for iOS 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 iOS application

Example recording:

def main():
    startApplication("iphonelauncher /Users/myuser/my_application.app")
    ctx_1 = waitForApplicationLaunch()
    clickObject(waitForObject(":Text Controls_UITableViewCell"))
test.py

Recording in the Web application

Example recording:

def main():
    loadUrl("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 iOS test suite now, which is a simple copy & paste operation at first:

def main():
    startApplication("iphonelauncher /Users/myuser/my_application.app")
    ctx_1 = waitForApplicationLaunch()
    clickObject(waitForObject(":Text Controls_UITableViewCell"))

    loadUrl("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():
    startApplication("iphonelauncher /Users/myuser/my_application.app")
    ctx_ios = waitForApplicationLaunch()
    clickObject(waitForObject(":Text Controls_UITableViewCell"))

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

As you can see we also modified one of the startApplication() lines and the waitForApplicationLaunch() lines to catch the return values, which are the application contexts of the iOS and web applications. We do this so that we are later able to switch between the application contexts, should it be required.

Replay

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

You can switch between application contexts via setApplicationContext():

def main():
    startApplication("iphonelauncher /Users/myuser/my_application.app")
    ctx_ios = waitForApplicationLaunch()
    clickObject(waitForObject(":Text Controls_UITableViewCell"))

    ...

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

    ...

    setApplicationContext(ctx_ios)

    ...
test.py

Further information

Recording on other applications

Application Context

How to Test Multiple AUTs from a Single Test Script, Using ApplicationContext

How to Use ApplicationContext Objects

setApplicationContext()

currentApplicationContext()

applicationContextList()