量角器 - 如何断言一个值不在 table 中?

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

我正在编写一个量角器测试,我删除了一条记录并需要断言它不在 table 中。我该怎么做?要断言值在 table 中,我使用以下代码。

expect(by.cssContainingText('table tbody tr td' , 'test@example.com'));

简单的答案是预计不会出现

expect(element(by.cssContainingText('table tbody tr td' , 'test@example.com')).isPresent()).toBeFalsy();

更好的方法是等到 invisibilityOf 元素然后断言。

    const expected = require('protractor').ExpectedConditions
    const btn = element(by.cssContainingText('table tbody tr td' , 'test@example.com'))
    await browser.wait(expected.invisibilityOf(btn), 5000)
    expect(btn.isPresent()).toBeFalsy();

使用预期条件等到 invisibilityOf web 元素。

invisibilityOf(elementFinder: ElementFinder): 函数; (方法) ProtractorExpectedConditions.invisibilityOf(elementFinder: ElementFinder): 函数 期望检查元素在 DOM 上是不可见的还是不存在的。这与'visibilityOf'相反。

@例子

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 — 要检查的元素

@returns returns 表示元素是否不可见的承诺的预期条件。