Logging object properties

Last edited on

The following log_obj() functions can be used to output all properties and property values of an object to the Test Results view and/or the log.

Python:

def main():
    # startApplication(...)
    log_obj(waitForObject("{type='MainWindow' visible='true'}"));

def log_obj(obj):
    properties = object.properties(obj)
    keys = properties.keys()
    keys.sort()
    for key in keys:
        value = properties[key]
        if isNull(value):
            test.log(key + '=null')
        else:
            test.log(key + '=%s' % value)
test.py

JavaScript:

function main()
{
    // startApplication(...);
    log_obj(waitForObject("{type='MainWindow' visible='true'}"));
}

function log_obj(obj)
{
    var properties = object.properties(obj);
    var keys = new Array();
    for (var key in properties) {
        keys.push(key);
    }
    keys.sort();
    for (var i = 0; i < keys.length; i++) {
        var key = keys[i];
        var value = properties[key];
        if (isNull(value)) {
            test.log(key + '=null');
        } else {
            try {
                test.log(key + '=' + value);
            } catch(e) {
                test.log(key + '=<' + typeName(value) + ' object reference>');
            }
        }
    }
}
test.js