当前位置: 首页 > 知识库问答 >
问题:

无法使用intellij和ubuntu运行cucumber方案,请实现步骤定义,但它们已实现

鲜于宜修
2023-03-14

我正在尝试使用几个cucumber场景运行一个示例功能文件,但当我运行它们时,我发现我没有实现步骤定义,但我实际上做到了,我有一个名为step定义的文件夹,并且在一个名为Step定义的java类中,我在其中编写了步骤

 Testing started at 20:14 ... 
Undefined scenarios:
/home/adrianjimenez/IdeaProjects/RestAssured/src/test/java/RestAssuredFramework/features/fileValidations.feature:13 # Verify if Place is being Successfully added using AddPlaceAPI
/home/adrianjimenez/IdeaProjects/RestAssured/src/test/java/RestAssuredFramework/features/fileValidations.feature:17 # Verify if Delete Place functionality is working

2 Scenarios (2 undefined)
10 Steps (10 undefined)
0m0.536s


You can implement missing steps with the snippets below:

@Given("Add Place Payload with {string}  {string} {string}")
public void add_Place_Payload_with(String string, String string2, String string3) {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@When("user calls {string} with {string} http request")
public void user_calls_with_http_request(String string, String string2) {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@Then("the API call got success with status code {int}")
public void the_API_call_got_success_with_status_code(Integer int1) {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@Then("{string} in response body is {string}")
public void in_response_body_is(String string, String string2) {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@Then("verify place_Id created maps to {string} using {string}")
public void verify_place_Id_created_maps_to_using(String string, String string2) {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}

@Given("DeletePlace Payload")
public void deleteplace_Payload() {
    // Write code here that turns the phrase above into concrete actions
    throw new cucumber.api.PendingException();
}


Process finished with exit code 0

但是我实际上实施了这些步骤,所以我不明白发生了什么,这些是我实施的步骤。

package RestAssuredFramework.stepDefinitions;

import RestAssuredFramework.resources.APIResources;
import RestAssuredFramework.resources.TestDataBuilder;
import RestAssuredFramework.resources.Utils;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;

import java.io.IOException;

import static io.restassured.RestAssured.given;
import static org.junit.Assert.assertEquals;

public class StepDefinition extends Utils {
    RequestSpecification res;
    String responseString;
   static String place_id;
    ResponseSpecification resspec;
    Response response;
    TestDataBuilder testDataBuilder = new TestDataBuilder();
    JsonPath jsonPath;

    @Given("Add Place Payload with {string}  {string} {string}")
    public void add_Place_Payload_with(String name, String language, String address) throws IOException {
        // Write code here that turns the phrase above into concrete actions
        res=given().spec(requestSpecification())
                .body(testDataBuilder.addPlacePayload(name,language,address));
    }
    @When("user calls {string} with {string} http request")
    public void user_calls_with_http_request(String resource, String method) {
        // Write code here that turns the phrase above into concrete actions
//constructor will be called with value of resource which you pass
        APIResources resourceAPI=APIResources.valueOf(resource);
        System.out.println(resourceAPI.getResource());
        resspec =new ResponseSpecBuilder().expectStatusCode(200).expectContentType(ContentType.JSON).build();

        if(method.equalsIgnoreCase("POST"))
            response =res.when().post(resourceAPI.getResource());
        else if(method.equalsIgnoreCase("GET"))
            response =res.when().get(resourceAPI.getResource());
    }
    @Then("the API call got success with status code {int}")
    public void the_API_call_got_success_with_status_code(Integer int1) {
        // Write code here that turns the phrase above into concrete actions
        assertEquals(response.getStatusCode(),200);
    }
    @Then("{string} in response body is {string}")
    public void in_response_body_is(String keyValue, String Expectedvalue) {
        // Write code here that turns the phrase above into concrete actions

        assertEquals(getJsonPath(response,keyValue),Expectedvalue);
    }

    @Then("verify place_Id created maps to {string} using {string}")
    public void verify_place_Id_created_maps_to_using(String expectedName, String resource) throws IOException {
        // requestSpec
        place_id=getJsonPath(response,"place_id");
        res=given().spec(requestSpecification()).queryParam("place_id",place_id);
        user_calls_with_http_request(resource,"GET");
        String actualName=getJsonPath(response,"name");
        assertEquals(actualName,expectedName);
    }
    //delete scneario
    @Given("DeletePlace Payload")
    public void deleteplace_Payload() throws IOException {
        // Write code here that turns the phrase above into concrete actions
        res =given().spec(requestSpecification()).body(testDataBuilder.deletePlacePayload(place_id));
    }
}

这是我的特征文件

Feature: Validating Place API's
  @AddPlace @Regression
  Scenario Outline: Verify if Place is being Successfully added using AddPlaceAPI
    Given Add Place Payload with "<name>"  "<language>" "<address>"
    When user calls "AddPlaceAPI" with "POST" http request
    Then the API call got success with status code 200
    And "status" in response body is "OK"
    And "scope" in response body is "APP"
    And verify place_Id created maps to "<name>" using "getPlaceAPI"

    Examples:
      |name      | language |address           |
      |peter |  Spanish |Aguascalientes, st|
#   |BBhouse | Spanish  |Sea cross center  |

  @DeletePlace @Regression
  Scenario: Verify if Delete Place functionality is working

    Given DeletePlace Payload
    When user calls "deletePlaceAPI" with "POST" http request
    Then the API call got success with status code 200
    And "status" in response body is "OK"

intellij版本

IntelliJ IDEA 2019.3.2 (Community Edition)
Build #IC-193.6015.39, built on January 21, 2020
Runtime version: 11.0.5+10-b520.30 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 5.0.0-37-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 725M
Cores: 4
Registry: 
Non-Bundled Plugins: gherkin, cucumber-java

pom.xml

http://maven.apache.org/xsd/maven-4.0.0.xsd“”

<groupId>org.example</groupId>
<artifactId>RestAssured</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <source>8</source>
        <target>8</target>
    </configuration>
</plugin>  

io.cucumbercucumber

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.8.0</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>4.1.2</version>
    <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind

--

这是test runner类

package RestAssuredFramework.cucumber.Options;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/RestAssuredFramework",
        glue = {"StepDefinition"}

        ) 

public class TestRunner {
}

我还在intellij Cucumber for java 193.5662.7 Gherkin 193.6015.53中安装了以下插件

共有1个答案

漆雕疏珂
2023-03-14

您需要在@CucumberOptions注释中提供正确的胶水

glue = {"RestAssuredFramework.stepDefinitions"}

glue-是存储步骤定义的包名称

 类似资料:
  • 自从我升级到最新的社区版IntelliJ 15.0.3以来,每当我使用alt-enter从功能定义文件自动生成步骤定义时,它都会以驼峰大小写而不是带下划线的常规样式创建方法。 例如,它过去是这样生成的 但现在它产生了通常的camelCase惯例: 有没有办法把这个设置改回第一种样式? 谢谢

  • 我要驱动执行的代码是: 因此,在一个实例中(当传入string=“have”时),我希望向我的方法中传入一个值,如objpolicyamendrequest.setcolor(“blue”); 另一个方法(当传递给string=“have not”时)我不想传递任何东西给这个方法。 我想我需要遵循if语句,但不确定Cucumber是否有帮助。 希望我说得有道理。我对编程还是有点陌生!

  • 我正在用cucumber和ruby实现自动化。我的情况如下。 为了实现,我在第二步中进行了迭代以单击所有链接。 为此,我每次都必须回到主页,然后进行验证。我是否必须每次重复第二步实现,或者我可以跳过第三步并在第二步中实现所有内容?

  • 好的,所以我正在使用IntelliJ进行一个项目,并试图利用它的cucumber功能。我没有使用过cucumber的java风格,但IntelliJ似乎希望步骤定义文件位于相对于特性文件的特定位置。 我在Intellij12和其他来源中找到了:如何定义cucumber的步骤定义位置,这些来源指出我能够添加运行配置的“glue”属性,它告诉cuke在哪个包中查找步骤文件。因此,我可以通过idea运行

  • 我试着做了一个简单的测试来尝试黄瓜是如何与柏树一起工作的,但是我没有设法解决标题中描述的问题。 贝娄是我的js文件: 这是一个屏幕截图,其中包含问题输入图像描述 在尝试了很多事情,但我没有设法解决这个问题。有什么建议吗?

  • 有人知道为什么当我尝试运行这个步骤时,它可能会显示为“未定义”吗?下面您将看到一个示例,我试图用cucumber场景大纲进行实验,我的“Examples:”部分有一个条目。另外,页面对象和步骤def也包含在内。出于某种原因,当我尝试运行它时,我得到如下错误: 下面是特性文件 注意:我在框架中有一个通用构造函数,因此在编写测试时不必导入任何页面。有人能帮助我理解第3步的错误是什么,它一直显示未定义?