运行测试时出现以下错误。我试图将API响应打印到文件,但是测试失败并抛出错误。该调用的响应以JSON格式显示,并位于GZIP中。 任何想法和想法,不胜感激。获取错误io.restassured.internal.ValidatableResponseImpl无法转换为io.restassured.response.Response
错误: io.restassured.internal.ValidatableResponseImpl不能转换到io.restassured.response.Response
这里是我的代码:
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);
}
}
你以后得到什么'得到(baseQUARL)。然后()...'是一个'ValidatableResponse',你可以尝试使用'得到(baseQAURL) .then()。extract()。response()'返回一个'Response'对象。 –
非常感谢Andrew。 get(baseQAURL).then()。extract()。response()就像一个魅力一样。我得到了答复 - 我认为使用extract()使所有的区别。感谢你的帮助。 – 9009