简体   繁体   English

获取错误 io.restassured.internal.ValidatableResponseImpl 无法转换为 io.restassured.response.Response

[英]Getting Error io.restassured.internal.ValidatableResponseImpl cannot be cast to io.restassured.response.Response

I am getting the following error upon running the test.运行测试时出现以下错误。 I am trying to print the API response to a file, however the test is failing and throwing the error.我正在尝试将 API 响应打印到文件,但是测试失败并抛出错误。 The response of the call is in JSON and is in GZIP.调用的响应采用 JSON 格式,采用 GZIP 格式。 Any thoughts and ideas are greatly appreciated.任何想法和想法都非常感谢。

Error : io.restassured.internal.ValidatableResponseImpl cannot be cast to io.restassured.response.Response错误:io.restassured.internal.ValidatableResponseImpl 无法转换为 io.restassured.response.Response

Here is my code :这是我的代码:

package TestPackage;

import org.testng.Assert;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import io.restassured.response.Response;


public class ApiServerTest {

    String baseQAURL = "http://some:8282/getworkitemwithtime";


    @Test
    public void apiServerTest() throws FileNotFoundException{

        Response srvrResponse = (Response) given().
                                param("starttime", "2017-08-10T11:17:00").
                                param("endtime", "2017-08-10T11:17:01").
                                when().
                                get(baseQAURL).
                                then().
                                log().
                                all();

            System.out.println(srvrResponse.getStatusCode());
            Assert.assertEquals(srvrResponse.getStatusCode(), 200);

            srvrResponse.asString();
            PrintStream out = new PrintStream(new FileOutputStream("C:\\Test\\output.txt"));
            System.setOut(out);


    }

}

Comments are right - you need to extract your response to be used out of request context. 评论是正确的-您需要提取您的响应以在请求上下文之外使用。

Actually you may optimize your code: 实际上,您可以优化代码:

import io.restassured.config.LogConfig;
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;

import static io.restassured.RestAssured.config;
import static io.restassured.RestAssured.given;

public class TestLogging {

    String baseQAURL = "https://httpbin.org/get";

    @Test
    public void apiServerTest() throws FileNotFoundException {
        config = config().logConfig(new LogConfig().defaultStream(new PrintStream(new File("C:\\Test\\output.txt"))));

        given().
                param("starttime", "2017-08-10T11:17:00").
                param("endtime", "2017-08-10T11:17:01").
                when().
                get(baseQAURL).
                then().
                log().
                all()
                .assertThat().statusCode(200);
    }
}

I got same error我有同样的错误

.contentType(ContentType.JSON) .body(loginBody) .cookies(cookies) .post() .then().extract().response() .contentType(ContentType.JSON) .body(loginBody) .cookies(cookies) .post() .then().extract().response()

io.restassured.internal.http.ResponseParseException: status code: 200, reason phrase: OK io.restassured.internal.http.ResponseParseException:状态代码:200,原因短语:OK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入 io.restassured.RestAssured 无法解决 - The import io.restassured.RestAssured cannot be resolved NoClassDefFoundError: io/restassured/RestAssured 发生错误 - NoClassDefFoundError: io/restassured/RestAssured Error is occured Rest 保证问题 io.restassured.internal.RestAssuredResponseImpl@46fc522d 响应 - Rest assured issue io.restassured.internal.RestAssuredResponseImpl@46fc522d in response io.restassured.internal.http.HttpResponseException:未找到 - io.restassured.internal.http.HttpResponseException: Not Found Rest Assured execption 类 io.restassured.path.xml.XmlPath 无法转换为类 java.util.ArrayList 错误 - Rest Assured execption class io.restassured.path.xml.XmlPath cannot be cast to class java.util.ArrayList error 进口 static io.restassured.RestAssured.*; 不工作 - import static io.restassured.RestAssured.*; NOT working 线程“ main”中的异常java.lang.NoClassDefFoundError:io / restassured / response / Response - Exception in thread “main” java.lang.NoClassDefFoundError: io/restassured/response/Response java.lang.NoClassDefFoundError: io/restassured/internal/common/assertion/AssertParameter - java.lang.NoClassDefFoundError: io/restassured/internal/common/assertion/AssertParameter 带有边界的放心的解析身体响应 - Restassured Parse Body response with boundary 如何在放心的回应中获取价值 - How to retrieve value in the response of restassured
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM