作为 ROBOT Framework 的一部分传递 --form 文件
Passing --form file as part of ROBOT Framework
我正在尝试在 ROBOT 框架中传递以下 API 请求
curl --request POST --url <API End Point> --form 'sourcefile=@/home/test.zip' --header "Authorization: <Bearer Token>"
等效机器人测试用例,
Sample Test Case
[Arguments] ${token}=default
Create Session mxesession ${mxe_host}
${accessToken}= Catenate Bearer ${token}
${data}= Create Dictionary sourcefile=/home/test.zip
${header}= Create Dictionary Authorization=${accessToken}
${response}= Post Request mxesession /v1/ml files=${data} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
上面的测试用例我执行的时候成功通过了。但是该文件无法被应用程序成功处理,而直接通过 curl 请求传递时它已成功处理。所以,我想在这里说的是,我在这里传递的文件没有问题,而通过 curl 请求命令和机器人框架测试用例传递给应用程序的文件似乎有所不同。
测试用例是否正确,尤其是我传递‘sourcefile’的方式 ?
我是否应该在机器人框架中以不同方式对待此路径中的“@”/home/test.zip?
link:Uploading files using multipart/form-data through REST API 已按照 Bryan Oakley 的建议提供帮助。
下面给出正确的测试用例供参考:
Sample Test Case
[Arguments] ${token}=default
Create Session mxesession ${mxe_host}
${accessToken}= Catenate Bearer ${token}
${fileData}= Get Binary File /home/test.zip
&{fileParts}= Create Dictionary
Set To Dictionary ${fileParts} sourcefile=${fileData}
${response}= Post Request mxesession /v1/ml files=${fileParts} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
关键行是:
${fileData}= Get Binary File /home/test.zip
&{fileParts}= Create Dictionary
Set To Dictionary ${fileParts} sourcefile=${fileData}
我正在尝试在 ROBOT 框架中传递以下 API 请求
curl --request POST --url <API End Point> --form 'sourcefile=@/home/test.zip' --header "Authorization: <Bearer Token>"
等效机器人测试用例,
Sample Test Case
[Arguments] ${token}=default
Create Session mxesession ${mxe_host}
${accessToken}= Catenate Bearer ${token}
${data}= Create Dictionary sourcefile=/home/test.zip
${header}= Create Dictionary Authorization=${accessToken}
${response}= Post Request mxesession /v1/ml files=${data} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
上面的测试用例我执行的时候成功通过了。但是该文件无法被应用程序成功处理,而直接通过 curl 请求传递时它已成功处理。所以,我想在这里说的是,我在这里传递的文件没有问题,而通过 curl 请求命令和机器人框架测试用例传递给应用程序的文件似乎有所不同。
测试用例是否正确,尤其是我传递‘sourcefile’的方式 ?
我是否应该在机器人框架中以不同方式对待此路径中的“@”/home/test.zip?
link:Uploading files using multipart/form-data through REST API 已按照 Bryan Oakley 的建议提供帮助。
下面给出正确的测试用例供参考:
Sample Test Case
[Arguments] ${token}=default
Create Session mxesession ${mxe_host}
${accessToken}= Catenate Bearer ${token}
${fileData}= Get Binary File /home/test.zip
&{fileParts}= Create Dictionary
Set To Dictionary ${fileParts} sourcefile=${fileData}
${response}= Post Request mxesession /v1/ml files=${fileParts} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
关键行是:
${fileData}= Get Binary File /home/test.zip
&{fileParts}= Create Dictionary
Set To Dictionary ${fileParts} sourcefile=${fileData}