I am using protractor with selenium and was trying to check the element present using the expect() condition with in the if statement, but it is going to else block even though the condition is true. In the condition I tried both toBe and toEqual and both has same effect.
let email_Original = element(by.css('button[value="original"][aria-pressed="true"]'))
var isTranslated = await email_Original.isPresent()
console.log('Translate button state is ' + isTranslated)
if (expect(isTranslated).toBe(true)) {
console.log('Pass: Email successfully translated to original language')
} else {
console.log('Fail: Email not translated to original language')
}
output
Translate button state is true
Fail: Email not translated to original language
I would get rid of the logging messages and just use the assertion to tell you if it passed or not.
it('should be translated', async () => {
const email_Original = element(by.css('button[value="original"][aria-pressed="true"]'));
const isTranslated = await email_Original.isPresent();
expect(isTranslated).toBe(true);
});