How to fail a test if element is not present using Protractor

Viewed 105

I need to fail test if element is not present using protractor. Here, I have implemented code. When expect condition out of if condition I expected it will fail. Unfortunately, test case is passing. Can anyone suggest if anything that i missed.

crossAttribute.isPresent().then(function (deleteAttribute) {
                if(deleteAttribute){
                    crossAttribute.click();
                }else{
                    console.log('Cross is not present to delete attribute') 
                }
                expect(crossAttribute).toBeTruthy;
            });
1 Answers

this will work easily

let attributeIsPresent = await crossAttribute.isPresent()
if (attributeIsPresent) {
  await crossAttribute.click();
} else {
  expect(false).toBe(true)
}

your code didn't work because you used wrong variable crossAttribute instead of deleteAttribute

Related