微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Katalon Studio 中跳过测试用例

如何解决如何在 Katalon Studio 中跳过测试用例

我们如何在 Katalon Studio 中跳过特定的测试用例?

对于我的应用程序,有不同要求的不同站点,因此所有功能不会出现在所有站点中。我想让脚本保持动态,所以我希望脚本在没有找到几个链接的情况下跳过一些测试用例。

 @Keyword
        def ClickonLinkText(String text) {
            try {
                WebDriver webDriver = DriverFactory.getWebDriver()
                KeywordUtil.logInfo("Clicking Link text")
                if(webDriver.findElement(By.linkText(text)).click()){
                KeywordUtil.logInfo("found")
            }else{
                KeywordUtil.logInfo("Not found")
// Need to skip the test case if not found!!
            }
                KeywordUtil.markPassed("Clicked on link text successfully")
            } catch (WebElementNotFoundException e) {
                KeywordUtil.markFailed("Link text not found")
            } catch (Exception e) {
                KeywordUtil.markFailed("Fail to click on the Link text")
            }
        }

解决方法

您可以针对该用例使用测试侦听器:

  1. 在测试资源管理器中,右键单击测试侦听器 > 新建 > 新建测试侦听器
  2. 在对话框中,为您的测试用例命名(在我的示例中为“ExampleListener”),并选中“在测试用例方法之前生成样本” enter image description here
  3. 检查所需条件,如果为真则跳过测试用例:
class ExampleListener {
    /**
     * Executes before every test case starts.
     * @param testCaseContext related information of the executed test case.
     */
    @BeforeTestCase
    def sampleBeforeTestCase(TestCaseContext testCaseContext) {
        if(condition){
            testCaseContext.skipThisTestCase()
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。