Skip to content

Commit 86790b7

Browse files
committed
JSON working
1 parent 0105a37 commit 86790b7

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

src/har2rf-req.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,22 @@ def process_entry(entry):
883883

884884
argdata = ""
885885

886+
# headers
887+
888+
hdrs = ""
889+
for h in entry["request"]["headers"]:
890+
print("h:", h["name"], h["value"])
891+
specialh = ["cookie", "accept-encoding", "content-length"] # , "pragma", "cache-control"
892+
if h["name"].lower() not in specialh and h["name"][0] != ":":
893+
# hdrs[h["name"]] = h["value"]
894+
value = find_variable(h["name"], h["value"])
895+
hdrs += " " + h["name"] + "=" + value
896+
if len(hdrs)>0:
897+
line = "&{Req_Headers}= Create dictionary" + hdrs
898+
outdata["*** Keywords ***"][kwname].append(line)
899+
argdata += " " + "headers=${Req_Headers}"
900+
901+
886902
# GET
887903
# GET
888904
# GET
@@ -982,11 +998,11 @@ def process_entry(entry):
982998
if pd_try and "text" in pd and pd["text"][0] == "{":
983999
pd_try = False
9841000
jsondata = json.loads(pd["text"])
985-
dname = "params_{}".format(ec)
1001+
dname = "json_{}".format(ec)
9861002
paramname, lines = process_dict(dname, jsondata)
9871003
# print("paramname:", paramname, " paramlst:", paramlst)
9881004
outdata["*** Keywords ***"][kwname].extend(lines)
989-
argdata += " " + "json=${"+dname+"}"
1005+
argdata += " " + "json="+paramname
9901006

9911007

9921008
statuscode = entry["response"]["status"]
@@ -1013,36 +1029,46 @@ def process_entry(entry):
10131029
workingdata["history"].append(entry)
10141030

10151031
def process_dict(key, dictdata):
1016-
dictparam = "${"+key+"}"
1032+
# keyname = "d_"+key
1033+
keyname = key
1034+
dictparam = "${"+keyname+"}"
10171035
dictconstr = []
10181036
dicttems = ""
10191037

10201038
for dkey in dictdata.keys():
10211039
value = dictdata[dkey]
1040+
newvalue = "${EMPTY}"
10221041
print("process_dict dkey: ", dkey, " value:", value, type(value))
1042+
1043+
if value is None:
1044+
newvalue = "${None}"
10231045
if isinstance(value, str) or isinstance(value, int):
10241046
newvalue = find_variable(dkey, str(value))
10251047
# dictdata[key] = newvalue
10261048

10271049
if isinstance(value, list):
1028-
newvalue, paramlst = process_list(dkey, value)
1050+
dkeyname = keyname + "_" + dkey
1051+
newvalue, paramlst = process_list(dkeyname, value)
10291052
dictconstr.extend(paramlst)
10301053

10311054
if isinstance(value, dict):
1032-
newvalue, paramlst = process_dict(dkey, value)
1055+
dkeyname = keyname + "_" + dkey
1056+
newvalue, paramlst = process_dict(dkeyname, value)
10331057
dictconstr.extend(paramlst)
10341058

10351059
dicttems = dicttems + " " + dkey + "=" + newvalue
10361060

10371061

10381062
print("process_dict dictdata: ", dictdata)
1039-
dictconstr.append("&{" + key + "}= Create Dictionary" + dicttems)
1063+
dictconstr.append("&{" + keyname + "}= Create Dictionary" + dicttems)
10401064
print("new robot line:",dictconstr[-1])
10411065

10421066
return (dictparam, dictconstr)
10431067

10441068
def process_list(key, listdata):
1045-
dictparam = "${"+key+"}"
1069+
# keyname = "l_"+key
1070+
keyname = key
1071+
dictparam = "${"+keyname+"}"
10461072
dictconstr = []
10471073
listitems = ""
10481074
for i in range(len(listdata)):
@@ -1063,7 +1089,7 @@ def process_list(key, listdata):
10631089

10641090
listitems = listitems + " " + newvalue
10651091

1066-
dictconstr.append("@{" + key + "}= Create List" + listitems)
1092+
dictconstr.append("@{" + keyname + "}= Create List" + listitems)
10671093
print("new robot line:",dictconstr[-1])
10681094

10691095
return (dictparam, dictconstr)
@@ -1157,12 +1183,16 @@ def process_har(harfile):
11571183

11581184
# sort pages
11591185
sortedpages = sorted(har["log"]["pages"], key=lambda k: iso2sec(k["startedDateTime"]))
1186+
# sortedpages = har["log"]["pages"]
11601187
# print("sortedpages:", sortedpages)
11611188

11621189
# sort pages
11631190
sortedentries = sorted(har["log"]["entries"], key=lambda k: iso2sec(k["startedDateTime"]))
1191+
# sortedentries = har["log"]["entries"]
11641192
# print("sortedentries:", sortedentries)
11651193

1194+
e0time = iso2sec(sortedentries[0]["startedDateTime"])-0.002
1195+
11661196
i = 0
11671197
for page in sortedpages:
11681198
# pagetime = int(iso2sec(page["startedDateTime"]))
@@ -1171,6 +1201,8 @@ def process_har(harfile):
11711201
# else:
11721202
# nextpagetime = int(iso2sec(sortedpages[i+1]["startedDateTime"]))
11731203
pagetime = iso2sec(page["startedDateTime"])-0.002
1204+
if i==0 and pagetime>e0time:
1205+
pagetime=e0time
11741206
if i+1 == len(sortedpages):
11751207
nextpagetime = datetime.timestamp(datetime.now())
11761208
else:
@@ -1183,10 +1215,11 @@ def process_har(harfile):
11831215

11841216
for e in sortedentries:
11851217
# print(e)
1186-
# print(e["request"]["method"], e["request"]["url"])
1218+
print("e URL:", e["request"]["method"], e["request"]["url"])
11871219

11881220
# etime = int(iso2sec(e["startedDateTime"]))
11891221
etime = iso2sec(e["startedDateTime"])
1222+
print("e time:", etime)
11901223
if etime >= pagetime and etime < nextpagetime:
11911224
# print("etime:", etime)
11921225
process_entry(e)
@@ -1209,7 +1242,7 @@ def process_har(harfile):
12091242
add_test_case(tc)
12101243
# get robot files
12111244
# dir = os.scandir(pathin)
1212-
dir = os.listdir(pathin)
1245+
dir = sorted(os.listdir(pathin))
12131246
# print("dir:", dir)
12141247
for item in dir:
12151248
print("item:", item, ".har ==", os.path.splitext(item)[1].lower())

0 commit comments

Comments
 (0)