首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >我不能在Protractor和Jasmine中使用IF和EXPECT

我不能在Protractor和Jasmine中使用IF和EXPECT
EN

Stack Overflow用户
提问于 2019-07-17 03:16:36
回答 1查看 51关注 0票数 1

这是一种情况。

代码语言:javascript
复制
if (await browser.wait(ExpectedConditions.presenceOf(this.collapsedContinent), 500)) {
            await this.helper.click(this.expandCountry);
            await this.helper.click(this.chkcountry);
        } else {
            await this.helper.click(this.chkcountry);
        }

我期望expect返回true或false,然后执行后续操作。看起来我好像做错了什么。

我知道expect返回一个promise,但是有没有什么方法可以让expect返回一个true或false,然后从那里开始呢?

我可以使用其他方法,只要它检查元素的存在。我使用的是异步等待,所以我不需要doThis.then(doThat);

我完全想避免使用.then()

EN

回答 1

Stack Overflow用户

发布于 2019-07-17 21:33:31

或者,如果您确实需要在检查之前等待一段时间,browser.wait不会返回true/false,但您可以使用.then来实现:

代码语言:javascript
复制
if (await browser.wait(ExpectedConditions.presenceOf(this.collapsedContinent), 500).then(()=> true, err=> false)) {
    await this.helper.click(this.expandCountry);
    await this.helper.click(this.chkcountry);
} else {
    await this.helper.click(this.chkcountry);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57064059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档