Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 72 additions & 17 deletions Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,31 +1541,37 @@ def save_web_elements_in_list(step_data):
all_elements = []
target_index = 0
target = []
paired = True

# paired = True
try:
for left, mid, right in step_data:
left = left.strip().lower()
mid = mid.strip().lower()
right = right.strip()
if not has_element or mid in ("element parameter", "parent parameter", "unique parameter", "child parameter", "sibling parameter"):
if not has_element and mid in ("element parameter", "parent parameter", "unique parameter", "child parameter", "sibling parameter"):
has_element = True
elif "target parameter" in mid:
target.append([[], [], [], []])
temp = right.strip(",").split(",")
data = []
for each in temp:
data.append(each.strip().split("="))
if each.strip("\n").startswith("return_contains"):
data.append(["return_contains", each.split("return_contains")[1].strip()[1:-1].split("=")])
elif each.strip("\n").startswith("return_does_not_contain"):
data.append(["return_does_not_contain", each.split("return_does_not_contain")[1].strip()[1:-1].split("=")])
else:
data.append(each.strip().split("="))
for i in range(len(data)):
for j in range(len(data[i])):
data[i][j] = data[i][j].strip()
if isinstance(data[i][j], str):
data[i][j] = data[i][j].strip()
if j == 1:
data[i][j] = data[i][j].strip('"') # dont add another strip here. dont need to strip inside quotation mark
if isinstance(data[i][j], list):
data[i][j][0], data[i][j][1] = data[i][j][0].strip().strip('"'), data[i][j][1].strip().strip('"')
elif isinstance(data[i][j], str):
data[i][j] = data[i][j].strip('"') # dont add another strip here. dont need to strip inside quotation mark

for Left, Right in data:
if Left == "return":
target[target_index][1] = Right
elif Left == "return_contains":
if Left == "return_contains":
target[target_index][2].append(Right)
elif Left == "return_does_not_contain":
target[target_index][3].append(Right)
Expand All @@ -1575,27 +1581,76 @@ def save_web_elements_in_list(step_data):
target_index = target_index + 1
elif left == "save web elements in list":
variable_name = right
elif left == "paired":
paired = False if right.lower() == "no" else True
# elif left == "paired":
# paired = False if right.lower() == "no" else True

if has_element:
Element = LocateElement.Get_Element(step_data, selenium_driver)
if Element == "failed":
CommonUtil.ExecLog(
sModuleInfo, "Unable to locate your element with given data.", 3
)
CommonUtil.ExecLog(sModuleInfo, "Unable to locate your element with given data.", 3)
return "failed"
else:
Element = selenium_driver
except:
CommonUtil.ExecLog(
sModuleInfo, "Unable to parse data. Please write data in correct format", 3
)
CommonUtil.ExecLog(sModuleInfo, "Unable to parse data. Please write data in correct format", 3)
return "failed"

for each in target:
all_elements.append(LocateElement.Get_Element(each[0], Element, return_all_elements=True))

cnt = 0
while cnt < target_index:
if target[cnt][2]:
count, to_del = 0, []
for elem in all_elements[cnt]:
for each in target[cnt][2]:
if each[0] == "text" and each[1] in elem.text:
break
else:
for each in target[cnt][2]:
if each[0] == "tag" and each[1] in elem.tag_name:
break
else:
for each in target[cnt][2]:
if each[0] not in ("text", "tag") and elem.get_attribute(each[0]) is None:
break
else:
for each in target[cnt][2]:
if each[0] not in ("text", "tag") and each[1] in elem.get_attribute(each[0]):
break
else:
to_del.append(count)
count += 1
all_elements[cnt] = CommonUtil.Delete_from_list(all_elements[cnt], to_del)
# Using this function to delete in O(N) complexity
if target[cnt][3]:
count, to_del = 0, []
for elem in all_elements[cnt]:
for each in target[cnt][3]:
if each[0] == "text" and each[1] in elem.text:
to_del.append(count)
break
else:
for each in target[cnt][3]:
if each[0] == "tag" and each[1] in elem.tag_name:
to_del.append(count)
break
else:
for each in target[cnt][3]:
if each[0] not in ("text", "tag") and elem.get_attribute(each[0]) is None:
to_del.append(count)
break
else:
for each in target[cnt][3]:
if each[0] not in ("text", "tag") and each[1] in elem.get_attribute(each[0]):
to_del.append(count)
break

count += 1
all_elements[cnt] = CommonUtil.Delete_from_list(all_elements[cnt], to_del)

cnt += 1

if target_index == 1:
return Shared_Resources.Set_Shared_Variables(variable_name, all_elements[0])
else:
Expand Down
19 changes: 18 additions & 1 deletion Framework/Utilities/CommonUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def CreateJsonReport(logs=None, stepInfo=None, TCInfo=None, setInfo=None):
# Can be optimized by taking error when occurs and append it if the step fails only
while count >= max_count and err_count < 3:
each_log = step_info["log"][count]
if each_log["status"].lower() == "error" and not each_log["details"].endswith(to_dlt_from_fail_reason):
if each_log["status"].lower() == "error":
step_error_logs.append(each_log["details"])
err_count += 1
count -= 1
Expand Down Expand Up @@ -814,6 +814,23 @@ def check_offline():
return False


def Delete_from_list(List, to_del):
""" This function can delete multiple elements from list with O(N) complexity """
if not to_del:
return List
to_del.sort()
cnt, del_cnt, new_list, check = 0, 0, [], True
for i in List:
if check and cnt == to_del[del_cnt]:
del_cnt += 1
if del_cnt == len(to_del):
check = False
else:
new_list.append(i)
cnt += 1
return new_list


class MachineInfo:
def getLocalIP(self):
"""
Expand Down
10 changes: 3 additions & 7 deletions node_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,15 @@ def disconnect_from_server():

def RunProcess(sTesterid, user_info_object):
etime = time.time() + (30 * 60) # 30 minutes
executor = CommonUtil.GetExecutor()
while 1:
try:
if exit_script:
return False
if time.time() > etime:
print("30 minutes over, logging in again")
return True # Timeout reached, re-login. We do this because after about 3-4 hours this function will hang, and thus not be available for deployment

executor.submit(RequestFormatter.Get, "update_machine_with_time_api", {"machine_name": sTesterid})
# r = RequestFormatter.Get("is_run_submitted_api", {"machine_name": sTesterid})
r = requests.get(RequestFormatter.form_uri("is_submitted_api"), {"machine_name": sTesterid}, verify=False).json()
Userid = (CommonUtil.MachineInfo().getLocalUser()).lower()
Expand Down Expand Up @@ -453,12 +454,7 @@ def RunProcess(sTesterid, user_info_object):
)
else:
time.sleep(3)
executor = CommonUtil.GetExecutor()
executor.submit(RequestFormatter.Get, "update_machine_with_time_api", {"machine_name": sTesterid})
# if r and "update" in r and r["update"]:
# _r = RequestFormatter.Get(
# "update_machine_with_time_api", {"machine_name": sTesterid}
# )

except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
Expand Down