Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Protractor 当预期条件失败时,测试分辨率被阻止_Protractor_Mocha.js - Fatal编程技术网

Protractor 当预期条件失败时,测试分辨率被阻止

Protractor 当预期条件失败时,测试分辨率被阻止,protractor,mocha.js,Protractor,Mocha.js,使用量角器和Mocha框架,我比较了两个值数组,一个来自条形图,一个来自文本字段。 代码如下所示: it("Each bar should have a value equal to its percentage", () => { var identicalValue: boolean = false; helper.getFirstValues(textLocator).then((textValue) => { helper.getBarValu

使用量角器和Mocha框架,我比较了两个值数组,一个来自条形图,一个来自文本字段。 代码如下所示:

it("Each bar should have a value equal to its percentage", () => {
    var identicalValue: boolean = false;
    helper.getFirstValues(textLocator).then((textValue) => {
        helper.getBarValues(barLocator).then((barValue) => {
            identicalValue = helper.compareArray(textValue, barValue);
            //compareArray returns a boolean, true if the arrays have the same values
            expect(identicalValue).to.equal(true);
        });
    });
});
功能的编码方式如下:

public getFirstValues(factsheetTab: protractor.ElementFinder): webdriver.promise.Promise<{}> {

    var deferred = protractor.promise.defer();
    factsheetTab.all(by.tagName("tr")).map((ele, index) => {
        return {
            index: index,
            text: ele.all(by.tagName("td")).first().getText()
        }
    }).then((topValue) => {
        deferred.fulfill(topValue);
    },
        (reason) => { deferred.reject(reason) });
    return deferred.promise;
};

public getBarValues(factsheetTab: protractor.ElementFinder): webdriver.promise.Promise<{}> {

    var deferred = protractor.promise.defer();
    factsheetTab.all(by.tagName("tr")).map((ele, index) => {
            return {
                index: index,
                text: ele.all(by.tagName("td")).last().element(by.tagName("div")).getAttribute("data-value")
            }
    }).then((barValue) => {
        deferred.fulfill(barValue);
    },
    (reason) => { deferred.reject(reason) });
    return deferred.promise;
};
(使用@盐水的建议,适用于deepEqual)

这似乎是可行的,如果这个测试失败,其他测试将运行。
我仍然很想知道第一个版本出了什么问题。

不确定这是否是您的
助手中的错误。compareArray
或摩卡咖啡。。。但是为什么不直接比较阵列呢?我不使用摩卡咖啡,但它似乎是这样的:

expect(textValue).deepEqual(barValue);

可能尝试用
.to.be.true替换?一般来说,你应该使用它,因为这正是你想要做的。我只是尝试了一下,但不幸的是,它并不能解决问题。在没有看到自定义代码的情况下,我们只能疯狂地猜测可能出现的错误。我添加了两个函数,如果这有帮助的话。我不知道这个函数,谢谢!但这并不能解决问题。我试着使用它,评论我的helper.comparearlay部分,结果是一样的(失败时被阻止,成功时通过)酷!我猜是摩卡承诺问题,还是一个彻头彻尾的摩卡迷?不确定。量角器调整Jasmine以处理预期内的所有承诺,因此这是另一个选项。。。很高兴这有点帮助。
expect(textValue).deepEqual(barValue);