简体   繁体   中英

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? 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
}]

}

how are you?

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.

If I helped you, please, let me know!

And good luck with coding: :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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