简体   繁体   English

在JBehave方案中步骤失败后继续执行

[英]Continue Execution after step fails in JBehave scenario

I am using Selenium Webdriver with JBehave. 我在JBehave中使用Selenium Webdriver。 My Jbehave Story contains few scenarios with some repetitive steps as shown in the below steps and I have created a common function to execute them. 我的Jbehave故事包含一些场景,其中包含一些重复步骤,如以下步骤所示,并且我创建了一个通用函数来执行它们。

Scenario: 25. Validate Column from Database 
Given I open application URL 
And I login with username "username1" and password "password1"
Then I validate the "column1" from database
Then I validate the "column2" from database
Then I validate the "column3" from database
Then I Logout of the Portal

This is my common function to validate the column from database 这是我验证数据库中列的常用功能

@Then("I validate the \"$column\" from database")
public void validateColumnFromDB(String column)
{
    if(column.equals("column1"))
       getColumnFromDB(propertiesConfiguration.getString("column1"));
    else if(column.equals("column2"))
       getColumnFromDB(propertiesConfiguration.getString("column2"));
    else if (column.equals("column3"))
       getColumnFromDB(propertiesConfiguration.getString("column3"));
}

I used Junit ErrorCollector() but after execution, JBehave says "All the tests passed" even though there are some failures and the ErrorCollector() collected them. 我使用了Junit ErrorCollector()但是执行后,JBehave会说“所有测试都通过了”,即使有一些失败并且ErrorCollector()收集了它们。 Atleast JBehave should say some steps failed. Atleast JBehave应该说某些步骤失败了。

My question is I want to continue the execution in JBehave even after validaiton of any one of the column fails (ony one of Step mentioned in Scenario). 我的问题是,即使任何一列的验证失败(场景中提到的步骤之一),我也想继续在JBehave中执行。

Thanks for your help 谢谢你的帮助

I would do cheking all of columns in a single step, in this way: 我会用这种方法一步一步检查所有列:

Scenario: 25. Validate Column from Database 

Given I open application URL 
Then I validate the following columns: "column1,column2,column3" from database

@Then("I validate the following columns: \"$columns\" from database")
public void then_i_walidate_columns_from_databale( List<String> columns){
    String columnsWithError = "";
    boolean validationResult = true;
    for( String column : columns){
        boolean validationResultOfCurrentColumn = ( null != getColumnFromDB(column));
        validationResult &= validationResultOfCurrentColumn;
        if( ! validationResultOfCurrentColumn ){
            columnsWithError += column + " ";
        }
    }
    Assert.assertTrue("The following columns don't pass the validation: " + columnsWithError, validationResult);
}

Are you throwing an exception in a JBehave step when an error occurs? 当发生错误时,您是否在JBehave步骤中引发异常? JBehave relies on knowing there is an error by your thrown exception. JBehave依靠您抛出的异常知道是否有错误。 I'm wondering whether the ErrorCollector is consuming your thrown exceptions therefore your errors are not reaching JBehave, hence JBehave thinks there are no errors. 我想知道ErrorCollector是否正在使用您抛出的异常,因此您的错误没有到达JBehave,因此JBehave认为没有错误。

By default, the story runners are configured to fail-fast , ie the execution will stop at first failed story (but will complete execution of the all the scenarios in the story first). 默认情况下,故事运行者配置为快速失败 ,即执行将在第一个失败的故事处停止(但将首先完成故事中所有场景的执行)。 To allow the generation of a complete stories view (reporting how many stories failed), the runners need to be enabled to run stories with ignoreFailureInStories flag set to true . 为了允许生成完整的故事视图(报告失败的故事数目 ),需要使跑步者能够运行将ignoreFailureInStories标志设置为true的故事。

Source: http://jbehave.org/reference/stable/running-stories.html 资料来源: http : //jbehave.org/reference/stable/running-stories.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM