【问题标题】:Assertion error in protractor using getText()使用 getText() 的量角器中的断言错误
【发布时间】:2018-08-28 12:26:11
【问题描述】:

我正在尝试使用 BDD 和量角器检查三个下拉框的值。

与此相关的代码是:

checkDropdown: function (value, dropdown) {
    let name = element(by.id(dropdown));
    console.log(name.getText());
    expect(name.getText()).to.equal(value);
},

输出是:

       AssertionError: expected { Object (browser_, then, ...) } to equal 'Apparent Energy'

我该怎么做才能让它发挥作用?我认为 getText 应该检索字符串而不是对象。

提前致谢。

【问题讨论】:

  • console.log(name.getText())的输出;?

标签: javascript angularjs protractor chai cucumberjs


【解决方案1】:

因为你是在断言一个promise,只需像下面这样更改代码来等待promise,

checkDropdown: function (value, dropdown) {
   element(by.id(dropdown)).then(function(elem){
     elem.getText().then(function(text) {
        expect(text).to.equal(value);
     })
   });   
}

【讨论】:

    【解决方案2】:

    expect(name.getText()).to.eventually.equal(value);

    请看这里: Getting "is not a thenable" message while using "eventually" in protractor chai

    【讨论】:

      猜你喜欢
      • 2015-03-27
      • 2020-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      相关资源
      最近更新 更多