简体   繁体   中英

Assertion error in protractor using getText()

I am trying to check the value of three dropdown boxes using BDD and Protractor.

The code related to this is:

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

And the output is:

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

How can I do to make it works? I thought that getText should retrieves a string instead of an object.

Thanks in advance.

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

参见此处: 在量角器chai中使用“最终”时收到“消息不可行”消息

Because you are asserting a promise, just change the code like below to wait for the promise,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM