Squish tip of the week: How to determine if a checkbox is checked?

Squish tip of the week: How to determine if a checkbox is checked?

You can check the state of a checkbox, radio button, or the property of any other object or widget using Squish.

Using a test.compare() Verification Point

The line below looks at the object :Controls.My_CheckBox and indicates if the verification point passed or failed: passed if the checkbox is checked, and failed if the checkbox isn’t checked:

test.compare(findObject(":Controls.My_CheckBox").checked, True)

Using <object>.<property>

You can also save an object’s properties to a variable, and access the properties in your script. The example below saves the object’s properties to checkBoxToVerify, after which it logs a message indicating if the checkbox is checked or unchecked:

checkBoxToVerify = waitForObject(":Controls.My_CheckBox")
if checkBoxToVerify.checked:
    test.log("Checkbox already checked")
else:
    test.log("Checkbox not checked")