Robot Framework RequestsLibrary - 这个 cookie 会导致类型错误吗?
Robot Framework RequestsLibrary - What about this cookie is causing a Type Error?
我有一个使用 RequestsLibrary 的 Robot Framework 测试套件,它测试 RESTful API。测试效果很好。一个简单的示例调用:
*** Test Cases ***
Test API
Create API Session
${resp} = Get Request api_session /foo/bar
BlahBlah test the ${resp} etc.
*** Keywords ***
Create API Session
${headers_str} = Evaluate str('application/json')
&{headers} = Create Dictionary Content-Type=${headers_str}
Create Session api_session ${BASE_URL} headers=${headers} verify=True
现在我需要开始添加 cookie,以跟踪此测试套件发出的所有调用的代码接收代码覆盖率。所以我修改了上面的代码,工作代码如下:
*** Test Cases ***
Test API
Create API Session
${resp} = Get Request api_session /foo/bar
BlahBlah test the ${resp} etc.
*** Keywords ***
Create API Session
${headers_str} = Evaluate str('application/json')
&{headers} = Create Dictionary Content-Type=${headers_str}
${cookies_str} = Evaluate str('{"CodeCoverage":"Test Name","CodeCoverage_Suite":null,"CodeCoverage_Config":null}')
&{cookies} = Create Dictionary CODECEPTION_CODECOVERAGE=${cookies_str}
Create Session api_session ${BASE_URL} headers=${headers} cookies=${cookies} verify=True
但现在 Test API
测试在 Get Request
关键字处失败,令人困惑 TypeError: string indices must be integers
。这里发生了什么?我假设我误解了我的 cookie,但文档让我比开始时更加困惑。
这不是针对您的特定问题的答案,但它确实意味着您尝试做的事情不会奏效,即使您的语法等是正确的。 RequestsLibrary 无法再处理 cookie。检查 https://github.com/bulkan/robotframework-requests/blob/master/src/RequestsLibrary/RequestsKeywords.py
具体来说:
# cant pass these into the Session anymore
self.timeout = float(timeout) if timeout is not None else None
self.cookies = cookies
self.verify = verify
有一次我快把自己逼疯了,因为我需要传入的 cookie 来做某事,当我发现这条评论时,我差点把显示器扔出 window。我通过 Twitter 联系了作者,但从未收到关于为什么这是一个问题的回复。也许我自己完全误解了情况,我只是放弃了我正在做的事情,因为它是一个 POC。
我有一个使用 RequestsLibrary 的 Robot Framework 测试套件,它测试 RESTful API。测试效果很好。一个简单的示例调用:
*** Test Cases ***
Test API
Create API Session
${resp} = Get Request api_session /foo/bar
BlahBlah test the ${resp} etc.
*** Keywords ***
Create API Session
${headers_str} = Evaluate str('application/json')
&{headers} = Create Dictionary Content-Type=${headers_str}
Create Session api_session ${BASE_URL} headers=${headers} verify=True
现在我需要开始添加 cookie,以跟踪此测试套件发出的所有调用的代码接收代码覆盖率。所以我修改了上面的代码,工作代码如下:
*** Test Cases ***
Test API
Create API Session
${resp} = Get Request api_session /foo/bar
BlahBlah test the ${resp} etc.
*** Keywords ***
Create API Session
${headers_str} = Evaluate str('application/json')
&{headers} = Create Dictionary Content-Type=${headers_str}
${cookies_str} = Evaluate str('{"CodeCoverage":"Test Name","CodeCoverage_Suite":null,"CodeCoverage_Config":null}')
&{cookies} = Create Dictionary CODECEPTION_CODECOVERAGE=${cookies_str}
Create Session api_session ${BASE_URL} headers=${headers} cookies=${cookies} verify=True
但现在 Test API
测试在 Get Request
关键字处失败,令人困惑 TypeError: string indices must be integers
。这里发生了什么?我假设我误解了我的 cookie,但文档让我比开始时更加困惑。
这不是针对您的特定问题的答案,但它确实意味着您尝试做的事情不会奏效,即使您的语法等是正确的。 RequestsLibrary 无法再处理 cookie。检查 https://github.com/bulkan/robotframework-requests/blob/master/src/RequestsLibrary/RequestsKeywords.py
具体来说:
# cant pass these into the Session anymore
self.timeout = float(timeout) if timeout is not None else None
self.cookies = cookies
self.verify = verify
有一次我快把自己逼疯了,因为我需要传入的 cookie 来做某事,当我发现这条评论时,我差点把显示器扔出 window。我通过 Twitter 联系了作者,但从未收到关于为什么这是一个问题的回复。也许我自己完全误解了情况,我只是放弃了我正在做的事情,因为它是一个 POC。