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"***
}
}
]
}
I need to use different config files for different test cases. Can I reference the config1 object of preparation object in the execution???
No, you can't do that, at least not directly. For a start, JSON doesn't support circular references.
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.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments