简体   繁体   English

如何使用机器人测试框架从创建的会话中获取访问令牌

[英]how to get access token from created session using robot testing framework

Hi here is my script file.I would like to get access token from created session.I tried this way but I am getting access token as none.Can any help me. 嗨,这是我的脚本文件。我想从创建的会话中获取访问令牌。我尝试过这种方式,但我获取的访问令牌为none。

    Create Session  httpbin     ${server_URL}       verify=${True}
&{dict}    Create Dictionary        username=${username}    password=${password}   email=${email}       role=${role}    
${header}  Create Dictionary  Content-Type=application/json    charset=UTF-8     
${resp}     Post Request    httpbin     /api/Owners          data=${dict}    headers=${header}
${accessToken}=    evaluate    $resp.json().get("access_token")
Log to Console        ${accessToken}
log Many        ${resp.text}
${id}   Evaluate     $resp.json().get("id")
Log     ${id}
log to console      ${resp.status_code}
${resp}  Get Request     httpbin        uri=/api/Owners?access_token=${accessToken}
${resp}     Get Substring   ${resp.text}    1   -1
Log      ${resp}
${json_str}    Convert JSON To String    ${resp}
Should Contain      ${json_str}         ${id}

using requests i will try to login and create an Token 使用请求,我将尝试登录并创建令牌

import requests

login = {
      "user" : "username",
      "pass" : "passwrod",
}

here Write your own Token that is only an Example 在这里写你自己的令牌仅仅是一个例子

accesToken = {

"Accept" : "application/json",

}

request = requests.post('http://www.web.com/user', data=login, headers=accesToken')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用python从机器人框架访问应用程序的logcat - How to access logcat for app from robot framework using python 如何从 Get Response Body - Robot 框架中获取值 - How to capture the values from Get Response Body - Robot framework 如何使用 Robot Framework 从 Google 电子表格中读取数据 - How to read Data from Google spread sheet using Robot Framework 您可以使用Robot Framework进行跨浏览器测试吗 - Can you have cross browser testing using Robot Framework 使用机器人框架测试使用OAuth 2.0的REST API - Testing REST APIs which use OAuth 2.0 using robot framework 如何使用机器人框架接受警报 - How to accept an alert using robot framework 如何在Robot Framework中使用一个机器人文件中的变量到另一个机器人文件中 - how to use variable from one robot file into another robot file in Robot Framework 如何在Robot Framework中使用获取库实例调用Python库函数 - How to call Python Library Function using Get Library Instance in Robot Framework 如何从Robot Framework中的Run Keyword If下调用的关键字获取返回值? - How to get Returned value from a Keyword called under Run Keyword If in Robot Framework? 使用机器人框架进行Web自动化时如何从自定义库实例化webdriver对象 - how to instantiate the webdriver object from the custom library when doing web automation using robot framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM