在 RestAssured 中发布 FileList
Posting FileList in RestAssured
目前我使用下面的代码 post 使用 RestAssured 的单个文件。
RestAssured.given().contentType(ContentType.MULTIPART_FORM_DATA.toString()).request().multiPart("files", ScreenshotFile).post().then().statusCode(200);
但是我想从下面提到的 FileList 上传多个文件。
File ScreenShotFolder = new File("C:\Users\1451615\Desktop\SessionScreenshot\");
File ScreenShotFiles[] = ScreenShotFolder.listFiles();
我在同一请求中对 post 多个文件进行了循环。请在下面找到相同的代码。
File ScreenShotFolder = new File("C:\Users\1451615\Desktop\SessionScreenshot\");
File ScreenShotFiles[] = ScreenShotFolder.listFiles();
RestAssured.baseURI = "http://10.141.188.112:7080/PIMSelfService/testing/uploadResultImg";
RequestSpecification request = RestAssured.given().contentType(ContentType.MULTIPART_FORM_DATA.toString()).request();
for (File file: ScreenShotFiles) {
System.out.println("File name: " + file.getName());
String FilePath = file.getAbsolutePath();
File ScreenShotPath = new File(FilePath);
System.out.println(ScreenShotPath);
request.multiPart("files", ScreenShotPath);
}
request.post().then().statusCode(200);
ValidatableResponse createAttachemnetResponse = expect()
.given()
.spec(requestSpecification)
.header("content-type", "multipart/form-data")
.multiPart("files-0", new File("testImages/1.jpg"))
.multiPart("files-1", new File("testImages/2.png"))
.multiPart("files-2", new File("testImages/3.png"))
.multiPart("files-3", new File("testImages/4.png"))
.multiPart("files-4", new File("testImages/5.png"))
.formParams("txn_id", transactionId)
.when()
.post(TRANSACTION_BASEPATH + POST_ATTACHMENT)
.then()
.spec(responseSpecification);
目前我使用下面的代码 post 使用 RestAssured 的单个文件。
RestAssured.given().contentType(ContentType.MULTIPART_FORM_DATA.toString()).request().multiPart("files", ScreenshotFile).post().then().statusCode(200);
但是我想从下面提到的 FileList 上传多个文件。
File ScreenShotFolder = new File("C:\Users\1451615\Desktop\SessionScreenshot\");
File ScreenShotFiles[] = ScreenShotFolder.listFiles();
我在同一请求中对 post 多个文件进行了循环。请在下面找到相同的代码。
File ScreenShotFolder = new File("C:\Users\1451615\Desktop\SessionScreenshot\");
File ScreenShotFiles[] = ScreenShotFolder.listFiles();
RestAssured.baseURI = "http://10.141.188.112:7080/PIMSelfService/testing/uploadResultImg";
RequestSpecification request = RestAssured.given().contentType(ContentType.MULTIPART_FORM_DATA.toString()).request();
for (File file: ScreenShotFiles) {
System.out.println("File name: " + file.getName());
String FilePath = file.getAbsolutePath();
File ScreenShotPath = new File(FilePath);
System.out.println(ScreenShotPath);
request.multiPart("files", ScreenShotPath);
}
request.post().then().statusCode(200);
ValidatableResponse createAttachemnetResponse = expect()
.given()
.spec(requestSpecification)
.header("content-type", "multipart/form-data")
.multiPart("files-0", new File("testImages/1.jpg"))
.multiPart("files-1", new File("testImages/2.png"))
.multiPart("files-2", new File("testImages/3.png"))
.multiPart("files-3", new File("testImages/4.png"))
.multiPart("files-4", new File("testImages/5.png"))
.formParams("txn_id", transactionId)
.when()
.post(TRANSACTION_BASEPATH + POST_ATTACHMENT)
.then()
.spec(responseSpecification);