如何从黄瓜的挂钩中跳过测试用例的执行 [英] How to skip execution of test case from the Hooks in cucumber

查看:119
本文介绍了如何从黄瓜的挂钩中跳过测试用例的执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当viewPort很大时,我才跳过测试案例@bannerVerificationSMMDView

I have to skip execution of the test case @bannerVerificationSMMDView only when the viewPort is Large

@Before
    public void beforestartUp(Scenario scenario) throws IOException {    
     boolean runTest = true;
        if (viewPort.contains("LARGE")) {
            System.out.println("for Scenario " + scenario.getName() + " tagname are");
            List<String> tags = (List<String>) scenario.getSourceTagNames();
            for (String tagName : tags) {
                if (tagName.contains("bannerVerificationLView"))
                    runTest = false;
            }
            try {
                Assume.assumeTrue(runTest);
            } catch (AssumptionViolatedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
   }

不确定原因,但例外没有被捕获

Not sure why, but exception is not getting caught

推荐答案

抛出 AssumptionViolatedException 跳过执行

@Before(value="@bannerVerificationSMMDView")
public void before(Scenario scenario) {

    if(viewPort.contains("LARGE"))
        throw new AssumptionViolatedException("Skipping as view is LARGE");

}

如果您使用的是黄瓜版3 plus,则可以使用改为使用 @BeforeStep 批注。这将允许您运行方案中的所有先前步骤,如果不满足条件,则跳过方案中的其余步骤

If you are on cucumber version 3 plus, you can use a @BeforeStep annotation instead, keep everything else same. This will allow you to run any previous steps in the scenario and if condition is not met then skip the rest of the steps in the scenario

这篇关于如何从黄瓜的挂钩中跳过测试用例的执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆