After upgrading to protractor 2.0, I encountered some issues in my project.
An expect()
statement fails because the given text is ''
, it appears that the expect is being executed before sendKeys()
is completed.
elem.clear().sendKeys('Message');
expect(elem.getAttribute('value')).toBe('Message');
The error message I receive is:
Expected '' to be 'Message'.
This was working fine prior to updating to protractor 2.0, and I am aware of a change related to then() and promises:
To facilitate the update and reduce confusion, the element().then function has been removed unless there is an action result. This change may lead to compatibility issues. Essentially, an ElementFinder is no longer a promise until an action is performed on it.
In other tests within my project, this works as expected. I suspect that the issue may arise from having the expect statement inside a loop. Below is the full code snippet:
describe('message', function() {
it('Should fill out visible message fields', function(){
getDisplayedElements(element.all(by.model('message')))
.then(function(displayedMessageInputs){
_.each(displayedMessageInputs, function(elem){
elem.clear().sendKeys('Message');
expect(elem.getAttribute('value')).toBe('Message');
});
});
});
});
Although using then() functions resolves the issue, I find it less desirable!
elem.clear().sendKeys('Message')
.then(function(){
return elem.getAttribute('value');
})
.then(function(inputValue){
expect(inputValue).toBe('Message');
});