我尝试运行这个 Rest Assured TestNG 测试:
@Test
public 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;
}
慕村225694
相关分类