在多个黄瓜步骤定义中使用多个软断言时,黄瓜范围报告显示已通过

时间:2019-05-14 06:50:41

标签: java extentreports

假设我有如下代码:

        public class Class1 
    {
    SoftAssert softAssert=null; 
    public Class1() 
    { softAssert=new SoftAssert();
    } 
    @Given("^some feature step1$") 
    { **somecode Reporter.addStepLog("condition failed.Hence test failed"); softAssert.assertTrue(false); 
    }

    @And("^some feature step1$")
    { **somecode Reporter.addStepLog("condition failed.Hence test failed"); softAssert.assertTrue(false); 
    } @After() {
    softAssert.AssertAll(); 
    }

    }

当我执行上面的代码时,它表明该场景在测试NG中失败。但是,在“黄瓜范围”报告中,所有步骤均已通过(尽管仅显示错误消息)

1 个答案:

答案 0 :(得分:0)

如果出现软件断言失败,我们将处理该异常,因为该测试用例没有被标记为“失败”。相同的内容将传递到范围报告,下面是Hooks中的范围代码,这里的控制权将传递给else语句。

@AfterTest
    public void afterScenario(Scenario scenario){
        String videoFile= Utility.stopAUTTestRecorder();
        try{
            if(scenario.isFailed()){
                //byte[] screenshot = ((TakesScreenshot)DriverManager.getDriver()).getScreenshotAs(OutputType.BYTES);
                //scenario.embed(screenshot, "image/png");
                ExtentTestManager.addScreenShotsOnFailure();
                //------------------------- Attaching video in the Report -------------------------
                String failedTestVideo = "<a href=\"" + videoFile + "\">Download Failed Test Case Video</a>";
                ExtentTestManager.embedVideoLink(failedTestVideo);
                //scenario.write(failedTestVideo);
                log.info("***** Scenario Execution is - "+ scenario.getStatus().firstLetterCapitalizedName() + " (Completed) : at " + Utility.getCurrentTime() +" *****");
                BaseSteps.getInstance().quit();
            }else {
                if(ExtentTestManager.getTest().getStatus().toString().equalsIgnoreCase("pass")) {
                    ExtentTestManager.scenarioPass();
                    log.info("***** Scenario Execution is - "+ scenario.getStatus().firstLetterCapitalizedName() + " (Completed) : at " + Utility.getCurrentTime() +" *****");
                    BaseSteps.getInstance().quit();
                }else if (ExtentTestManager.getTest().getStatus().toString().equalsIgnoreCase("warning")){
                    ExtentTestManager.scenarioWarning();
                    log.info("***** Scenario Execution is - "+ scenario.getStatus().firstLetterCapitalizedName() + " (Completed) : at " + Utility.getCurrentTime() +" *****");
                    BaseSteps.getInstance().quit();
                }
            }

解决方案-我们需要明确调用“范围报告:失败方法()”,并使其失败

// You can customize your methods as per your framework requirement - 
ExtentTestManager.logFailed("Some message");