In protractor everything is promise:
so you have to sueuse await with browser sleep.sleep also, if you wnatwant it synchronously.
it('click on the arrow and click on yes', async function () {
await element(by.css('button')).click();
await browser.sleep(1000);
let text = await element(by.css("p")).getText()
console.log(text);
expect(text).toBe("Would you like to preserve this return?");
await element(by.css('button:nth-of-type(2)')).click();
});
Note: use SELENIUM_PROMISE_MANAGER: false, in your config file https://www.protractortest.org/#/async-await
If you don't want to use await :
it('click on the arrow and click on yes', function () {
element(by.css('button')).click().then(function (){
WaitForLoad(element(by.css("p"))).getText().then(function (){
expect(text).toBe("Would you like to preserve this return?")
})
});
browser.sleep(2000).then( function(){
element(by.css("p")).getText().then(function(text){
console.log(text);
expect(text).toBe("Would you like to preserve this return?");
element(by.css('button:nth-of-type(2)')).click();
})
});
}
);