Javascript 使用getText()的量角器中的断言错误

Javascript 使用getText()的量角器中的断言错误,javascript,angularjs,protractor,chai,cucumberjs,Javascript,Angularjs,Protractor,Chai,Cucumberjs,我试图使用BDD和量角器检查三个下拉框的值 与此相关的代码是: checkDropdown: function (value, dropdown) { let name = element(by.id(dropdown)); console.log(name.getText()); expect(name.getText()).to.equal(value); }, 输出为: AssertionError: expected { Object (brows

我试图使用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应该检索字符串而不是对象

提前感谢。

expect(name.getText()).to.finally.equal(value)

请看这里:
因为您正在声明一个承诺,只需更改下面的代码,等待承诺

checkDropdown: function (value, dropdown) {
   element(by.id(dropdown)).then(function(elem){
     elem.getText().then(function(text) {
        expect(text).to.equal(value);
     })
   });   
}
console.log(name.getText())的输出;?