Protractor 量角器-是否可以使用单个';期望';陈述

Protractor 量角器-是否可以使用单个';期望';陈述,protractor,Protractor,我想知道是否有可能在同一个'expect'语句中对一个元素进行连锁检查。例如,代替此: expect(loginPage.getLoginPageBackground().isPresent()).toBeTruthy(); expect(loginPage.getLoginPageBackground().isDisplayed()).toBeTruthy(); 大概是这样的: expect(loginPage.getLoginPageBackground().isPresent().isD

我想知道是否有可能在同一个'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(“此处的可选错误消息”)

仅供参考:isDisplayed()在DOM中不存在元素的情况下抛出错误

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

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

好吧,我的目标是避免像“loginPage.getLoginPageBackground()”那样多次调用同一个函数。我想做进一步的检查,一旦我得到的元素,而不是做另一个电话,做另一个检查我不明白你为什么要这样做。您可以执行类似于让ele=loginPage.getLoginPageBackground()的操作并多次使用ele,但仍然是一样的。从性能上看,如果这就是你所想的,那也没什么区别。而且我认为多次使用loginPage.getLoginPageBackground()不会有任何问题。谢谢你的回答。这看起来像是我一直在找的东西。为了澄清,使用“预期条件”检查和“预期”断言之间有什么区别