Squish/Using Custom Properties

From Qt Wiki
< Squish
Revision as of 10:00, 11 August 2020 by Christian Ehrlicher (talk | contribs) (style)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Using Squish and custom properties

To fully test your application, there might be situations where you need to modify the application source code to add properties to specific widgets that can be tested from Squish. There are essentially two ways of doing this:

1) Use the Q_PROPERTY macro

If you have access to the source code for the widget you want to change, you can simply use the Q_PROPERTY macro to add a property to the widget:

class MyWidget : public QWidget
{
 Q_OBJECT
 Q_PROPERTY(QString nameOfProperty READ getValue)

public:

 QString getValue() const { return m_memberVar; }

private:
 QString m_memberVar;
}

This property will then be accessible in Squish using the Squish Spy just like any other widget property, and turned into a verification point simply by recording:

waitFor("object.exists(':NameOfObject')", 20000)
object = findObject(":NameOfObject")
value = object.nameOfProperty
test.compare(value, "Expected value")

2) Use dynamic properties

In the case where you do not have access to the source code for the widget, but instead only to the application using it, you cannot use the Q_PROPERTY approach as described above, but will need to use dynamic properties instead. This is essentially using the QObject::setProperty() function in the application source code to set the value of the property on the widget. This function takes two parameters, the name of the property (which you will later use from Squish) and the value to set:

myWidget->setProperty("nameOfProperty", "Expected value"

The dynamic properties are however not seen automatically by Squish, so you cannot access them in the Squish Spy. Instead, we need to call the QObject::property() function to get the value. This is nothing different from calling other Qt functions from your Squish scripts:

waitFor("object.exists(':NameOfObject')", 20000)
object = findObject(":NameOfObject")
value = object.property("nameOfProperty").toString()
test.compare(value, "Expected value")