Squish/Hooking into Subprocesses

From Qt Wiki
< Squish
Revision as of 15:40, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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:

However, if the squish IDE is set up to attach to the AUT manually, the desired call would be:

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:

This gives the launching app 30 seconds to launch—if it fails after that, a RuntimeError is thrown and the error will be reported in the squish test output. Otherwise, the subprocess is successfully attached to.

Categories: