【问题标题】:Is there any way that I conditionally skip a scenario in Cucumber java?有什么方法可以有条件地跳过 Cucumber java 中的场景?
【发布时间】:2016-09-08 12:59:16
【问题描述】:

有什么方法可以让我有条件地跳过 Cucumber java 中的某个场景?

在下图中,当新闻稿部分没有可用数据时,我想跳过为数据检查编写的场景。

我打算先检查没有数据可用的场景,如果执行成功则跳过其余的场景。

添加功能文件以加深理解:

背景: 显示给定主页 当我导航到“XYZ”菜单时 然后应该显示“新闻稿”部分

@News    
And "Press release" section should I check for No data present

@News 
And "Press release" section should feature "latest News" portion 
And "Press release" section having "abc" link for pagination

@News
And in "Press release" section click on news link 
Then news details should be displayed

在上面的文件中, 如果@News
我应该检查“新闻稿”部分是否没有数据存在

返回肯定的结果,然后我在标签@News 下的其余场景应该被秒杀,而不是在每个场景中检查相同的条件。

【问题讨论】:

  • 您是在谈论场景中的步骤还是跳过整个场景?您可以在问题中添加您的功能文件吗?
  • 您可以有一个步骤来检查数据并在未找到数据时添加数据。使用步骤作为前提。给定......我有一些数据然后......,或者我没有任何数据。
  • 添加了示例功能文件
  • 可以使用黄瓜线束来实现(我对此不太了解,如果有人知道可以提供帮助),如下面的链接所述? search.cpan.org/~bdr/Test-BDD-Cucumber-0.17/lib/Test/BDD/… 致电。 scenario_done 分别在场景执行开始和结束时调用。两种方法都接受 Test::BDD::Cucmber::Model::Scenario 模块和数据集哈希。
  • 请问有人对此查询有任何解决方案吗?

标签: java cucumber bdd


【解决方案1】:

如果您使用QAF-Gherkin,您可以使用step listener 来实现。例如,在步骤失败时将原始异常扭曲到 AutomationError,您的场景将被跳过而不是失败。您还可以设置 step-meta-data 并在侦听器中使用它。这是代码示例:

    //This will called on step failure
    @Override
    public void onFailure(StepExecutionTracker stepExecutionTracker) {
        TestStep step = stepExecutionTracker.getStep();
        String myCustomMetaDataVal = (String) step.getMetaData().get("my-custom-meta-data");
        if ("somevlaue".equalsIgnoreCase(myCustomMetaDataVal)) {
            Throwable originalThrowable = stepExecutionTracker.getException();
            stepExecutionTracker.setException(new AutomationError("meaningful message", originalThrowable));
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    相关资源
    最近更新 更多