diff --git a/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py b/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py index 1ad42d30b..66b3e275a 100644 --- a/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py +++ b/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py @@ -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) @@ -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: diff --git a/Framework/Utilities/CommonUtil.py b/Framework/Utilities/CommonUtil.py index 15be8f2b6..2d6c8e6ef 100644 --- a/Framework/Utilities/CommonUtil.py +++ b/Framework/Utilities/CommonUtil.py @@ -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 @@ -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): """ diff --git a/node_cli.py b/node_cli.py index e972657d7..e745ae7b5 100755 --- a/node_cli.py +++ b/node_cli.py @@ -403,6 +403,7 @@ 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: @@ -410,7 +411,7 @@ def RunProcess(sTesterid, user_info_object): 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() @@ -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]