实际网址如下 https://xxa-sa-usedtrucks.abc.com/api/vehicles?itemsPerPage=20&facets=r=US;g=truck
当我开火时我会得到结果。我稍微更改了上面的网址,以便它对您有用,因为它是保密的。
我使用 selenium 和 cucumber 编写了下面的一段代码,但是当我打印 url 时,我得到的结果如下所示,并且在响应中会出现错误结果。
https://xxx-cmax-usedtrucks.hal.com/api/vehicles?itemsPerPage=20&facets=r=US&g=truck
如果您在末尾看到上述网址而不是“;”正在添加“&”,因此请帮助我
public RequestSpecification httpRequest;
public Response response;
String FleetBase = "http://st-cm-usedtrucks.abc.com";
RestAssured.baseURI = FleetBase;
httpRequest = RestAssured.given().log().all();
httpRequest.queryParam("itemsPerPage", "20").urlEncodingEnabled(false);
httpRequest.queryParam(facets_param, "US").urlEncodingEnabled(false);
httpRequest.queryParam("g", "truck").urlEncodingEnabled(false);
response = httpRequest.get("/api/vehicles");
最佳答案
多个GET参数的分隔符是&
,您的代码使用的URL是正确的。
从外观上看,US
和 truck
字符串是同一个 GET 参数的一部分:facets
。
试试这个:
httpRequest = RestAssured.given().log().all();
httpRequest.queryParam("itemsPerPage", "20").urlEncodingEnabled(false);
httpRequest.queryParam(facets_param, "r=US;g=truck").urlEncodingEnabled(false);
response = httpRequest.get("/api/vehicles");
关于java - 在 Restassured Api 测试中,当我运行代码时,为什么在 g=truck 之前添加 "&"而不是 "; ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58502509/