@BeforeStep 不会被调用

huangapple go评论50阅读模式
英文:

@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..

         &lt;dependency&gt;
            &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
            &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
            &lt;version&gt;${cucumber.version}&lt;/version&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
            &lt;artifactId&gt;cucumber-testng&lt;/artifactId&gt;
            &lt;version&gt;${cucumber.version}&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;

        &lt;dependency&gt;
            &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
            &lt;artifactId&gt;cucumber-core&lt;/artifactId&gt;
            &lt;version&gt;${cucumber.version}&lt;/version&gt;
        &lt;/dependency&gt;

Let me know if it helps.

huangapple
  • 本文由 发表于 2020年7月30日 09:04:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/63164652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定