50.4 The qf module

In some cases there is no run context available, especially when implementing some of the extension interfaces described in the following sections. The module qf enables logging in those cases and also provides some generally useful methods that can be used without depending on a run context. Following is a list of the methods of the qf module in alphabetical order. Unless mentioned otherwise, methods are available in Groovy and Jython and for both Server script and SUT script nodes.

Note Please note that the Groovy syntax for keyword parameters is different from Jython and requires a ':' instead of '='. The tricky bit is that, for example, qf.logMessage("bla", report=true) is perfectly legal Groovy code yet doesn't have the desired effect. The '=' here is an assignment resulting in the value true, which is simply passed as the second parameter, thus the above is equal to qf.logMessage("bla", true) and the true is passed to dontcompactify instead of report. The correct Groovy version is qf.logMessage("bla", report:true).

 
 
Pattern asPattern(String regexp)
This method interprets the input as regular expression and returns the corresponding Java Pattern object. Valid input values are defined in the Java API of the Pattern object.
Parameters
regexpThe regular expression
Returns A Pattern object, which can be used for string comparisons.
 
String getClassName(Object objectOrClass)
Get the fully qualified name of the Class of a Java object, or of a Java class itself. Mostly useful for Jython where getting the name of a class can become a real hassle.
Parameters
objectOrClass The Java object or class to get the class name for.
Returns The class name or None in case something non-Java is passed in.
 
Object getProperty(Object object, String name)
Get a property for an object that was previously set via setProperty.
Parameters
objectThe object to get the property for.
nameThe name of the property.
ReturnsThe property value.
 
boolean isInstance(Object object, String className)
This is a simple alternative to instanceof in Groovy and isinstance() in Jython that deliberately compares class and instance names only so conflicts with differing class loaders are avoided.
Parameters
objectThe object to check.
classNameThe name of the class or interface to test for.
Returns True if the object is an instance of the given class or implements the given interface.
 
void logError(String msg, boolean nowrap=false)
Add a user-defined error message to the run log. If a run context is available it is used and logging takes effect immediately. Otherwise the message is buffered and logged at the next opportunity.
Parameters
msgThe message to log.
nowrap If true, lines of the message will not be wrapped in the report. Use for potentially long messages. This parameter has no effect if the message needs to be buffered.
 
void logMessage(String msg, boolean dontcompactify=false, boolean report=false, boolean nowrap=false)
Add a plain message to the run log. If a run context is available it is used and logging takes effect immediately. Otherwise the message is buffered and logged at the next opportunity.
Parameters
msgThe message to log.
dontcompactifyIf true, the message will never be removed from a compact run log.
reportIf true, the message will appear in the report.
nowrap If true, lines of the message will not be wrapped in the report. Use for potentially long messages. This parameter has no effect if the message needs to be buffered.
 
void logWarning(String msg, boolean report=true, boolean nowrap=false)
Add a user-defined warning message to the run log. If a run context is available it is used and logging takes effect immediately. Otherwise the message is buffered and logged at the next opportunity.
Parameters
msgThe message to log.
reportIf true (the default), the warning will be listed in the report. Set this to false to exclude this specific warning from the report.
nowrap If true, lines of the message will not be wrapped in the report. Use for potentially long messages. This parameter has no effect if the message needs to be buffered.
 
void print(Object object, ...)
Prints a string or the string representation of an object to the terminal. If more than one object is specified there representations are joint with a space character. In contrast to a simple print statement, the text is not transferred using the standard output stream.
Parameters
objectThe object, which should be printed.
 
void println(Object object)
Prints a string or the string representation of an object to the terminal, and starts a new line. If more than one object is specified there representations are joint with a space character. In contrast to a simple println statement, the text is not transferred using the standard output stream.
Parameters
objectThe object, which should be printed.
 
void setProperty(Object object, String name, Object value)
Set an arbitrary property for an object. For Swing, SWT or web components the value is stored in the respective user data via putClientProperty, setData or setProperty respectively. For everything else a WeakHashMap is used. Either way the property will not prevent garbage collection of the object.
Parameters
objectThe object to set the property for.
nameThe name of the property.
valueThe value to set. Null to remove the property.
 
String toString(Object object, String nullValue)
Get the string representation of an object. Mostly useful for Jython but sometimes also useful for Groovy thanks to the default conversion of null to the empty string.
Parameters
objectThe object to get the string representation for.
nullValueThe value to return if object is None, the empty string by default.
Returns Jython 8-bit or Unicode strings are returned unchanged, Java objects are turned into a string via toString. In Jython, everything else is converted into an 8-bit Jython string.
 
VariableData wrapObject(Object value, String stringValue, String description)

Wraps an object into a data container, to further define the object behavior when stored as QF-Test variable or property value.

Parameters
valueThe object to wrap and to return upon rc.getObj().
stringValueOptional string representation of the object, when accessed e.g. via rc.getStr().
descriptionOptional description of the object (Visible in log files and stack traces instead of the stringValue).
Returns The object wrapped in a VariableData instance.