TA的每日心情 | 擦汗 8 小时前 |
---|
签到天数: 527 天 连续签到: 4 天 [LV.9]测试副司令
|
1测试积点
问题:
Post 请求用 postman 构造时能正常响应,相同的参数用 rest assured 请求却提示参数格式异常,哪位大神能帮忙看下?
1.如下是用postman构造的request,此api要同时传查询参数和body.postman构建请求返回为200.
2.用restassured构造相同的请求,所有 参数完全一致,甚至参数名都是直接复制的,但总是提示参数格式异常。
个人怀疑问题出在传递的body中,因为另外一条只有body请求的api也call不通,传递的body和这条内容 是一样的。这个问题困扰我2天了
- ' public Response registerDevice(String strSWAccess2,String type,String serial,String deviceId,String sig,String ctr,String nounce) throws Exception {
- givenWhetherNeedToLoginWithLID("yes");
- JSONObject body=new JSONObject();
- body.put("modelType",type);
- body.put("sn",serial);
- givenAnUrl(baseUrl+registerDevicePath);
- //用Lambda表达式,用父类中带参数的方法发Request,并拿回Response
- super.whenSendRequestWithMethod("post",x -> {
- x.cookie("SWAccess", strSWAccess).
- queryParam("deviceId", deviceId.trim()).
- queryParam("ctr", ctr.trim()).
- queryParam("nounce", nounce.trim()).
- queryParam("sig", sig.trim()).
- contentType("application/json").body(body).
- header("Cache-Control","no-cache");
- return x;
- });
- System.out.println("registerDevice return code:"+actualResponse.statusLine());
- return actualResponse;
- }
- '
- '
- public void whenSendRequestWithMethod(String httpMethod, IFunc iFunc){
- switch (HttpMethod.getHttpMethod(httpMethod)){
- case GET:
- actualResponse = iFunc==null?get((strURL)):iFunc.ISpecifyParams4HttpRequest(given()).get(strURL);
- strResponse = actualResponse.asString();
- break;
- case POST:
- //actualResponse = iFunc==null?given().contentType(JSON).body(strRequestBody).post(strURL):iFunc.ISpecifyParams4HttpRequest(given()).contentType(JSON).body(strRequestBody).post(strURL);
- actualResponse = iFunc==null?given().log().all().post(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).post(strURL);
- strResponse = actualResponse.asString();
- break;
- case PUT:
- actualResponse = iFunc==null?put(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).put(strURL);
- strResponse = actualResponse.asString();
- break;
- case DELETE:
- actualResponse = iFunc==null?delete(strURL):iFunc.ISpecifyParams4HttpRequest(given().log().all()).delete(strURL);
- strResponse = actualResponse.asString();
- break;
- default:
- actualResponse =iFunc==null?get(strURL): iFunc.ISpecifyParams4HttpRequest(given().log().all()).get(strURL);
- strResponse = actualResponse.asString();
- break;
- }
- logger.info("Response = " + strResponse);
- }
- '
复制代码
|
|