如何使用 chai/chai-smoothie 断言输入字段的值?
How do I assert the value of an input field with chai/chai-smoothie?
感谢奶昔!
如何使用 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'
chai-smoothie
使断言失败时的错误消息更易于阅读。但它无法处理承诺:this.nameTextbox.getAttribute('value')
return 一个承诺。
注意:所有量角器APIreturn承诺。
您需要使用 chai-as-promised
和 chai
来处理承诺。
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');
感谢奶昔!
如何使用 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'
chai-smoothie
使断言失败时的错误消息更易于阅读。但它无法处理承诺:this.nameTextbox.getAttribute('value')
return 一个承诺。
注意:所有量角器APIreturn承诺。
您需要使用 chai-as-promised
和 chai
来处理承诺。
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');