代码之家  ›  专栏  ›  技术社区  ›  Rod McCutcheon

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

  •  0
  • Rod McCutcheon  · 技术社区  · 6 年前

    谢谢你的奶昔!

    如何使用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'
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   yong    6 年前

    chai-smoothie 当断言失败时,启用错误消息更易于读取。但它不能处理承诺: this.nameTextbox.getAttribute('value') 回报承诺。

    注意 :所有量角器API返回承诺。

    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');