如何从黄瓜中的 Hooks 跳过测试用例的执行

How to skip execution of test case from the Hooks in cucumber

仅当视口较大时,我才必须跳过测试用例@bannerVerificationSMMDView 的执行

@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();
            }
        }
   }

不知道为什么,但没有捕获到异常

抛出一个AssumptionViolatedException跳过场景的执行。

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

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

}

如果您使用的是 cucumber 版本 3 plus,则可以改用 @BeforeStep 注释,其他一切保持不变。这将允许您 运行 场景中的任何先前步骤,如果不满足条件,则跳过场景中的其余步骤