testInteraction Functions
Squish provides several functions for tests which need interaction with a real user during replay. Such interaction includes simple questions for manual verification as well as providing user-input, i.e., for manually driven testing or for taking notes while observing test execution.
testInteraction
functions that display a message box return one of the following constant values depending on the button that was pressed by the user:
- testInteraction.Ok
- testInteraction.Yes
- testInteraction.No
Any testInteraction
function that displays a dialog shows the current testscript filename and line number in its title bar.
Calling any of these functions only works if squishrunner was started with the --interactive
option (See also squishrunner –testsuite: Running tests in batch mode). Tests executed from the squishide
are always run in interactive mode. Calling any of the testInteraction
functions (except for testInteraction.isAvailable()
) in non-interactive mode will result in a script error causing script execution to abort.
string testInteraction.choice(message, items)
Shows a dialog with message
as message text and a list of items
to choose from. The returned string contains the selected item text or an empty string if the user canceled the dialog.
var name = testInteraction.choice("Choose something", ["First", "Second", "Third"]) if (name == "") { test.warning("No item was chosen") } else { test.log(item + " it is!") }
my $item = testInteraction::choice("Choose something", ["First", "Second", "Third"]); if ($item eq "") { test::warning("No item was chosen"); } else { test::log($item." it is!"); }
item = testInteraction.choice("Choose something", ["First", "Second", "Third"]) if not item: test.warning("No item was chosen") else: test.log("{} it is!".format(item))
item = TestInteraction.choice("Choose something", ["First", "Second", "Third"]) if item == "" Test.warning("No item was chosen") else Test.log("#{item} it is!") end
set item [testInteraction choice "Choose something" [list "First" "Second" "Third"]] if {$item == ""} { test warning "No item was chosen" } { test log "$item it is!" }
int testInteraction.information(message)
Shows a message box with message
as message text, an information icon and an OK button.
testInteraction.information("This is the 'information' function.\nPress 'OK' to continue.")
testInteraction::information("This is the 'information' function.\nPress 'OK' to continue.");
testInteraction.information("This is the 'information' function.\nPress 'OK' to continue.")
TestInteraction.information("This is the 'information' function.\nPress 'OK' to continue.")
testInteraction information "This is the 'information' function.\nPress 'OK' to continue."
string testInteraction.input(message, initialText)
Shows a dialog with message
as message text and a line edit for user input. The optional initialText
sets the initial text of the line edit. The returned string contains the contents of the line edit or an empty string if the user canceled the dialog.
name = testInteraction.input("Type in your name and press one of buttons below.") if (name == "") { testInteraction.warning("It's sad you don't want to share your name.") } else { testInteraction.information("Hello " + name + "!") }
$name = testInteraction::input("Type in your name and press one of buttons below."); if ($name eq "") { testInteraction::warning("It's sad you don't want to share your name."); } else { testInteraction::information("Hello $name!"); }
name = testInteraction.input("Type in your name and press one of buttons below.") if name == "": testInteraction.warning("It's sad you don't want to share your name.") else: testInteraction.information("Hello %s!" %name)
name = TestInteraction.input("Type in your name and press one of buttons below.") if name == "" TestInteraction.warning("It's sad you don't want to share your name.") else TestInteraction.information("Hello " + name + "!") end
set name [testInteraction input "Type in your name and press one of buttons below."] if {$name == ""} { testInteraction warning "It's sad you don't want to share your name." } { testInteraction information "Hello $name!" }
bool testInteraction.isAvailable()
This function returns whether the test script is executed by a squishrunner that was started including the --interactive
option. This allows creating tests that only show interactive dialogs on request but also run in a non-interactive way.
void testInteraction.notification(message)
void testInteraction.notification(message, timeoutSecs)
Shows a timed non-blocking message box with message
as message text for timeoutSecs
seconds. If timeoutSecs
is not provided, the message box will be shown for 5 seconds.
timeOut = 2 testInteraction.notification("This is the 'notification' function.\nWait " + timeOut +" seconds for message box to close.", timeOut) //or testInteraction.notification("This is the 'notification' function.\nWait 5 seconds for message box to close.")
$timeOut = 2; testInteraction::notification("This is the 'notification' function.\nWait $timeOut seconds for message box to close.", $timeOut); #or testInteraction::notification("This is the 'notification' function.\nWait 5 seconds for message box to close.");
timeOut = 2 testInteraction.notification("This is the 'notification' function.\nWait %s seconds for message box to close." %timeOut, timeOut) #or testInteraction.notification("This is the 'notification' function.\nWait 5 seconds for message box to close.")
timeOut = "2" TestInteraction.notification("This is the 'notification' function.\nWait "+ timeOut + " seconds for message box to close.", timeOut) #or TestInteraction.notification("This is the 'notification' function.\nWait 5 seconds for message box to close.")
set timeOut 2 testInteraction notification "This is the 'notification' function.\nWait $timeOut seconds for message box to close." $timeOut #or testInteraction notification "This is the 'notification' function.\nWait 5 seconds for message box to close."
string testInteraction.password(message)
Shows a dialog with message
as message text and a line edit with asterisks instead of the characters actually entered for user input. The returned string contains the contents of the line edit or an empty string if the user canceled the dialog.
passwd = testInteraction.password("Type 'P@ssw0rd' without quotes to reveal secret information.") if (passwd == "P@ssw0rd") { testInteraction.information("The secret information is: The Cake is a Lie!") } else { testInteraction.warning("Wrong password. It seems the secret will remain hidden.") }
$passwd = testInteraction::password("Type 'Passw0rd' without quotes to reveal secret information."); if ($passwd eq "Passw0rd") { testInteraction::information("The secret information is: The Cake is a Lie!"); } else { testInteraction::warning("Wrong password. It seems the secret will remain hidden."); }
passwd = testInteraction.password("Type 'P@ssw0rd' without quotes to reveal secret information.") if passwd == "P@ssw0rd": testInteraction.information("The secret information is: The Cake is a Lie!") else: testInteraction.warning("Wrong password. It seems the secret will remain hidden.")
passwd = TestInteraction.password("Type 'P@ssw0rd' without quotes to reveal secret information.") if passwd == "P@ssw0rd" TestInteraction.information("The secret information is: The Cake is a Lie!") else TestInteraction.warning("Wrong password. It seems the secret will remain hidden.") end
set passwd [testInteraction password "Type 'P@ssw0rd' without quotes to reveal secret information."] if {$passwd == "P@ssw0rd"} { testInteraction information "The secret information is: The Cake is a Lie!" } { testInteraction warning "Wrong password. It seems the secret will remain hidden." }
int testInteraction.question(message)
Shows a message box with message
as message text, a questionmark-icon, a Yes button and a No button.
questionResult = testInteraction.question("Do you wish to continue?") if (questionResult == testInteraction.Yes) { testInteraction.information("Button 'Yes' was pressed.") } else { testInteraction.information("Button 'No' was pressed.") }
$questionResult = testInteraction::question("Do you wish to continue?"); if ($questionResult == testInteraction::Yes) { testInteraction::information("Button 'Yes' was pressed."); } else { testInteraction::information("Button 'No' was pressed."); }
questionResult = testInteraction.question("Do you wish to continue?") if questionResult == testInteraction.Yes: testInteraction.information("Button 'Yes' was pressed.") else: testInteraction.information("Button 'No' was pressed.")
questionResult = TestInteraction.question("Do you wish to continue?") if questionResult == TestInteraction::YES TestInteraction.information("Button 'Yes' was pressed.") else TestInteraction.information("Button 'No' was pressed.") end
set questionResult [testInteraction question "Do you wish to continue?"] if {$questionResult == [testInteraction Yes] } { testInteraction information "Button 'Yes' was pressed." } { testInteraction information "Button 'No' was pressed." }
void testInteraction.showImage(image, [message], [timeoutSecs])
Shows a timed non-blocking dialog that contains the image
, a message
message text, and a OK button. If timeoutSecs
is not provided, the dialog will be shown for 5 seconds.
var img = grabDesktopScreenshot(); testInteraction.showImage(img, "Current desktop", 2);
my $img = grabDesktopScreenshot(); testInteraction::showImage($img, "Current desktop", 2);
img = grabDesktopScreenshot() testInteraction.showImage(img, "Current desktop", 2)
img = grabDesktopScreenshot(); TestInteraction.showImage(img, "Current desktop", 2)
set img [grabDesktopScreenshot] testInteraction showImage $img, "Current desktop", 2
int testInteraction.warning(message)
Shows a message box with message
as message text, a warning-icon and an OK button.
testInteraction.warning("This is the 'warning' function.\nPress 'OK' to continue.")
testInteraction::warning("This is the 'warning' function.\nPress 'OK' to continue.");
testInteraction.warning("This is the 'warning' function.\nPress 'OK' to continue.")
TestInteraction.warning("This is the 'warning' function.\nPress 'OK' to continue.")
testInteraction warning "This is the 'warning' function.\nPress 'OK' to continue."
© 2024 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners.