简体   繁体   中英

Protractor error message returns a Object

I am expecting that the value_key (translation) is found by protractor and returns true, so that the test succeeds.

In my test-spec.js file I

it('test if tile "Value of Key" shows result text', function() {
   expect(
     element(by.xpath('//*[@id="idname"]/div/h3')
   ).getText()).toEqual(helpers.translate('value_key'));
});

Protractor error Message: Expected 'Value of Key' to equal Object({ $$state: Object({ status: 0 }), catch: Object({ }), then: Object({ }), finally: Object({ }) }).

Thank you for your help

It looks like your helpers.translate() function returns a promise .

In Protractor/Jasmine, only the left part of the assertion - the expect() part is capable of resolving promises implicitly. The right part, toEqual() in your case, is not.

Resolve the promise explicitly :

helpers.translate('value_key').then(function(value) {
    var text = element(by.xpath('//*[@id="idname"]/div/h3')).getText();
    expect(text).toEqual(value);
});

You can also use protractor.promise.all() to resolve both promises and then assert:

var promise1 = element(by.xpath('//*[@id="idname"]/div/h3')).getText();
var promise2 = helpers.translate('value_key');

protractor.promise.all([promise1, promise2]).then(function(values) {
   expect(values[0]).toEqual(values[1]);
});

Not that there are currently issues with using protractor.promise.all() in 4.0.0 (should be fixed in the next version(s) ). Workaround is available here.

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