如何通过API(RequestsLibrary)传递cookie来获取请求Robot框架

问题描述 投票:0回答:1

我想在下一个带有

POST
请求的会话中使用从我执行
GET
请求的会话中收到的 cookie,但我有问题。

这是我的关键词:

MY_Profile
    Log To Console    HEADER
    Log To Console    COOKIE
    Create Session    mySession         ${api_auth}    ${cookie}
    ${response}=      GET On Session    mySession      ${api_auth}
    Log To Console    ${response.status_code}

这是我收到的错误:

${cookie} 在此会话中未知

robotframework session-cookies web-api-testing
1个回答
0
投票

根据文档,cookie 是

Create Session
关键字的第四个参数。在您的示例中,您将其作为第三个传递,因此它最终会成为标题。

所以也许可以将其传递为 kwarg:

   Create Session    mySession         ${api_auth}    cookies=${cookie}

文档可在此处获取; https://marketsquare.github.io/robotframework-requests/doc/RequestsLibrary.html#Create%20Session

© www.soinside.com 2019 - 2024. All rights reserved.