05 Promise Handling - biswajitsundara/Protractor GitHub Wiki
Protractor scripts are developed in Java Script and Type Script and both languages are asynchronous in nature and that brings a challenge in automation. Refer Java Script Promise
- SELENIUM_PROMISE_MANAGER: false is the switch to enable/disable the control flow(promise) implemented by Protractor. Before ES6, Javascript had not supplied native promise API and protractor implemented the promise and promise management (called control flow) by itself. This is out dated now and we should not use it.
- All the actions performed on the browser (like click, enter text) etc are taken care by the Protractor API and we won't have synchronization issue, however when we take something out of the browser like getText() or getTitle() then we need to handle the promise else we won't get the accurate result.
- Use the promise handling of
then()orasync/await
This will print the text as undefined.
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
const text= element(by.css('h3')).getText();
console.log('text--->'+text);
});
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
element(by.css('h3')).getText().then((text)=>{
console.log('text--->'+text);
})
});
Reference