The Remote System API can be used to start applications on a remote system. As you can see in the picture below the Remote System API is centered around the Squishserver. This makes it possible to interact with the filesystem and to start processes on the system the Squishserver is running on. This limits the use of the Remote System API to systems the Squishserver is compatible with, which excludes mobile devices. This post will explain some general issues when starting a process via the Remote System API, but will mainly focus on Windows.
Using the Remote System API to start a process on the remote machine
To start a process on the remote machine you can use the RemoteSystem.execute(…) command. Using this command is a bit more complicated, because there are a couple of things to consider. Since it is important to know if the application got executed successfully, RemoteSystem.execute(…) is expected to return the exit code of the process started, as well as the command line output and potential error information. But this also means that the process started needs to return in a short time frame and shouldn’t block the test script execution. You don’t have to consider this when you start smaller command line tools, that return immediately or within the time frame specified by the
timeout option, that can be passed to the
The following example shows a basic execution of the
ipconfig command and logs the result:
# -*- coding: utf-8 -*- from remotesystem import RemoteSystem def main(): try: remotesys = RemoteSystem() #call the ipconfig command on the remote machine (exitcode, stdout, stderr) = remotesys.execute(["ipconfig"]) #verify the exitcode test.verify(exitcode == "0", "Command executed") #log the output of the ipconfig command test.log( stdout ) except Exception as e: test.fail("RemoteSystem error", str(e))
If we now try to call the very basic command line tool
date like this
cmd date /T, we will already run into the problem that this command will not return in time and RemoteSystem.execute(…) will run into a timeout. The reason for this is that
cmd will just wait for the next command after executing
date /T, but will not return. So what we actually need to call is
cmd /c date /T. The command line option
/c will run the command and then terminate immediately.
# -*- coding: utf-8 -*- from remotesystem import RemoteSystem def main(): try: remotesys = RemoteSystem() #call the date command on the remote machine (exitcode, stdout, stderr) = remotesys.execute(["cmd","/c","date","/T"]) #verify the exitcode test.verify(exitcode == "0", "Command executed") #log the output of the date command test.log( stdout ) except Exception as e: test.fail("RemoteSystem error", str(e))
Using the Remote System API to start an AUT
To start the AUT using the Remote System API we can use
cmd /c in combination with the
start command to detach the AUT from the current execution context and make RemoteSystem.execute(…) return immediately while the AUT can keep running on the remote system.
Another important thing to note is that when supplying double quoted parameters to the
start command the first parameter isn’t the application to start but the title of the newly created window. So the command that needs to be used to start the AUT is
cmd /c start "" "<path to your AUT>".
Of course we also want to be able to attach to the AUT we started, so we shouldn’t start the AUT directly but through Squishs
startaut command. To determine the location of the Squish installation on the remote system we can also use the Remote System API ( RemoteSystem.getEnvironmentVariable(…) ).
# -*- coding: utf-8 -*- import os from remotesystem import RemoteSystem def main(): try: remotesys = RemoteSystem() pathToSquish = remotesys.getEnvironmentVariable("SQUISH_PREFIX") pathToStartAUT = os.path.join( pathToSquish, "bin\\startaut.exe" ) pathToAUT = os.path.join( pathToSquish, "examples\\qt\\addressbook\\addressbook.exe" ) #command array cmd = [ "cmd", "/c", "start", "", pathToStartAUT, "--port=55531", pathToAUT] #set current working directory on remote system cwd = os.path.join( pathToSquish, "examples\\qt\\addressbook" ) #start the AUT on the remote machine (exitcode, stdout, stderr) = remotesys.execute(cmd, cwd) #verify the exitcode test.verify(exitcode == "0", "AUT started successfully") #connect to the started AUT attachToApplication("addressbook") #basic automation clickButton(waitForObject(":Address Book.Open_QToolButton")) mouseClick(waitForObjectItem(":stackedWidget.listView_QListView", "MyAddresses\\.adr"), 52, 13, 0, Qt.LeftButton) clickButton(waitForObject(":QFileDialog.Open_QPushButton")) except Exception as e: test.fail("RemoteSystem error", str(e))
Further required parameters for your AUT can just be added at the end of the command array.