Ashley
Ashley

Reputation: 157

Protractor - How to assert a value is not in the table?

I am writing a protractor test where I delete a record and need to assert that it is not in the table. How do I do it? To assert that a value is in the table I use the below code.

expect(by.cssContainingText('table tbody tr td' , '[email protected]'));

Upvotes: 1

Views: 150

Answers (1)

Bharath Kumar S
Bharath Kumar S

Reputation: 1408

Simple answer is expect not be present

expect(element(by.cssContainingText('table tbody tr td' , '[email protected]')).isPresent()).toBeFalsy();

Better way is to wait until invisibilityOf element and then assert.

    const expected = require('protractor').ExpectedConditions
    const btn = element(by.cssContainingText('table tbody tr td' , '[email protected]'))
    await browser.wait(expected.invisibilityOf(btn), 5000)
    expect(btn.isPresent()).toBeFalsy();

Use expected conditions to wait until invisibilityOf web element.

invisibilityOf(elementFinder: ElementFinder): Function; (method) ProtractorExpectedConditions.invisibilityOf(elementFinder: ElementFinder): Function An expectation for checking that an element is either invisible or not present on the DOM. This is the opposite of 'visibilityOf'.

@example

let EC = protractor.ExpectedConditions;
// Waits for the element with id 'abc' to be no longer visible on the dom.
browser.wait(EC.invisibilityOf($('#abc')), 5000);
@alias — ExpectedConditions.invisibilityOf

@param elementFinder — The element to check

@returns An expected condition that returns a promise representing whether the element is invisible.

Upvotes: 1

Related Questions