使用Process lib,我创建了以下内容:
*** Settings ***
Documentation
Library Process
Library OperatingSystem
*** Test Case ***
Test Case
Start Sesh
*** Keyword ***
Start Sesh
${Authenticate}= Run Process curl -c cookie.txt -d j_username\=regression1%40att&j_password\=TCpass1234&submit\=Login https://api.company.com/j_spring_security_check
在命令行上运行curl命令会在工作目录中生成一个名为cookie.txt的cookie。
出于某种原因在Robot Framework中运行命令甚至不会创建文本文件,更不用说用会话填充它了。
目标:我试图让curl在RF中创建一个cookie,就像在命令行场景中一样。
编辑:我可能已经使用shell = True解决了这个问题。留下来发布
答案 0 :(得分:0)
<强>先决条件:强>
<强>代码:强>
*** Settings ***
Documentation
Library Process
*** Variables ***
${COOKIE} C:/sq_automation/cookie.txt
*** Keywords ***
Start API Session
${Authenticate} Run Process curl -i -c ${COOKIE} -d "j_username\=regression1%40att&j_password\=TCpass1234&submit\=Login https://api.website.com/j_spring_security_check" shell=True alias=Auth cwd=C:/sq_automation
Should Contain ${Authenticate.stdout} HTTP/1.1 302 Found
${result} Get Process Result Auth rc=True stdout=True stderr=True
API POST
${Login} Run Process curl -i -b ${COOKIE} -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "{\\"password\\":\\"${PASSWORD}\\",\\"username\\":\\"${USERID}\\"}" https://api.touchcommerce.com/engagementAPI/v1/agent/login?output\=json shell=True alias=Login cwd=C:/sq_automation
Should Contain ${Login.stdout} HTTP/1.1 200 OK
${result} Get Process Result Login rc=True stdout=True stderr=True
Get Registered ID ${Login.stdout}
我只能使用shell = True。你必须编写curl命令,参数之间只有一个空格,并且正确的字符转义为反斜杠和等号。