我尝试使用下面的代码来验证我的一个REST API负责上传文件
def builder = new RestRequestObjectBuilder()
//Create a new POST object using builder
def requestObject = builder.withRestRequestMethod('POST')
.withRestUrl(GlobalVariable.APIurl + '/add_track')
.withHttpHeaders([
new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'multipart/form-data'),
new TestObjectProperty('key', ConditionType.EQUALS, GlobalVariable.key),
new TestObjectProperty('token', ConditionType.EQUALS, GlobalVariable.token)])
.withMultipartFormDataBodyContent([
new FormDataBodyParameter('file',"C:\\SampleAudio.mp3" , 'File'),
new FormDataBodyParameter('description', 'This track is uploaded by automation', 'PARAM_TYPE_TEXT'),
new FormDataBodyParameter( 'title', 'being single', 'PARAM_TYPE_TEXT'),
])
.build()
def response =WS.sendRequest(requestObject)
WS.verifyResponseStatusCode(response, 200)
WS.verifyElementPropertyValue(response, "message", "test")
但是文件未发布在服务器上,我尝试了所有可能的方法,但是没有运气。