0

感谢柴冰沙!

如何使用 chai/chai-smoothie 断言输入字段的值?

鉴于 getText() 始终为空,我们应该使用 element.getAttribute('value') (请参阅:How to getText on an input in protractor

我希望能够做类似的事情:

expect(this.nameTextbox).to.eventually.have.value('name');

这似乎不起作用:

expect(this.nameTextbox.getAttribute('value')).to.eventually.equal('name');

AssertionError: expected { Object (browser_, then, ...) } to equal 'name'
4

1 回答 1

1

chai-smoothie是在断言失败时启用错误消息更易于阅读。但它不能处理承诺:this.nameTextbox.getAttribute('value')返回一个承诺。

注意:所有 Protractor API 都返回承诺。

您需要使用chai-as-promisedwithchai来处理承诺。

var chai = require('chai'),

chai.use(require('chai-as-promised'));
chai.use(require('chai-smoothie'));

global.expect = chai.expect;

// then can do assertion as following:
expect(this.nameTextbox.getAttribute('value')).to.eventually.equal('name');
于 2018-11-08T12:32:36.283 回答