简体   繁体   English

无论如何都可以在没有 .robot/.txt 脚本的情况下运行机器人框架,或者我可以从一些数据生成 .robot/.txt 文件吗?

[英]Is there anyway to run robot framework without a .robot/.txt script, or can I generate .robot/.txt file from some data?

Is there any way to run robot framework with a code or json instead of.robot file?有什么方法可以使用代码或 json 而不是 .robot 文件来运行机器人框架? Or should I generate a.robot file first and then run?还是先生成一个.robot文件再运行? 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).我不确定是否有更好的方法来执行此操作,因为某些步骤取决于前面的步骤 output(unittest/pytest 不支持此操作)。

I have a list of test sequences in json, for example例如,我在 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
}]

} }

how are you?你好吗?

If you need to run Robot Framework but not in.robot file, you can run in Python instead.如果你需要运行Robot Framework而不是in.robot文件,你可以在Python中运行。

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.或者如果你想阅读这个 json 文件,你可以在 Python 中创建一个 function 或者在 Robot Framework 中搜索一个库 Json 来读取这个 json 文件并在字典中转换以使用你的 881759586304 中的信息。

A example of read and transform this json file in dictionary in Python:在 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

You cannot run a json file like.py or.robot archives, because.json files is made to use for information.您不能运行 json 文件,例如 .py 或 .robot 存档,因为 .json 文件是用来提供信息的。

If I helped you, please, let me know!如果我帮助了你,请告诉我!

And good luck with coding: :)祝你编码顺利: :)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM