RestAssured中的超时错误,而服务在postman/soapUI中给出响应 [英] Timeout error in RestAssured whereas the service giving response in postman/soapUI

查看:359
本文介绍了RestAssured中的超时错误,而服务在postman/soapUI中给出响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码给出超时错误,而服务在postman/soapUI中给出响应

我正在尝试使其余服务自动化.该服务在soapUI上运行良好,而在restAssured中自动运行时却给出了超时错误.

I am trying to automate the rest service. The service working fine soapUI whereas when automating in restAssured giving timeout error.

import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;

import io.restassured.RestAssured;
import io.restassured.response.Response;

public class AddUsers {

    @Test

    public void addUsers()

    {

        RestAssured.baseURI = "http://reqres.in";

        given().header("Content-Type","application/json").body("{\r\n" + 
                "    \"name\": \"Mallik\",\r\n" + 
                "    \"job\": \"TestLead\"\r\n" + 
                "}").when().post("/api/users");



    }


}

推荐答案

尝试使用以下内容.我已经为addUsers和getUsers添加了代码.我建议您为传递POST端点的正文创建POJO类.

Try using the below. I have added code for addUsers and getUsers. I'd suggest you to create POJO class for the body you are passing the POST endpoint.

import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import net.serenitybdd.rest.SerenityRest;

public class Test11 {

    static Response response;

    @Test
    public void addUsers() {
        RestAssured.baseURI = "http://reqres.in";
        response = SerenityRest.given().urlEncodingEnabled(false).relaxedHTTPSValidation().contentType(ContentType.JSON)
                .log().all()
                .when().body("{\r\n" + 
                        "    \"name\": \"Mallik\",\r\n" + 
                        "    \"job\": \"TestLead\"\r\n" + 
                        "}")
                .post("/api/users")
                .then().log().all().extract().response();
    }

    @Test
    public void getUsers() {
        RestAssured.baseURI = "http://reqres.in";
        response = SerenityRest.given().urlEncodingEnabled(false).relaxedHTTPSValidation().contentType(ContentType.JSON)
                .log().all()
                .when()
                .get("/api/users?id=3")
                .then().log().all().extract().response();
    }
}

如果这解决了您的问题,请告诉我.

Let me know, if this solved your problem.

这篇关于RestAssured中的超时错误,而服务在postman/soapUI中给出响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆