我正在尝试使用json开发测试自动化框架来描述数据. 我有一个看起来像这样的json文件:
I'm trying to develop a test automation framework using json to describe data. I have a json file which looks like this:
{ "preparation":{ "configuration":[ { "config1":{ "src_configfile":"/home/xxx/etc/src_config1.cfg", "dest_configfile":"/home/xxx/etc/abc.cfg" } }, { "config2":{ "src_configfile":"/home/xxx/etc/src_config2.cfg", "dest_configfile":"/home/xxx/etc/xyz.cfg" } } ], "executable_info1":[ { "login_info":{ "hostname":"abc.dw", "username":"xyz", "password":"*******" } }, { "command":{ "folderpath":"/home/xxx/yyy/bin", "processname":"sys.exe", "parameters":"-d" } } ], }, "execution":[ { "test_case1":{ "folderpath":"/home/xxx/testscripts", "scriptname":"test_case1.py", ***???????????Can I access the config1 object here???????????? "config_file"="preparation.configuration[0].config1.dest_configfile"*** } }, { "test_case1":{ "folderpath":"/home/xxx/testscripts", "scriptname":"test_case2.py", ***"config_file"="preparation.configuration[1].config2.dest_configfile"*** } } ] }我需要针对不同的测试用例使用不同的配置文件.我可以在执行中引用准备对象的config1对象吗???
I need to use different config files for different test cases. Can I reference the config1 object of preparation object in the execution???
推荐答案不,您不能这样做,至少不能直接这样做.首先,JSON不支持循环引用.
No, you can't do that, at least not directly. For a start, JSON doesn't support circular references.
您可能会考虑使用诸如jsonpath之类的库,该库允许您按模式引用元素,但是无论值是实际值还是对其他分支的引用,您都倾向于先验.
You might consider using a library such as jsonpath that allows you to reference elements by pattern, but you would tend to need apriori whether a value was an actual value or a reference to some other branch.
更多推荐
我可以在同一个json文件中的另一个对象中引用一个json对象吗?
发布评论