我正在使用Cucumber,Java和Rest-Assured开发API自动化测试。我创建了黄瓜功能:
@criarConta
Esquema do Cenario: Criar uma conta valida
Dado que realizo a chamada no <ambiente> da <api> informando <token_admin> e um email e <senha> novos
Entao devera retornar <status code> e <response>
我有dataMap类,我在其中调用API和您的响应:
public void criarConta(String srtAmbiente, String srtAPI, String srtToken, String srtSenha) {
String uriBase = srtAmbiente;
RequestSpecification apiRequest = RestAssured.given().contentType(ContentType.JSON);
int length = 15;
String email = generateRandomEmail(length);
System.out.println(email);
Map<String, String> emailContent = new HashMap<String,String>();
emailContent.put("email", email);
Map<String, Object> postContent = new HashMap<String,Object>();
postContent.put("customer", emailContent);
postContent.put("password", srtSenha);
apiRequest.header("Authorization", "Bearer "+srtToken).with().body(postContent);
Response response = apiRequest.post(uriBase+srtAPI).prettyPeek();
}
public void responseCriarContaStatus (String srtStatusCode, Response response) {
String status = response.getStatusLine();
Assert.assertTrue(status.contains(srtStatusCode));
}
还有Steps类,我将其称为Cucumber步骤和dataMap的方法:
public class steps extends dataMap {
@Test
@Dado("que realizo a chamada no (.*) da (.*) informando (.*) e um email e (.*) novos")
public void executarCriarConta(String srtAmbiente, String srtAPI, String srtToken, String srtSenha) {
dataMap data = new dataMap();
data.criarConta(srtAmbiente, srtAPI, srtToken, srtSenha);
}
@Test
@Entao("devera retornar (.*) e (.*)")
public void validarStatus (String srtStatusCode, Response response) {
dataMap data = new dataMap();
data.responseCriarContaStatus(srtStatusCode, response);
}
但是我收到以下消息错误:
cucumber.runtime.CucumberException: Don't know how to convert "<response>" into io.restassured.response.Response.
Try writing your own converter:
@cucumber.deps.com.thoughtworks.xstream.annotations.XStreamConverter(ResponseConverter.class)
public class Response {}
我该如何解决?你能帮我吗?谢谢