【问题标题】:Protractor error message returns a Object量角器错误消息返回一个对象
【发布时间】:2016-07-21 16:29:57
【问题描述】:

我期待value_key(翻译)被protractor找到并返回true,这样测试成功。

在我的 test-spec.js 文件中

it('test if tile "Value of Key" shows result text', function() {
   expect(
     element(by.xpath('//*[@id="idname"]/div/h3')
   ).getText()).toEqual(helpers.translate('value_key'));
});

量角器错误 信息: 预期的“键值”等于 Object({ $$state: Object({ status: 0 }), catch: Object({ }), then: Object({ }), finally: Object({ }) })。

感谢您的帮助

【问题讨论】:

  • helpers.translate('value_key') 它会返回什么,我能看到它的代码吗?

标签: javascript angularjs protractor


【解决方案1】:

看起来您的 helpers.translate() 函数返回了一个承诺

在 Protractor/Jasmine 中,只有断言的左侧部分 - expect() 部分能够隐式解析承诺。正确的部分,在你的情况下是 toEqual(),不是。

明确地解决承诺

helpers.translate('value_key').then(function(value) {
    var text = element(by.xpath('//*[@id="idname"]/div/h3')).getText();
    expect(text).toEqual(value);
});

你也可以使用protractor.promise.all()来解决两个promise然后断言:

var promise1 = element(by.xpath('//*[@id="idname"]/div/h3')).getText();
var promise2 = helpers.translate('value_key');

protractor.promise.all([promise1, promise2]).then(function(values) {
   expect(values[0]).toEqual(values[1]);
});

目前没有issues with using protractor.promise.all() in 4.0.0(应该是fixed in the next version(s))。此处提供了解决方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    相关资源
    最近更新 更多