1

这有效

it('should create a report for index: ', function() {
    var dataLength = window.test.parameters.length;
    for (var i = 0; i < dataLength; i++){
        var parameterObject = window.test.parameters[i];
        var propNumber = parameterObject.propertyNumber;
        element(":contains('" + propNumber + "')").click();
        element(":button('View')").click();
        expect(element('div *:contains(' + reportName + ')').count()).toEqual(4);
    }
});

这不

var dataLength = window.test.parameters.length;
for (var i = 0; i < dataLength; i++){
    it('should create a report for index: ', function() {
        var parameterObject = window.test.parameters[i];
        var propNumber = parameterObject.propertyNumber;
        element(":contains('" + propNumber + "')").click();
        element(":button('View')").click();
        expect(element('div *:contains(' + reportName + ')').count()).toEqual(4);
    });
};

我的意图是将此测试参数化,以便每次使用不同的参数组合多次运行它。我试过删除 var 并“使用严格”;以确保 i 是全球性的。我尝试在“描述”函数之外声明 i 。这有什么诀窍吗?

4

1 回答 1

4

it可能是异步的,尝试对其进行词法范围。

var dataLength = window.test.parameters.length;
for (var i = 0; i < dataLength; i++){
    it('should create a report for index: ', function(i) {
        return function () {
            var parameterObject = window.test.parameters[i];
            var propNumber = parameterObject.propertyNumber;
            element(":contains('" + propNumber + "')").click();
            element(":button('View')").click();
            expect(element('div *:contains(' + reportName + ')').count()).toEqual(4);
        };
    }(i));
};
于 2013-05-11T16:08:49.187 回答