守夜人一旦满足可见条件就无法继续测试

Unable to continue the test once the nightwatch isVisible condition has met

我正在使用 nightwatch isVisible 命令来检查元素是否可见。这里的场景是,如果元素是可见的,我想点击那个元素并继续测试。如果该元素不可见,我不想单击该元素,我仍然想继续测试。 因此,我无法将代码包装在 else 块中。

这里的问题是,一旦条件满足,测试就不会继续。我相信它不可能从那个条件中出来。请在下面找到我的代码并提供您的建议。

        `       
        const result = await  this.myAccountTest.isVisible('@btnremove');
        console.log('isVisible result', result);
        if(await result.value==true)
        {
            await this.myAccountTest.remove();
            await this.myAccountTest.clickConfirm();

        }
        // rest of the code to continue
        await this.myaccountTest.create();
        //more code`

我认为您在错误的地方使用 await。也许你可以简单地编码如下。

const result = await this.myAccountTest.isVisible('@btnremove');
console.log('isVisible result', result);
if (result.value) {
  this.myAccountTest.remove();
  this.myAccountTest.clickConfirm();
}
// rest of the code to continue
await this.myaccountTest.create();