Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重启:发送请求后如何获取RequestSpecification字段或参数?_Java_Java 8_Cucumber_Rest Assured_Cucumber Java - Fatal编程技术网

Java 重启:发送请求后如何获取RequestSpecification字段或参数?

Java 重启:发送请求后如何获取RequestSpecification字段或参数?,java,java-8,cucumber,rest-assured,cucumber-java,Java,Java 8,Cucumber,Rest Assured,Cucumber Java,我在做cucumber bdd测试,我有一个类[MyClient],它包装了重启的方法,我有多个类调用[MyClient] 我可以使用put、post等方法,但我想知道是否有办法获得请求后发送的实际请求字段(标题、正文…) 我在获取和解析响应方面也没有任何问题,但是我无法发送请求 考虑到以下情况,我可以调用sendPostRequest(),它将RequestSpecification实例存储到名为request的字段中,我可以通过调用getter随时获取它。但是,我无法从RequestSpec

我在做cucumber bdd测试,我有一个类
[MyClient]
,它包装了重启的方法,我有多个类调用
[MyClient]

我可以使用put、post等方法,但我想知道是否有办法获得请求后发送的实际请求字段(标题、正文…)

我在获取和解析响应方面也没有任何问题,但是我无法发送请求

考虑到以下情况,我可以调用
sendPostRequest()
,它将
RequestSpecification
实例存储到名为
request
的字段中,我可以通过调用
getter
随时获取它。但是,我无法从
RequestSpecification
对象中获取单个字段。通过
调试器
,我可以很好地看到这些字段,因此我认为必须有一些干净的方法来获取这些字段

我已经试过了
log()
,但它似乎不能满足我的需要。 感谢您的帮助

调用类:

public class MyInterfaceSteps() {
 private myClient = new MyClient();

 public sendPostRequest(){
  myClient.post(someHeaders, someBody, someUrl);
 }
}
public class MyClient() {
 private RequestSpecification request;
 private Response response;

 public getRequest() {
  return request;
 }

 public getResponse() {
  return response;
 }

 public Response post(Map<String, String> headers, String body, String url) {
  request = given().headers(headers).contentType(ContentType.JSON).body(body);
  response = request.post(url);  
 }
}
客户端类:

public class MyInterfaceSteps() {
 private myClient = new MyClient();

 public sendPostRequest(){
  myClient.post(someHeaders, someBody, someUrl);
 }
}
public class MyClient() {
 private RequestSpecification request;
 private Response response;

 public getRequest() {
  return request;
 }

 public getResponse() {
  return response;
 }

 public Response post(Map<String, String> headers, String body, String url) {
  request = given().headers(headers).contentType(ContentType.JSON).body(body);
  response = request.post(url);  
 }
}
公共类MyClient(){
专用请求规范请求;
私人回应;
公共getRequest(){
返回请求;
}
公共响应(){
返回响应;
}
公共响应帖子(映射头、字符串正文、字符串url){
request=given().headers(headers).contentType(contentType.JSON).body(body);
response=request.post(url);
}
}

您可以创建一个过滤器(),该过滤器允许您访问FilterableRequestSpecification(),您可以从中获取(和修改)标题和正文等。过滤器可以将这些值存储到您选择的数据结构中

我希望能够将请求的完整URI添加到testNG自定义报告中。为此,我必须重新启动.given(),然后使用
queryParam(…)
应用我的查询参数,然后执行
.get(mypath)
。通过将请求转换为
FilterableRequestSpecification
,而不需要过滤器,我最终可以使用
httpRequest.getURI()
访问URI。为什么
getURI()
不是RequestSpecification的默认方法?将其转换为FilterableRequest规格是否会导致任何问题?