等待空手道测试的2种不同结果



我们有一个需要更多时间来构建的组件,我们想用空手道测试它:

retry(120, 1000).waitForText('h1', 'Successful')

在h1元素中可以有更多的状态(Waiting, Building),但是错误通常会立即显示。我们如何将waitForText放到这两种最终状态之间的条件和差异中呢?像这样

retry(120, 1000).if (waitForText('h1', 'Successful')) { ...continue with tests } elseif(waitForText('h1', 'Error')) { karate.fail('Error occured') }

请阅读optional()exists()的文档:https://github.com/intuit/karate/tree/master/karate-core#optional

也很可能waitForAny()将解决这个问题:https://github.com/intuit/karate/tree/master/karate-core#waitforany

* retry(120, 1000).waitForAny('{h1}Successful', '{h1}Error')
* if exists('{h1}Error') karate.fail('error occurred')

上面的第一行实际上将返回Element,因此您可以在第二行更聪明。有很多选择,找到最适合你的方式。

相关内容

最新更新