Search code examples
protractorinvisible

Expected true to be false error while tesing for not visible in protractor


I delete a row. now I am trying to check that the row is deleted. I tried with:

expect(element(by.cssContainingText('.ng-star-inserted','2')).isPresent()).toBe(false);

or

expect(element(by.cssContainingText('.ng-star-inserted','2')).isDisplayed()).toBe(false);

which returns an error

Expected true to be false

then I tried with :

expect(element(by.cssContainingText('.ng-star-inserted','2')).isPresent()).toBeFalsy();

which returns an unknown error. I am not sure what am I doing wrong here. please help.


Solution

  • I find that the expect statement was not correct here. it was showing a message like

    more than one element found....

    which was the main cause of the error.

    so, what I did to overcome the problem is, declare a variable and then use that in the validation part.

    let removedItem = element(by.cssContainingText('.ng-star-inserted', '6701202609675'));
    .
    .
    .
    expect((removedItem).isPresent('6701202609675')).toBe(false);