【问题标题】:Using Robot Framework's Process lib, curl -c will not create a cookie使用机器人框架进程 libcurl -c 不会创建 cookie
【发布时间】:2018-06-28 02:50:52
【问题描述】:

使用 Process 库,我创建了以下内容:

*** 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 解决了这个问题。保持关注

【问题讨论】:

    标签: curl cookies robotframework


    【解决方案1】:

    如果您想使用 Robot Framework 运行 CURL,答案如下:

    先决条件:

    • 流程库
    • Windows 卷曲
    • 在 Windows 中将 Curl.exe 设置为路径变量
    • 还知道我让它与 REST API 一起使用

    代码:

    *** 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 命令时,必须在参数之间仅使用一个空格,并为反斜杠和等号提供正确的字符转义。

    【讨论】:

      猜你喜欢
      • 2020-01-22
      • 2018-04-01
      • 2021-11-23
      • 2011-02-20
      • 2019-10-25
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多