java - 在 IntelliJ 中运行功能文件时缺少步骤
问题描述
Intellij 在运行我的功能文件时一直说未定义步骤。但是,我已经复制了这些步骤并将它们放入另一个包中,并将该包名称添加到编辑配置的“胶水”参数中。还是行不通。
我已经添加了功能文件,它没有显示任何缺少的步骤参考。我正在添加屏幕截图。我已经在另一个包中添加了所有步骤。请看下面
CountrySteps 的代码如下
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
. 确保黄瓜没有找错地方。
推荐阅读
- java - 如何将 BufferedImage 作为输入加载到 DeepLearning4j 中的分类器?
- java - Java:如何进行图像处理(平移、缩放、翻转和旋转)?
- javascript - 为什么我在使用 javascript 数组中的 .length 属性时收到此错误?
- performance - 使用 beanshell 脚本在 jmeter 中的线程之间共享哈希映射
- r - 将图例标签和颜色与闪亮的饼图段颜色匹配
- c# - 通过 Restful API 从云端下载大文件的最佳实践
- css - Search Console 说我的横向网站在手机上是个问题
- mysql - docker-compose 没有正确启动 mysql:8
- javascript - 如何以 javascript 方式创建 php getter 和 setter
- angular - 如何使用 *ngFor 循环我的数据对象?