如何解决使用 Serenity RestAssured 时出现 noBaseStepListener 错误
我正在尝试用黄瓜实现 Rest Assured 框架
我面临一个奇怪的情况,我已经定义了我的功能文件的所有步骤定义,然后当我运行我的功能文件时,我也收到如下错误:-
Step undefined
You can implement this step and 3 other step(s) using the snippet(s) below:
@Given("I create new service by using create service API data")
public void i_create_new_service_by_using_create_service_api_data() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
当我从 Junit Testrunner 运行相同的程序时,我收到如下错误:-
INFO net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated - No BaseStepListener,POST /services not registered.
在我的框架中,我定义了包含基类文件的 basepackage,如下所示:-
public class TestBase {
public static Properties propertyConfig = new Properties();
public static FileInputStream fis;
public static Response response;
public static RequestSpecification requestSpecification;
public static void loadPreConfigs(){
try {
fis = new FileInputStream("./src/test/resources/ConfigurationURLs/config.properties");
try {
propertyConfig.load(fis);
} catch (IOException e) {
e.printstacktrace();
}
} catch (FileNotFoundException e) {
e.printstacktrace();
}
RestAssured.baseURI=propertyConfig.getProperty("BaseURI");
}
}
然后我有一个 ApiCall 包,其中包含所有具有请求规范和相应响应存储其余 API 调用的类文件 APICall 文件如下:-
public class PostRequestCall extends TestBase {
private static String productVal;
public static int getProductVal() {
return Integer.parseInt(productVal);
}
public static void setProductVal(String productVal) {
PostRequestCall.productVal= productVal;
}
public RequestSpecification definePostRequest(){
requestSpecification= SerenityRest.given();
requestSpecification.contentType(ContentType.JSON);
return requestSpecification;
}
public Response CreateService(String serviceName){
JSONObject jsonObject=new JSONObject();
jsonObject.put("name",serviceName);
response=definePostRequest().body(jsonObject).post(propertyConfig.getProperty("createService"));
return response;
}
}
public class PostRequestSteps {
PostRequestCall postRequestCall=new PostRequestCall();
@Step
public RequestSpecification setPostSpecification(){
TestBase.requestSpecification=postRequestCall.definePostRequest();
return TestBase.requestSpecification;
}
@Step
public Response setPostRequestCall(String serviceName){
TestBase.response=postRequestCall.CreateService(serviceName);
return TestBase.response;
}
}
public class PostRequest_StepDeFinitions {
String serviceID;
@Steps
PostRequestSteps postRequestSteps=new PostRequestSteps();
@Before
public void setUp() {
TestBase.loadPreConfigs();
}
@Given("I create new service by using create service API data")
public void i_create_new_service_by_using_create_service_api_data() {
postRequestSteps.setPostSpecification();
}
@When("I provide valid name {string} for service creation")
public void i_provide_valid_name_for_service_creation(String serviceName) {
TestBase.response=postRequestSteps.setPostRequestCall(serviceName);
}
@And("I save the id of created service")
public void i_save_the_id_of_created_service() {
serviceID=TestBase.response.jsonPath().get("id").toString();
PostRequestCall.setProductVal(serviceID);
}
@Then("I validate status code {int}")
public void i_validate_status_code(int statusCode) {
Assert.assertEquals(TestBase.response.getStatusCode(),statusCode);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。