我有以下python方法,它是导入到Robot Framework测试套件中的库的一部分:
def check_activation_status(self):
'''
A simple keyword to check if my app has been activated not. Returns boolean value from the API response.
*Arguments*
'''
url = os.path.join(self.url, "api/activation")
print_to_log(url) # a custom keyword that prints the url to the RF log.html file, just for info purpose
r = requests.get(url, verify=False)
activated = r.json()["activated"]
return activated
当检查激活状态关键字被调用时,我得到以下错误:
15:45:11.446 DEBUG Starting new HTTPS connection (1): localhost:8001
15:45:11.448 FAIL ConnectionError: HTTPSConnectionPool(host='localhost', port=8001): Max retries exceeded with url: /api/activation (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7efdcb718a30>: Failed to establish a new connection: [Errno 111] Connection refused'))
我不知道为什么它"开始一个新的HTTPS连接";因为
https://localhost:8001
在套件设置后成功运行,这是测试需要在/api/activation
端点上执行的后续检查。当我在Python控制台中运行以下命令时,它工作正常,并给出我期望的json值(True或False)
import requests
r = requests.get("https://localhost:8001/api/activation", verify=False)
activated = r.json()['activated']
有什么原因为什么这在Python中工作,而不是在机器人框架?
我熟悉Robot Framework Requests库,然而,这种导入我自己的库的方法允许存储在Python库中的可读关键字-也可以在Robot Framework之外使用。
在机器人框架中使用requestlibrary。你可以直接使用GET方法。参考这里的库
pip install robotframework-requests
Robot框架库本身是一个python库,可以直接导入到python文件中-它不限于Robot框架。你可以使用机器人框架请求库直接进入python文件。