Squish/Hooking into Subprocesses: Difference between revisions
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
Sometimes when writing Squish tests the application being tested launches a subprocess. In this short tip we'll see how to robustly connect to an externally launched subprocess on Windows. | Sometimes when writing Squish tests the application being tested launches a subprocess. In this short tip we'll see how to robustly connect to an externally launched subprocess on Windows. | ||
As the froglogic Squish manual (section 17.7.1) explains, hooking into an AUT's subprocess when on windows is slightly more complex, as Squish is not able to use LD_PRELOAD (or DYLD_INSERT_LIBRARIES on OS X) to insert the squish library hook into the launching executable. Two options to get around this are clear—the AUT sourcecode can be modified to optionally insert | As the froglogic Squish manual (section 17.7.1) explains, hooking into an AUT's subprocess when on windows is slightly more complex, as Squish is not able to use LD_PRELOAD (or DYLD_INSERT_LIBRARIES on OS X) to insert the squish library hook into the launching executable. Two options to get around this are clear—the AUT sourcecode can be modified to optionally insert "dllpreload.exe" into the subprocess launch (as the squish manual explains), or the AUT can be modified to call an external shell script that does the optional prepending of 'dllpreload.exe'. | ||
In any case, once the AUT has been modified to properly launch the subprocess, the squish test still needs to attach to the launching subprocess. If the AUT uses QProcess to launch the subprocess, it is enough to do: | In any case, once the AUT has been modified to properly launch the subprocess, the squish test still needs to attach to the launching subprocess. If the AUT uses QProcess to launch the subprocess, it is enough to do: | ||
<code> subprocess = waitForApplicationLaunch() | <code> subprocess = waitForApplicationLaunch() | ||
</code> | |||
However, if the squish IDE is set up to attach to the AUT manually, the desired call would be: | |||
<code> subprocess = attachToApplication( | <code> subprocess = attachToApplication( "APPNAME" ) | ||
</code> | |||
However, the attachToApplication() call will throw an exception if the subprocess is not ready. So, a more robust way to give the subprocess time to launch properly is to try again in a loop for a predetermined amount of time: | |||
<code> subprocess = 0 | <code> subprocess = 0 | ||
count = 0 | |||
while True: | |||
if count > 30: | |||
raise RuntimeError( "Attaching to AUT subprocess failed!" ) | |||
try: | |||
subprocess = attachToApplication("APPNAME") | |||
break | |||
except: | |||
snooze(1) | |||
count += 1</code> |
Revision as of 10:52, 25 February 2015
Hooking into slow-launching subprocesses on Windows
Sometimes when writing Squish tests the application being tested launches a subprocess. In this short tip we'll see how to robustly connect to an externally launched subprocess on Windows.
As the froglogic Squish manual (section 17.7.1) explains, hooking into an AUT's subprocess when on windows is slightly more complex, as Squish is not able to use LD_PRELOAD (or DYLD_INSERT_LIBRARIES on OS X) to insert the squish library hook into the launching executable. Two options to get around this are clear—the AUT sourcecode can be modified to optionally insert "dllpreload.exe" into the subprocess launch (as the squish manual explains), or the AUT can be modified to call an external shell script that does the optional prepending of 'dllpreload.exe'.
In any case, once the AUT has been modified to properly launch the subprocess, the squish test still needs to attach to the launching subprocess. If the AUT uses QProcess to launch the subprocess, it is enough to do:
subprocess = waitForApplicationLaunch()
However, if the squish IDE is set up to attach to the AUT manually, the desired call would be:
subprocess = attachToApplication( "APPNAME" )
However, the attachToApplication() call will throw an exception if the subprocess is not ready. So, a more robust way to give the subprocess time to launch properly is to try again in a loop for a predetermined amount of time:
subprocess = 0
count = 0
while True:
if count > 30:
raise RuntimeError( "Attaching to AUT subprocess failed!" )
try:
subprocess = attachToApplication("APPNAME")
break
except:
snooze(1)
count += 1