Robot Framework获取令牌

时间:2018-05-31 11:15:30

标签: python-requests http-post robotframework

Robot Framework的新手。尝试从Azure获取令牌。我用纯python代码对它进行了编码,它可以作为一个魅力,但我想在Robot Framework中做到这一点,我对理解这个库有很大的问题。

所以我在Robot Framework中的代码看起来像这样:

*** Settings ***
Library         RequestsLibrary
Library         json

*** Variables ***
${Content-Type}=    application/x-www-form-urlencoded                
${resource}=        xxxxxxxxxx
${grant_type}=      client_credentials
${client_secret}=   xxxxxxxxxx
${client_id}=       xxxxxxxxxx
${headers}=         accept=application/json

*** Test Cases ***
Post Requests
[Tags]  post
Create Session   azure   https://login.microsoftonline.com/xxxxxxxxxx/oauth2/token
&{data}=  Create Dictionary   client_id=${client_id}   client_secret=${client_secret}   grant_type=${grant_type}
&{headers}=  Create Dictionary   Content-Type=application/json
${resp}=  Post Request  azure  ${url}  ${data}  ${headers}
Should Be Equal As Strings  ${resp.status_code}  200

而不是得到200我得到404。

我也试过使用ExtendedRequestLibrary,但是我得到了其他奇怪的错误,所以我想我不知道如何实际使用它,但是我得到了404.普通python中的代码或多或少是同样,希望有人可以指出我正确的答案。

如果有帮助我可以发布我的python代码。

谢谢!

1 个答案:

答案 0 :(得分:1)

${url}的价值是什么?您已经在会话创建中设置了azure oauth2令牌端点,如果您添加更多内容,并且将请求发送到必须可能不存在的资源。

尝试这样(只有相关部分):

Create Session   azure   https://login.microsoftonline.com/xxxxxxxxxx/oauth2
${resp}=  Post Request  azure  /token  ${data}  ${headers}

Create Session关键字为将来的请求(在此会话中)设置基本网址,例如之后使用的每条路线都将附加到基地。