我尝试运行这个 Rest Assured TestNG 测试:@Testpublic void test_createIssue() { RestAssured.baseURI = "localhost:8080"; String sessionCookie = Reusable.getSessionCookie(); given(). header("Content-Type", "application/json"). header("Cookie", sessionCookie). body("{\n" + " \"fields\": {\n" + " \"project\":\n" + " {\n" + " \"key\": \"PROJ\"\n" + " },\n" + " \"summary\": \"REST ye merry gentlemen.\",\n" + " \"description\": \"Creating of an issue using project keys and issue type names using the REST API\",\n" + " \"issuetype\": {\n" + " \"name\": \"Zadanie\"\n" + " }\n" + " }\n" + "}"). when(). post("/rest/api/2/issue"). then(). statusCode(201);}getSessionCookie()在第 4 行调用方法:static String getSessionCookie() { RestAssured.baseURI = "localhost:8080"; Response response = given(). header("Content-Type", "application/json"). body("{\"username\": \"admin\", \"password\": \"admin\"}"). when(). post("/rest/auth/1/session"). then(). statusCode(200). extract().response(); JsonPath responseJson = rawToJson(response); String sessionName = responseJson.get("session.name"); String sessionValue = responseJson.get("session.value"); return sessionName + "=" + sessionValue;}
2 回答
![?](http://img1.sycdn.imooc.com/545862aa0001f8da02200220-100-100.jpg)
慕村225694
TA贡献1880条经验 获得超4个赞
您应该删除 RestAssured.baseURI = "localhost:8080"; 因为 baseURI 默认是本地主机,如果你想设置端口,你应该使用 RestAssured.port=8080;
添加回答
举报
0/150
提交
取消