This article is deprecated.
Please use the testInteraction functions that Squish provides for semi-automatic testing.
Overview The following solution is based on the open source project
easygui
.
Please note that Squish adds its Python folder path to the PATH environment variable. This means that if you run a Python script as a separate process from the test script, the Squish Python installation will be used.
However, because the Squish Python installation lacks the Tkinter
module which easygui
requires, extra steps must be performed to first remove Squish's entries from the PATH
environment variable again, and then another Python process is started, with the original parameters, in an attempt to use a globally installed, full featured Python installation.
Installation Download and save these two files in your test suite directory:
Using the choicebox.py script from JavaScript To use the above Python script from inside your test script use something like the choicebox function in this example:
function main () {
var c = choicebox ( "Message" , "Title" , [ "Choice 1" , "Choice 2" ]);
test . log ( c );
}
function choicebox ( msg , title , choicesArray ) {
var cmd = 'python "' + squishinfo . testCase + '/../choicebox.py"' ;
cmd += ' "' + msg + '"' ;
cmd += ' "' + title + '"' ;
for ( var i = 0 ; i < choicesArray . length ; i ++ ) {
cmd += ' "' + choicesArray [ i ] + '"' ;
}
return OS . capture ( cmd );
}
test.js Using the choicebox.py script from Python To use the above Python script from inside your test script use something like the choicebox function in this example:
# -*- coding: utf-8 -*-
import subprocess
def main ():
c = choicebox ( "Message" , "Title" , [ "Choice 1" , "Choice 2" ])
test . log ( c )
def choicebox ( msg , title , choices_array ):
cmd = [ "python" ]
cmd . append ( squishinfo . testCase + "/../choicebox.py" )
cmd . append ( msg )
cmd . append ( title )
for c in choices_array :
cmd . append ( c )
return os_capture ( cmd )
def os_capture ( cmd ):
res = subprocess . Popen (
args = cmd ,
stdout = subprocess . PIPE ,
stderr = subprocess . STDOUT
) . communicate ()
return res [ 0 ] . decode ( "utf8)
test.py