记录对象属性

最后编辑了

概述

为了比较对象,它可以很有用迭代并输出所有对象属性及其各自的值。这可以通过帮助实现 object.properties()功能:

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.