量角器 - 是否可以使用单个 'expect' 语句对一个元素进行多次检查?

Protractor - is it possible to do multiple check on an element with a single 'expect' statement?

我想知道是否可以在同一个 'expect' 语句中链接对元素的检查。

例如,而不是这样:

expect(loginPage.getLoginPageBackground().isPresent()).toBeTruthy();
expect(loginPage.getLoginPageBackground().isDisplayed()).toBeTruthy();

像这样:

expect(loginPage.getLoginPageBackground().isPresent().isDisplayed()).toBeTruthy();

这只是一个随机示例。我知道这行不通,但我想你明白了。如果有任何解决方法,想听听。

谢谢

答案是否定的,你不能那样做。请提供完整的上下文,以便我可以建议您进行一轮工作以实现您想要的。

实际上对于你的问题,你不需要单独做 isPresent 和 isDisplayed 检查,因为 isDisplayed 已经在里面做了 isPresent 检查:

expect(loginPage.getLoginPageBackground().isDisplayed()).toBeTruthy('Optional error message here');

仅供参考:如果 DOM 中不存在元素,isDisplayed() 会抛出错误。

但如果您想断言其他条件 - 您可以使用 ExpectedConditions 函数 - and(), or(), not() 将各种检查组合在一起:

const EC = ExpectedConditions
const myElem = $('div')
await browser.wait(
      EC.and(
             EC.visibilityOf(myElem),
             EC.textToBePresentInElement(myElem, 'hello world!'),
      ),
      10000 // timeout
      `Optional error message`
)

http://www.protractortest.org/#/api?view=ProtractorExpectedConditions