Broadcasting test steps to multiple target systems

Broadcasting test steps to multiple target systems

Creating tests for projects which target several different platforms at once can be quite challenging, even if the different versions of tested software and devices have the “same” GUI.

I will describe an approach to conveniently tackle such scenarios. Using this approach, test steps are automatically broadcast to each target system, and results from each involved target platform are grouped together. This is an alternative to driving the test and verifications separately for each target platform.

I will give a short example on how test scripts can be developed for performing on several platforms within single test steps. One possible use case could be when testing web-based applications where several different browsers can be used from different platforms.

The example I’ll give, assumes that all involved AUTs (Applications Under Test) have been started up already, have been registered as ‘Attachable AUTs’ with running squishservers, and are now waiting for the test to start. (see: squish documentation)

A helper script for managing multiple targets

Let’s begin creating a Python class which can store each application’s ‘name’ and ‘applicationContext’ properties. In addition it holds platform-dependent functions and platform-dependent ‘Name Objects’ that may be needed from the tests:

 
class ApplicationPlatform:
    nam = ""
    ctx = None
    obj = []
    fnc = []
    def __init__(self,appNam,host="localhost",port=4322):      
        self.ctx = attachToApplication(appNam,host,port)
        self.nam = appNam

Also let us define a function which attaches to all tested applications and devices by returning an array of such ‘ApplicationPlatform’ objects, as well as global variables for indexing these:

 
def attachToAllApps():
    return [ ApplicationPlatform("DesktopApp"),
             ApplicationPlatform("IOsDevice"),
             ApplicationPlatform("WinDevice"),
             ApplicationPlatform("AndroidDevice") ]

DesktopApp=0
IOsDevice=1
WinDevice=2
AndroidDevice=3

 

Implementing Multi-Platform callable functions:

Now we can implement verification functions which take ApplicationPlatform objects as parameter, which are able to perform either:

  • On just one distinct platform alone (if just one platform object passed)
  • Or by doing the same actions several times, once per platform (if an array of platforms is passed)

Here are two example functions, the first one automates AUTs to create new folders in the cloud’s file system structure:

 
def createNewFolder(app,fldNam,i=0):
    if typeName(app) == "list":
        if i<apps.__len__():
            createNewFolder(app[i],fldNam)
            createNewFolder(app,fldNam,i+1)
    else:
        setApplicationContext(app.ctx)
        mouseClick(names.button_NewFolder) 
        type(names.lineEdit_NewFolder,fldNam)
        mouseClick(names.button_NewFolder_ok)   

The second example can verify if some folder may exist within these tree views which our AUTs display for accessing files within the cloud:

 
def verifyFolderExists(app,fldNam,i=0):
    if typeName(app) == "list": 
        if i<apps.__len__():
            verifyFolderExists(app[i],fldNam)
            verifyFolderExists(app,fldNam,i+1)
    else:
        setApplicationContext(app.ctx)
        fldObj = names.treeView_folder
        fldObj['name']=fldNam
        if object.exist(fldObj['name']):
            test.passes(app.nam + ": '"+fldNam+"' exists!")
        else:
            test.fail(app.nam + ": '"+fldNam+"' doesn't exist!")   
    return

Now we can implement multiple-platform tests which make use of these functions.

Implementing Multiple-Platform Tests using the import script:

Our functions can be called from a single-platform tests, or from a multiple-platform test, which will run on all of our platforms at once:

 
source(findFile("scripts","ApplicationPlatform.py"))

def main(): 
    platforms = attachToAllApps()

    # 1 add a new folder on just the 'Desktop' application:
    createNewFolder(platforms[DesktopApp],"FolderXY")

    # 2 verify if new folder "FolderXY" exists on all devices connected to the cloud:
    verifyFolderExists(platforms,"FolderXY") 

 

BDD-styled multiple-platform tests are also possible:

Assume following scenario:

Feature: Syncing Documents in a Cloud

Scenario: Synchronize file system between devices

When I create a folder “FolderXY” in the Desktop application.
Then I expect new folder “FolderXY” appears on all devices connected to the cloud.

 

Our step implementations might look like this:

 
@When("I create a folder “FolderXY” in the Desktop application")
def step(context):
    # lets assign our platform array to the BDD context's userData
    # variable, so it also can be used by other steps which follow:
    context.userData = attachToAllApps()

    # we can call our functions to be performed on just one platform:
    createNewFolder(context.userData[DesktopApp],"FolderXY")
    
@Then("I expect new folder “FolderXY” appears on all devices connected to the cloud.")
def step(context):
    # and we can call being performed on all of the platforms at once 
    verifyFolderExists(context.userData,“FolderXY”)

Related links:

https://www.froglogic.com/blog/tip-setting-squish-attach-running-applications-distributed-environment/

https://www.froglogic.com/blog/hybrid-qt-on-android-app-testing/

https://www.froglogic.com/blog/approaches-creating-bdd-scenarios/

 

Attaching to running applications:

https://doc.froglogic.com/squish/latest/rghsa-attach.html#rghsa-attach

 

0 Comments

Leave a reply

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

*