My requirement is to update a JSON structure and then write it into a file using key value pair. Below is my Python script, based upon the values for TESTVER, TESTLVL and TESTGRP we will receive from Robot script we need to update it:
cmd =
"""{
"TESTVER": "v1",
"TESTLVL": "Level1",
"TESTGRP": "SET"
}"""
class myLib(object):
def change_test_details(self, ver, lvl, grp):
d = json.loads(cmd)
d["TESTVER"] = ver
d["TESTLVL"] = lvl
d["TESTGRP"] = grp
print(json.dumps(d, indent=2))
This is my Robot script extract:
test Suite to be selected and executed ${TEST}
Log to Console ${TEST}
Change test details "v1", "L1", "Get"
I keep getting " No keyword with name 'Change test details' found. " - how can I pass multiple param from Robot to Python scripts?
cmd = """{
"TESTVER": "v1",
"TESTLVL": "Level1",
"TESTGRP": "SET"
}"""
class myLib(object):
def change_test_details(self, ver, lvl, grp,filename):
d = json.loads(cmd)
d["TESTVER"] = ver
d["TESTLVL"] = lvl
d["TESTGRP"] = grp
with open(filename, 'w') as outfile:
json.dump(d, outfile,indent=2)
return 'Done'
x=myLib()
ver=1
lvl=1
grp=1
filename =r'file.json'
v=x.change_test_details(ver, lvl, grp,filename)
print(v)
"""
output
done
"""
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.