无法使用标头中的API密钥创建Robot Framework API自动化测试

时间:2019-07-23 08:43:11

标签: robotframework web-api-testing

我为POST请求创建一个API自动化测试。我使用以下库:RequestLibrary和HttpLibrary.HTTP。

我有一个用于请求正文的JSON对象。我的标题包含内容类型:application/json和API密钥。如何在机器人框架中发送api密钥?

***Settings***                  
Library             RequestsLibrary
Library             HttpLibrary.HTTP            


***Variables***
${url}              https://blabla/api/login            
${email}            blabla
${password}         blabla


***Test Cases***
API Login Email
    ${apikey}=    Set Variable    wQ0f7FgE9wLhq

    ${body}=    catenate    {"email_or_phone":${email},"password":${password}}
       &{header}=      Create Dictionary       Content-Type=application/json

       CreateSession        login       ${url}      ${header}    auth=${apikey}       verify=True
       ${resp}=    Post Request    login    api/login    data=${body}    headers=${header}
       Should Be Equal As Strings   ${resp.status_code} 200 

0 个答案:

没有答案