如何用另一种方法验证“有保证的请求”?

时间:2019-04-13 18:32:09

标签: java cucumber rest-assured

我在 // Create a gradient layer let gradient: CAGradientLayer = CAGradientLayer() // Create an array of colours you can use, as many colours as you require gradient.colors = [.blue.cgColor, .red.cgColor, .orange.cgColor].cgColor // Chose the locations for your colors, 0.5 is center gradient.locations = [0.0, 0.5, 1.0] // Start and end points so this goes from y: 0.0 to y: 1.0 so top to bottom gradient.startPoint = CGPoint(x: 1.0, y: 0.0) gradient.endPoint = CGPoint(x: 1.0, y: 1.0) // Set the frame gradient.frame = CGRect(x: 0.0, y: 0.0, width: yourView.frame.size.width, height: yourView.frame.size.height) // Add to view yourView.layer.insertSublayer(gradient, at: 0) 类上开发了Rest-Assured请求,但是我需要通过另一种方法来验证此请求,以调用该功能的黄瓜步骤。

我的黄瓜特色

dataMap

我试图这样做:

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>

但是public class dataMap extends tests { private Response response; private ValidatableResponse json; private RequestSpecification request; public void criarConta(String srtAmbiente, String srtAPI, String srtToken, String srtSenha) { String uriBase = srtAmbiente; String Api = srtAPI; 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); request = RestAssured.given().contentType(ContentType.JSON) .header("Authorization", "Bearer "+srtToken).with().body(postContent); response = request.when().post(uriBase+Api).prettyPeek(); } public void responseCriarContaStatus (String srtStatusCode) { json = response.then().statusLine("HTTP/1.1 200 OK"); 方法不起作用。当我将responseCriarContaStatus插入json = response.then().statusLine("HTTP/1.1 200 OK");方法中时,代码有效。

如何使用criarConta方法验证此请求?

1 个答案:

答案 0 :(得分:0)

您可以设置Response对象static,并且在定义response之后,可以在另一种方法中使用它。我正在分享您自己的方法,然后您可以对其进行编辑。如果请求成功,则statusCode将是200

private static Response response;

public void responseCriarContaStatus (String srtStatusCode) {
        JSONObject json = new JSONObject(response.getBody().asString); 
        Asser.asserEquals(srtStatusCode , json.getString("statusCode"));