1
我想开发一个使用json来描述数据的测试自动化框架。 我有一个JSON文件,该文件是这样的:我可以在同一个json文件中引用另一个对象中的一个json对象吗?
{
"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对象吗?
据我所知,不是纯粹的JSON。现在,您可以在解析时创建一些标记,并在创建对象时引用该对象。所以'obj = JSON.parse(json)',然后循环访问'obj'的属性'值并引用其他属性,如果它匹配某种语法(即'preperation.configuration [0] .config1.dest_configfile')。 – Sam 2014-09-24 18:11:14
为什么你需要在那里引用config1对象?我假设无论运行时应用程序使用这个,只需要知道要使用哪个配置(即只是config1属性名称),而不需要引用整个对象路径。 – 2014-09-24 18:43:26