【发布时间】:2022-01-09 06:07:19
【问题描述】:
总结: 当我尝试实现这个简单的测试时,我是使用带有 REST 的 Cucumber 的新手,该测试将从 XML 响应中获取 nuValue,然后验证所有值是否超过 4000,尝试运行测试跳过的测试时出现一些错误
这是我的功能文件
Feature: This Test will validate the value of numViews to be more than 4000
Scenario: The user will be able to validate that numValue values are greater than 400
Given The API url
Then Validates the numValue value greater than 4000
这是步骤定义步骤文件
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import java.util.List;
public class MyStepdefs {
Response response;
public List<String> x;
@Given("The API url")
public void theAPIUrl() {
RestAssured.baseURI=("https://www.colourlovers.com");
String path = "/api/patterns";
response = RestAssured
.given()
.header("User-Agent:", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36")
.get(path)
.then().extract().response();
List<String> numViewsList = response.xmlPath().getList("patterns.pattern.numViews");
x = numViewsList;
}
@Then("Validates the numValue value greater than {int}")
public void validatesTheNumValueValueGreaterThan() {
for (String x : numViewsList) {
int numViewsValue = Integer.parseInt(x);
if (numViewsValue > 4000){
System.out.println("Success!");
assert(true);
}
else
{
System.out.println("Fail!");
assert(false);
}
}
}
}
我在控制台中收到此错误
Step undefined
You can implement this step and 1 other step(s) using the snippet(s) below:
@Given("The API url")
public void the_api_url() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
@Then("Validates the numValue value greater than {int}")
public void validates_the_num_value_value_greater_than(Integer int1) {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
【问题讨论】:
-
可能是您错误地在运行器文件中配置了 stepDefinition 文件位置。
-
没有从功能文件运行它
标签: java cucumber rest-assured