Пропущены шаги при запуске файла объектов в IntelliJ - PullRequest
0 голосов
/ 26 апреля 2019

Intellij продолжает говорить Undefined Step при запуске моего файла функций.Однако я скопировал шаги и поместил их в другой пакет и добавил это имя пакета в параметр «glue» для редактирования конфигураций.Все еще не работает.

Я добавил файл функций, и он не показывает пропущенные ссылки на шаги.Я добавляю скриншот.Я добавил все шаги в другой пакет.Пожалуйста, смотрите ниже

enter image description here

Код для 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;
}

}

1 Ответ

1 голос
/ 29 апреля 2019

При создании нового файла определения шага IntelliJ по умолчанию предлагает путь к файлу \IdeaProjects\RestAPI\src\main\resources\stepmethods.

Ваша папка определения шага - \IdeaProjects\RestAPI\src\test\java\Steps. Убедитесь, что огурец не выглядит в неправильном месте.

...