将Python脚本转换为Robot Framework

问题描述 投票:0回答:1

我有需要转换为Robot Framework的Python代码。

        client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname=host, username=user, password=passwd, port=port)
    stdin, stdout, stderr = client.exec_command(command, timeout=15)
    stdout_bin = stdout.read()
    stdout_str = bytes(stdout_bin).decode()
    # print(stdout_str)
    flag_corect_retriev = 0
    client.close()
    if value is not None:
         if str(stdout_str).find(value) != -1:
             print(f"{value}.\tFounded.")
             return 1
         else:
             print(f"{value}.\tNot founded.")
             return 0
    else:
        return stdout_str

是否可以使其在Robot Framework中工作?

我对Robot Framework了解不多。

python robotframework
1个回答
0
投票

如果从机器人测试用例调用 python 代码适合您,那么这是一个替代解决方案:

  1. 将关键字修饰器添加到你的Python代码中
  2. 在你的机器人测试中导入Python库
  3. 在机器人测试中调用关键字

这将允许从 Robot 测试用例调用 python 代码, 代码就变成这样了:

Python 文件

from robot.api.deco import keyword
@keyword('Name Of New keyword'):
def name_of_new_keyword(arg1, arg2):
    ##### your python code goes here ..

机器人文件

*** Settings ***
Library           path_to_your_python_library/python_file_name.py

*** Test Cases ***
TC_YOUR_ROBOT_TEST
  [Setup]
  Name Of New Keyword    arg1_value_    arg2_value
  [Teardown]

检查是否需要更新参数值或从 python 方法和机器人测试中删除它们。 我建议您查看官方文档以获取有关RobotFramework的更多知识:https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html

© www.soinside.com 2019 - 2024. All rights reserved.