Iterating over or logging object properties

Last edited on

Overview

For comparing objects it can be useful to iterate over and output all object properties and their respective values. This can be achieved with the help of the object.properties() function:

def main():
    startApplication("myaut")

    o = waitForObject(":some_obj_name")

    log_obj(o)

    test.log("")

    log_obj_sorted(o)

def log_obj(obj):
    for key, value in object.properties(obj).iteritems():
        if isNull(value):
            test.log(key + '=null')
        else:
            test.log(key + '=%s' % value)

def log_obj_sorted(obj):
    keys_values = {}
    for key, value in object.properties(obj).iteritems():
        if isNull(value):
            keys_values[key] = "null"
        else:
            keys_values[key] = value
    keys_sorted = keys_values.keys()
    keys_sorted.sort()
    for key in keys_sorted:
        test.log("%s=%s" % (key, keys_values[key]))
test.py

Related information

object.properties()