gpt4 book ai didi

java - 在 IntelliJ 中运行功能文件时缺少步骤

转载 作者:行者123 更新时间:2023-12-02 09:57:44 24 4
gpt4 key购买 nike

运行我的功能文件时,Intellij 一直显示“未定义步骤”。但是,我已复制这些步骤并将它们放入另一个包中,并在编辑配置的“glue”参数中添加该包名称。仍然无法工作。

我已添加功能文件,并且它没有显示任何缺少的步骤引用。我正在添加屏幕截图。我已将所有步骤添加到另一个包中。请看下面

enter image description here

CountriesSteps的代码如下

package Steps;

import Fixtures.Countries;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Assert;

public class CountriesSteps {

Countries countriesclass = new Countries();

@Given("^I generate a restful request for countries$")
public void iGenerateARestfulRequestForCountries() throws Throwable {
countriesclass.GetCountries();
}

@When("^I receive a successful country response (.*)$")
public void iReceiveASuccessfulCountryResponseResponse(int code) throws Throwable {
Assert.assertEquals(code, countriesclass.getsCode());
}

@When("^I receive a successful country response$")
public void iReceiveASuccessfulCountryResponse() throws Throwable {
Assert.assertEquals(200, countriesclass.getsCode());
}

@Then("^the api country response returns (.*)$")
public void theApiCountryResponseReturnsCountries(int countries) throws Throwable {
Assert.assertEquals(countries, countriesclass.getCount());
}

@Then("^the api country response returns (.*),(.*),(.*),(.*),(.*)$")
public void theApiCountryResponseReturnsCountriesNameCapitalPopulation(int countries, int index, String name, String capital, int population) throws Throwable {
Assert.assertEquals(countries, countriesclass.getCount());
}

@Then("^the api country response for Index (.*) returns (.*),(.*),(.*)$")
public void theApiCountryResponseForIndexIndexReturnsNameCapitalPopulation(int index, String name, String capital, int population) throws Throwable {
//Validate a few values from response
Assert.assertEquals(name, countriesclass.getcList().get(index).name);
Assert.assertEquals(capital, countriesclass.getcList().get(index).capital);
Assert.assertEquals(population, countriesclass.getcList().get(index).population);
}
}

国家代码是

package Fixtures;

import Models.CountriesData;
import com.jayway.restassured.response.Response;
import gherkin.deps.com.google.gson.Gson;
import gherkin.deps.com.google.gson.reflect.TypeToken;
import org.json.JSONArray;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import static com.jayway.restassured.RestAssured.get;

public class Countries {

private static String url;
private static int count;
private static int sCode;
private static List<CountriesData> cList;


public void GetCountries() throws Exception
{
try {
url = "http://restcountries.eu/rest/v1/all";

// make get request to fetch json response from restcountries
Response resp = get(url);

//Fetching response in JSON as a string then convert to JSON Array
JSONArray jsonResponse = new JSONArray(resp.asString());

count = jsonResponse.length(); // how many items in the array
sCode = resp.statusCode(); // status code of 200

//create new arraylist to match CountriesData
List<CountriesData> cDataList = new ArrayList<CountriesData>();

Gson gson = new Gson();
Type listType = new TypeToken<List<CountriesData>>() {}.getType();

cDataList = gson.fromJson(jsonResponse.toString(), listType);

cList = cDataList;

}
catch (Exception e)
{
System.out.println("There is an error connecting to the API: " + e);
e.getStackTrace();
}
}

//getters to return ('get) the values
public int getsCode() {
return sCode;
}

public int getCount() {
return count;
}

public List<CountriesData> getcList() {
return cList;
}

}

最佳答案

创建新的步骤定义文件时,IntelliJ 默认建议文件路径为 \IdeaProjects\RestAPI\src\main\resources\stepmethods

您的步骤定义文件夹为\IdeaProjects\RestAPI\src\test\java\Steps。确保 cucumber 没有找错地方。

关于java - 在 IntelliJ 中运行功能文件时缺少步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55871103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com