此API URL正用招贴和邮递员方式
*设置* 图书馆要求图书馆 图书馆藏书
*** Variables ***
${base_URL}= https://someurl.com
${file_name}= Get Binary File Test.png
*** Test Cases ***
TC008_Upload_File
create session upload_file ${base_url}
${body}= create dictionary asset=${file_name}
${header}= create dictionary Content-Type=multipart/form-data:boundary= <calculated when request is sent> Accept=text/plain
${response}= post request upload_file /api/insertFile data=${body} headers=${header}
log to console ${response.content}
#to validate status code with the actual status code
${Status_code}= convert to string ${response.status_code}
should be equal ${Status_code} 200
#to validate the content of the response body
${response_body}= convert to string ${response.content}
should contain ${response_body} true
我的卷曲URL是:
curl -X POST "https://someurl.com/api/insertFile" -H "accept: text/plain" -H "Content-Type: multipart/form-data" -F "asset=@Test.png;type=image/png"
答案 0 :(得分:0)
您显然希望将文件的内容作为请求的正文,但是-您正试图在变量部分中获取它:
*** Variables ***
${base_URL}= https://someurl.com
${file_name}= Get Binary File Test.png # <-- this call here
在该位置-变量部分-您不能运行关键字并将其返回值分配给变量;在那里放置的所有内容都会直接变成值(即使它类似于关键字名)。因此,${file_name}
的值实际上是“获取二进制文件C:\ Users \ fl792 \ PycharmProjects \ ResrAssured \ VideoGameProject \ Test15.txt”,而不是该文件的内容。
您可以通过将其移动到可调用位置(例如测试用例本身)来解决此问题:
*** Test Cases ***
TC008_Upload_File
${file_name}= Get Binary File Test.png