无论如何,是否可以在没有.robot/.txt脚本的情况下运行机器人框架,还是可以从某些数据中生成.robot/.txt文件?

发布于 2025-02-09 15:22:44 字数 1218 浏览 1 评论 0原文

有什么方法可以使用代码或JSON而不是.Orobot文件运行机器人框架?还是我应该先生成一个.robot文件然后运行?我不确定是否有更好的方法来执行此操作,因为某些步骤取决于上述步骤的输出(Unitsest/Pytest不支持这一点)。

例如,我有JSON中的测试序列列表

{
"seq_id": 1,
"seq_type": 1,  # normal, flag
"seq_len": 1,  # 1 for normal, n for flag
"flag_data": {
    "flag_name": "",
    "flag_type": "", # if/else, for, while with steps block
    "flag_length": 1,

    # flag_type-if
    "mid_val": 1,  # variable
    "comparison_left_type": '>',  # > >= empty
    "comparison_left_var": 1,  # variable or constant
    "comparison_right_type": '<',  # > >= empty
    "comparison_right_var": 1,  # variable or constant

    # flag_type-else

    # flag_type-for
    "loop_length": 1,  # variable or constant
    
    # flag_type-while
    # "mid_val": 1,  # variable
    # "comparison_left_type": '>',  # > >= empty
    # "comparison_left_var": 1,  # variable or constant
    # "comparison_right_type": '<',  # > >= empty
    # "comparison_right_var": 1,  # variable or constant
},

"sequence_data": [{
    "step_name": 'step_1',
    "step_type": '', # a embedded function to be used in function library
    "step_variable_a": a
    "step_variable_b": b
}]

}

Is there any way to run robot framework with a code or json instead of .robot file? Or should I generate a .robot file first and then run? I am unsure if there is a better way to do this, since some of the steps depend on previous steps' output (unittest/pytest does not support this).

I have a list of test sequences in json, for example

{
"seq_id": 1,
"seq_type": 1,  # normal, flag
"seq_len": 1,  # 1 for normal, n for flag
"flag_data": {
    "flag_name": "",
    "flag_type": "", # if/else, for, while with steps block
    "flag_length": 1,

    # flag_type-if
    "mid_val": 1,  # variable
    "comparison_left_type": '>',  # > >= empty
    "comparison_left_var": 1,  # variable or constant
    "comparison_right_type": '<',  # > >= empty
    "comparison_right_var": 1,  # variable or constant

    # flag_type-else

    # flag_type-for
    "loop_length": 1,  # variable or constant
    
    # flag_type-while
    # "mid_val": 1,  # variable
    # "comparison_left_type": '>',  # > >= empty
    # "comparison_left_var": 1,  # variable or constant
    # "comparison_right_type": '<',  # > >= empty
    # "comparison_right_var": 1,  # variable or constant
},

"sequence_data": [{
    "step_name": 'step_1',
    "step_type": '', # a embedded function to be used in function library
    "step_variable_a": a
    "step_variable_b": b
}]

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽梦紫曦~ 2025-02-16 15:22:44

如果您需要运行机器人框架,但不能在.robot文件中运行,则可以在Python中运行。

或者,如果要读取此JSON文件,则可以在Python中创建一个函数,或在Robot框架中搜索库JSON以读取此JSON文件并在字典中转换,以使JSON文件中的信息工作。

在Python中的字典中读取和转换此JSON文件的一个示例:

def json_to_dict(YOUR_JSON_PATH):
    try:
        with open(YOUR_JSON_PATH) as json_file:
            data = json.load(json_file) 
        return data
    except Exception as err:
        return err

您无法运行.py或.robot Archives之类的JSON文件,因为将.json文件用于信息。

If you need to run Robot Framework but not in .robot file, you can run in Python instead.

Or if you want to read this json file, you can create a function in Python or search a Library Json in Robot Framework to use for read this json file and transform in dictionary to work whit the information inside of your json file.

A example of read and transform this json file in dictionary in Python:

def json_to_dict(YOUR_JSON_PATH):
    try:
        with open(YOUR_JSON_PATH) as json_file:
            data = json.load(json_file) 
        return data
    except Exception as err:
        return err

You cannot run a json file like .py or .robot archives, because .json files is made to use for information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文