首页 > 解决方案 > 无法读取未定义的属性“等于”

问题描述

我正在使用量角器来测试我的应用程序。

我正在尝试获取标签内的值<p>,我可以按照 所示执行此操作console.log,但预期会返回错误:

[14:54:57] E/launcher - Cannot read property 'equal' of undefined
[14:54:57] E/launcher - TypeError: Cannot read property 'equal' of undefined

这是我的代码stepdefinitions.js

Then('I see the alert "Values are incorrect" for the contents which does not match the proper data', function (next) {
    browser.sleep(9999);
    let failed_msg = element(by.css('.error-message'));
    failed_msg.getText().then(function(text){
        console.log('MY ALERT MESSAGE FOR THIS SCENARIO IS: ',text);
        expect((failed_msg).to.equal("Values are incorrect"));   
        next();
    });
});

有人能帮我吗?

标签: protractorcucumberundefined

解决方案


我通过使用这个解决了这个问题:

expect(text.should.be.equal("Values are incorrect")); 

同样感谢你;)


推荐阅读