英文:
@BeforeStep doesn't get called
问题
我正在尝试使用@BeforeStep和@AfterStep钩子,但似乎标签没有被调用。但@Before和@After钩子正常工作。
import cucumber.api.java.After;
import cucumber.api.java.AfterStep;
import cucumber.api.java.Before;
import cucumber.api.java.BeforeStep;
@BeforeStep
public void before_step(Scenario scenario, Step step){
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@AfterStep
public void afterStep(){
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@After
public void afterTest() {
System.out.println("after test");
}
@Before
public void beforeTest() {
System.out.println("before test");
}
在过去,我使用了info.cukes组,但今天我将它们更改为io.cucumber,以便可以使用@AfterStep和@BeforeStep,但没有成功。过去使用info.cukes和现在使用io.cucumber都可以正常工作的是@After和@Before钩子。
英文:
I am trying to use the @BeforeStep /@AfterStep hooks but it seems that the tags doesn't get called. But the @After /@Before hooks work just fine.
import cucumber.api.java.After;
import cucumber.api.java.AfterStep;
import cucumber.api.java.Before;
import cucumber.api.java.BeforeStep;
@BeforeStep
public void before_step(Scenario scenario, Step step){
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@AfterStep
public void afterStep(){
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
@After
public void afterTest() {
System.out.println("after test");
}
@Before
public void beforeTest() {
System.out.println("before test");
}
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.0</version>
</dependency
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
In the past, I was using info.cukes group but today I changed them to io.cucumber so I can use @AfterStep and @BeforeStep but to no avail. The @After and @Before hooks worked fine in the past with info.cukes and also now with io.cucumber.
答案1
得分: 3
你可以尝试从cucumber的io包中导入库,而不是从cucumber.api导入。
以下是这些类:
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.AfterStep;
import io.cucumber.java.BeforeStep;
你也可以添加以下依赖:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
</dependency>
如果有帮助,请告诉我。
英文:
Can you try importing library from cucumber's io package instead of cucumber.api
below are the classes
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.AfterStep;
import io.cucumber.java.BeforeStep;
Can you add following dependencies too..
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>${cucumber.version}</version>
</dependency>
Let me know if it helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论