Example - Recording on other applications

Skip to end of metadata
Go to start of metadata

Overview

Recording on applications other than the first one is supported but these following restrictions apply:

  • The additional applications must be hooked by Squish.
  • The additional applications must be hooked via the same squishserver instance as the first application.
  • To record on a specific application the current application context must be set to the desired application context and recording be started then.

Here is a rough example that demonstrates the last point:

def main():
    ctx1 = startApplication("application1")
    # Now the application context of application1
    # is the current application context.

    ctx2 = startApplication("application2")
    # Now the application context of application2
    # is the current application context.

    # To record on application1 we must make its
    # application context the current application
    # context:
    setApplicationContext(ctx1)

    # Introduce dummy line that we set a breakpoint on:
    snooze(1)

After setting a breakpoint on the "snooze(1)" line and executing to it you can use Squish | Record Snippet to start recording - on application1.

Note that you can also execute a script snippet like "setApplicationContext(applicationContextList()[0])" in the Script Console in the Squish IDE to change the application context to the desired application.

Advanced setting and waiting for application contexts

Here is an example (it won't work out of the box for you however) that introduces the functions setApplicationContextByName() and waitForApplicationContextByName(), both of which are useful when you rely on the Extra Window Watcher (see Hooking arbitrary Windows applications) to hook into other applications.

(The reason for introducing these functions is that the Extra Window Watcher hooks other (configured) applications more or less at a random time, so you do not know at what point in your test script execution they have been hooked.)

import os
import sys

def main():
    startApplication("eclipse")

    aut_name = "notepad"
    if not waitForApplicationContextByName(aut_name, 3000, True):
        test.fail("Failed to find aut: " + aut_name)
    return

def setApplicationContextByName(aut_name, verbose=False):
    ctxs = []
    for ctx in applicationContextList():
        if ctx.name == aut_name:
            ctxs.append(ctx)
    if len(ctxs) == 0:
        if verbose:
            test.warning("Application context with AUT name not found: " + str(aut_name))
        return False
    if verbose:
        if len(ctxs) > 1:
            test.warning("More than one application context with AUT name found: " + str(aut_name))
    setApplicationContext(ctxs[0])
    if verbose:
        test.log("Set application context (ctx.name): " + str(aut_name))
    return True

def waitForApplicationContextByName(aut_name, timeout_ms=20000, verbose=False):
    i = 0
    while not setApplicationContextByName(aut_name):
        if verbose and i > 0:
            test.log("Could not find application context after " + str(i) + " seconds: " + aut_name)
        if i * 1000 > timeout_ms:
            return False
        i += 1
        snooze(1)
    return True

Further information

Application Context
How to Test Multiple AUTs from a Single Test Script, Using ApplicationContext
How to Use ApplicationContext Objects
setApplicationContext()
currentApplicationContext()
applicationContextList()

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.