@After 不起作用(带有 SenerityBDD 的黄瓜)

@After doesn't work (Cucumber with SenerityBDD)

我的问题:我正在使用带有 senerityBDD 的 Cucumber JAVA。在我的项目中,@after not working after scenario as senerity document I read.

我的钩子class:

package com.TestSuite;

import cucumber.api.CucumberOptions;
import cucumber.api.java.After;
import net.serenitybdd.core.Serenity;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
    
import static com.netdreamers.utils.Performance.PerformanceController.*;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "src/test/resources/features", tags = "@testCase")

public class TestSuite{

    @BeforeClass
    public static void beforeClass(){
        System.out.println("Start BeforeClass");   
   }

    @AfterClass
    public static void afterClass() {
       System.out.println("Start AfterClas");   

    }

    @After
    public void afterScenario(){
        System.out.println("After Scenario");
    }
}

我的专题文件:

Feature: Access to Url

  Background:

  Scenario Outline: Access to Url
    Given I access to the Url at line "<index>"
    Examples:
      | index |
      | 0     |
      | 1     |

正如预期的那样,@after 注释应该可以工作,它应该在场景之后调用。所以 请有人告诉我当 Scenario Ouline 重复示例时 @after 注释在 2 循环后不起作用的原因 table“索引”变量?

AFAIK @After 仅适用于步骤代码。将您的选项更新为

@CucumberOptions(features = "src/test/resources/features", glue = 
        "com.testsuite.steps", tags = "@testCase" )

并将后面的代码移到新的步骤class

 package com.testsuite.steps;

 import cucumber.api.java.After;

 public class TestSteps {
    
        @After
        public void afterScenario(){
            System.out.println("After Scenario");
        }
 }