From 7053445588a178089cbcc4285c48d91ee5994f0b Mon Sep 17 00:00:00 2001 From: Muntasib-creator Date: Mon, 2 Sep 2024 14:07:55 +0600 Subject: [PATCH] Remove unnecessary actions and functions --- .../action_declarations/selenium.py | 12 +- .../Web/Selenium/BuiltInFunctions.py | 1231 +---------------- 2 files changed, 42 insertions(+), 1201 deletions(-) diff --git a/Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py b/Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py index 638c3a0f..4f9265b4 100644 --- a/Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py +++ b/Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py @@ -2,14 +2,12 @@ { "name": "click", "function": "Click_Element", "screenshot": "web" }, { "name": "click and hold", "function": "Click_and_Hold_Element", "screenshot": "web" }, { "name": "click and download", "function": "Click_and_Download", "screenshot": "web" }, - { "name": "context click", "function": "Context_Click_Element", "screenshot": "web" }, + { "name": "right click", "function": "Right_Click_Element", "screenshot": "web" }, { "name": "double click", "function": "Double_Click_Element", "screenshot": "web" }, - { "name": "move to element", "function": "Move_To_Element", "screenshot": "web" }, { "name": "hover", "function": "Hover_Over_Element", "screenshot": "web" }, { "name": "keystroke keys", "function": "Keystroke_For_Element", "screenshot": "web" }, { "name": "keystroke chars", "function": "Keystroke_For_Element", "screenshot": "web" }, { "name": "text", "function": "Enter_Text_In_Text_Box", "screenshot": "web" }, - { "name": "initialize list", "function": "Initialize_List", "screenshot": "web" }, { "name": "validate full text", "function": "Validate_Text", "screenshot": "web" }, { "name": "validate partial text", "function": "Validate_Text", "screenshot": "web" }, { "name": "deselect all", "function": "Select_Deselect", "screenshot": "web" }, @@ -27,14 +25,12 @@ { "name": "switch browser", "function": "Switch_Browser", "screenshot": "none"}, { "name": "get current url", "function": "Get_Current_URL", "screenshot": "none"}, { "name": "navigate", "function": "Navigate", "screenshot": "web" }, - { "name": "get location", "function": "get_location_of_element", "screenshot": "web" }, { "name": "validate table", "function": "validate_table", "screenshot": "web" }, { "name": "handle alert", "function": "Handle_Browser_Alert", "screenshot": "desktop"}, { "name": "browser", "function": "Open_Browser_Wrapper", "screenshot": "web" }, { "name": "teardown", "function": "Tear_Down_Selenium", "screenshot": "none"}, { "name": "open new tab", "function": "open_new_tab", "screenshot": "web" }, { "name": "close tab", "function": "close_tab", "screenshot": "web" }, - { "name": "switch tab", "function": "switch_tab", "screenshot": "web" }, { "name": "validate table row size", "function": "validate_table_row_size", "screenshot": "web" }, { "name": "validate table column size", "function": "validate_table_column_size", "screenshot": "web" }, { "name": "upload file", "function": "upload_file", "screenshot": "web" }, @@ -46,10 +42,7 @@ { "name": "scroll to element", "function": "scroll_to_element", "screenshot": "web" }, { "name": "scroll element to top", "function": "scroll_to_element", "screenshot": "web" }, { "name": "scroll to top", "function": "scroll_to_top", "screenshot": "web" }, - { "name": "if element exists", "function": "if_element_exists", "screenshot": "web" }, - { "name": "click and enter text", "function": "Click_and_Text", "screenshot": "web" }, - { "name": "validate url", "function": "Validate_Url", "screenshot": "web" }, - { "name": "switch window", "function": "switch_window", "screenshot": "web" }, + { "name": "switch window", "function": "switch_window_or_tab", "screenshot": "web" }, { "name": "switch window or frame", "function": "switch_window_or_tab", "screenshot": "web" }, { "name": "switch window/tab", "function": "switch_window_or_tab", "screenshot": "web" }, { "name": "switch iframe", "function": "switch_iframe", "screenshot": "web" }, @@ -58,7 +51,6 @@ { "name": "extract table data", "function": "Extract_Table_Data", "screenshot": "web" }, { "name": "save web elements in list", "function": "save_web_elements_in_list", "screenshot": "web" }, { "name": "take screenshot web", "function": "take_screenshot_selenium", "screenshot": "web" }, - { "name": "mouse click", "function": "Mouse_Click_Element", "screenshot": "web" }, { "name": "execute javascript", "function": "execute_javascript", "screenshot": "web" }, { "name": "check uncheck all", "function": "check_uncheck_all", "screenshot": "web" }, { "name": "check uncheck", "function": "check_uncheck", "screenshot": "web" }, diff --git a/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py b/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py index 86cda330..7a2b7fba 100644 --- a/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py +++ b/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py @@ -1535,14 +1535,6 @@ def Handle_Browser_Alert(step_data): ErrorMessage = "Failed to handle alert" return CommonUtil.Exception_Handler(sys.exc_info(), None, ErrorMessage) - -@logger -@deprecated -def Initialize_List(data_set): - """ Temporary wrapper until we can convert everything to use just data_set and not need the extra [] """ - return Shared_Resources.Initialize_List([data_set]) - - @logger def save_screenshot(driver, path): """ @@ -2173,115 +2165,9 @@ def Click_and_Download(data_set): return CommonUtil.Exception_Handler(sys.exc_info()) -@logger -def Mouse_Click_Element(data_set): - """ - This funciton will move the mouse to the element and then perform a physical mouse click - - element_prop element parameter element_value - mouse click selenium action click - - - - """ - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - # Click using elemen - CommonUtil.ExecLog(sModuleInfo, "Looking for element", 0) - # Get element object - Element = LocateElement.Get_Element(data_set, selenium_driver) - if Element in failed_tag_list: - CommonUtil.ExecLog(sModuleInfo, "Could not find element", 3) - return "zeuz_failed" - # Get element location - - # Get element size - try: - size_ele = ( - Element.size - ) # Retreive the dictionary containing the x,y location coordinates - if size_ele in failed_tag_list: - CommonUtil.ExecLog(sModuleInfo, "Could not get element location", 3) - return "zeuz_failed" - # Find center of the element. We will use offset - width = (size_ele["width"]) / 2 - height = (size_ele["height"]) / 2 - except Exception: - return CommonUtil.Exception_Handler( - sys.exc_info(), None, "Error retrieving element location" - ) - try: - actions = ActionChains(selenium_driver) - actions.move_to_element_with_offset(Element, width, height).click().perform() - CommonUtil.ExecLog(sModuleInfo, "Successfully clicked the element", 1) - return "passed" - except Exception: - - errMsg = "Could not select/click your element." - return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) - - -# Method to click and hold on element; step data passed on by the user -@logger -def Click_and_Text(data_set): - """ Click and enter text specially for dropdown box""" - - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - data_set_to = [] - data_set_to2 = [] - - for row in data_set: - if row[0] == "click and enter text" and row[1] == "action": - row[2].lower() - data_set_to2.append(("keystroke chars", "action", row[2])) - - elif row[1] == "element parameter": - data_set_to.append(row) - Click_Element(data_set_to) - - Keystroke_For_Element(data_set_to2) - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - -@logger -def Click_and_Hold_Element(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - Element = LocateElement.Get_Element(step_data, selenium_driver) - if Element != "zeuz_failed": - try: - click_and_hold = ActionChains(selenium_driver).click_and_hold(Element) - click_and_hold.perform() - CommonUtil.ExecLog( - sModuleInfo, - "Successfully clicked and held the element with given parameters and values", - 1, - ) - return "passed" - except Exception: - try: - element_attributes = Element.get_attribute("outerHTML") - CommonUtil.ExecLog(sModuleInfo, "Element Attributes: %s" % (element_attributes), 3) - errMsg = "Could not click and hold your element." - return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) - except: - return CommonUtil.Exception_Handler(sys.exc_info()) - else: - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your element with given data.", 3 - ) - return "zeuz_failed" - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - # Method to right click on element; step data passed on by the user @logger -def Context_Click_Element(step_data): +def Right_Click_Element(step_data): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME global selenium_driver try: @@ -2347,39 +2233,6 @@ def Double_Click_Element(step_data): return CommonUtil.Exception_Handler(sys.exc_info()) -# Method to move to middle of the element; step data passed on by the user -@logger -def Move_To_Element(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - Element = LocateElement.Get_Element(step_data, selenium_driver) - if Element != "zeuz_failed": - try: - move = ActionChains(selenium_driver).move_to_element(Element).perform() - CommonUtil.ExecLog( - sModuleInfo, - "Successfully moved to the middle of the element with given parameters and values", - 1, - ) - return "passed" - except Exception: - try: - element_attributes = Element.get_attribute("outerHTML") - CommonUtil.ExecLog(sModuleInfo, "Element Attributes: %s" % (element_attributes), 3) - errMsg = "Could not click and hold your element." - return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) - except: - return CommonUtil.Exception_Handler(sys.exc_info()) - else: - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your element with given data.", 3 - ) - return "zeuz_failed" - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - # Method to hover over element; step data passed on by the user @logger def Hover_Over_Element(step_data): @@ -2414,56 +2267,6 @@ def Hover_Over_Element(step_data): return CommonUtil.Exception_Handler(sys.exc_info()) -@logger -def get_location_of_element(data_set): - """ Returns the x,y location of an element """ - - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - # Parse data set - try: - shared_var = "" - for row in data_set: - if row[1] == "action": - shared_var = row[2] # Save the shared variable name - - if shared_var == "": - CommonUtil.ExecLog( - sModuleInfo, "Shared variable name missing from Value on action row", 3 - ) - return "zeuz_failed" - except Exception: - return CommonUtil.Exception_Handler( - sys.exc_info(), None, "Error parsing data set" - ) - - # Get element object - Element = LocateElement.Get_Element(data_set, selenium_driver) - if Element in failed_tag_list: - CommonUtil.ExecLog(sModuleInfo, "Could not find element", 3) - return "zeuz_failed" - - # Get element location - try: - location = ( - Element.location - ) # Retreive the dictionary containing the x,y location coordinates - if location in failed_tag_list: - CommonUtil.ExecLog(sModuleInfo, "Could not get element location", 3) - return "zeuz_failed" - - # Save location as string, in preparation for the shared variable - x = str(location["x"]) - y = str(location["y"]) - except Exception: - return CommonUtil.Exception_Handler( - sys.exc_info(), None, "Error retrieving element location" - ) - - # Save location in shared variable - Shared_Resources.Set_Shared_Variables(shared_var, "%s,%s" % (x, y)) - return "passed" - @logger def get_element_info(dataset): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME @@ -2539,196 +2342,6 @@ def Save_Attribute(step_data): return CommonUtil.Exception_Handler(sys.exc_info()) -# Search for element on new page after a particular time-out duration entered by the user through step-data -@logger -def Wait_For_New_Element(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - Element = LocateElement.Get_Element(step_data, selenium_driver) - wait_for_element_to_disappear = False - for each in step_data: - if each[1] == "action": - timeout_duration = int(each[2]) - if each[0] == "wait disable": - wait_for_element_to_disappear = True - start_time = time.time() - interval = 1 - for i in range(timeout_duration): - time.sleep(time.time() + i * interval - start_time) - Element = LocateElement.Get_Element(step_data, selenium_driver) - if wait_for_element_to_disappear == False: - if Element == "zeuz_failed": - continue - else: - return "passed" - else: - if Element == "zeuz_failed": - return "passed" - else: - continue - if wait_for_element_to_disappear == False: - CommonUtil.ExecLog( - sModuleInfo, "Waited for %s seconds but couldnt locate your element", 3 - ) - else: - CommonUtil.ExecLog( - sModuleInfo, "Waited for %s seconds but your element still exists", 3 - ) - return "zeuz_failed" - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - -# Validating text from an element given information regarding the expected text -@logger -def Compare_Lists(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - try: - return Shared_Resources.Compare_Lists([step_data]) - except: - return CommonUtil.Exception_Handler(sys.exc_info()) - - -# Validating text from an element given information regarding the expected text -@logger -def Compare_Variables(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - try: - return Shared_Resources.Compare_Variables([step_data]) - except: - return CommonUtil.Exception_Handler(sys.exc_info()) - - -# Inserting a field into a list of shared variables -@logger -def Insert_Into_List(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - try: - if len(step_data) == 1: # will have to test #saving direct input string data - list_name = "" - key = "" - value = "" - full_input_key_value_name = "" - - for each_step_data_item in step_data: - if each_step_data_item[1] == "action": - full_input_key_value_name = each_step_data_item[2] - - temp_list = full_input_key_value_name.split(",") - if len(temp_list) == 1: - CommonUtil.ExecLog( - sModuleInfo, - "Value must contain more than one item, and must be comma separated", - 3, - ) - return "zeuz_failed" - else: - list_name = temp_list[0].split(":")[1].strip() - key = temp_list[1].split(":")[1].strip() - value = temp_list[2].split(":")[1].strip() - - result = Shared_Resources.Set_List_Shared_Variables(list_name, key, value) - if result in failed_tag_list: - CommonUtil.ExecLog( - sModuleInfo, - "In list '%s' Value of Variable '%s' could not be saved!!!" - % (list_name, key), - 3, - ) - return "zeuz_failed" - else: - Shared_Resources.Show_All_Shared_Variables() - return "passed" - - else: - Element = LocateElement.Get_Element(step_data, selenium_driver) - if Element == "zeuz_failed": - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your element with given data.", 3 - ) - return "zeuz_failed" - list_name = "" - key = "" - for each_step_data_item in step_data: - if each_step_data_item[1] == "action": - key = each_step_data_item[2] - # get list name from full input_string - temp_list = key.split(",") - if len(temp_list) == 1: - CommonUtil.ExecLog( - sModuleInfo, - "Value must contain more than one item, and must be comma separated", - 3, - ) - return "zeuz_failed" - else: - list_name = str(temp_list[0]).split(":")[1].strip() - key = str(temp_list[1]).strip() - - # get text from selenium element - list_of_element_text = Element.text.split("\n") - visible_list_of_element_text = "" - for each_text_item in list_of_element_text: - if each_text_item != "": - visible_list_of_element_text += each_text_item - # save text in the list of shared variables in CommonUtil - result = Shared_Resources.Set_List_Shared_Variables( - list_name, key, visible_list_of_element_text - ) - if result in failed_tag_list: - CommonUtil.ExecLog( - sModuleInfo, - "In list '%s' Value of Variable '%s' could not be saved!!!" - % (list_name, key), - 3, - ) - return "zeuz_failed" - else: - Shared_Resources.Show_All_Shared_Variables() - return "passed" - - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - -# Validating text from an element given information regarding the expected text -@logger -def Save_Text(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - Element = LocateElement.Get_Element(step_data, selenium_driver) - if Element == "zeuz_failed": - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your element with given data.", 3 - ) - return "zeuz_failed" - for each_step_data_item in step_data: - if each_step_data_item[1] == "action": - variable_name = each_step_data_item[2] - list_of_element_text = Element.text.split("\n") - visible_list_of_element_text = "" - for each_text_item in list_of_element_text: - if each_text_item != "": - visible_list_of_element_text += each_text_item - result = Shared_Resources.Set_Shared_Variables( - variable_name, visible_list_of_element_text - ) - if result in failed_tag_list: - CommonUtil.ExecLog( - sModuleInfo, - "Value of Variable '%s' could not be saved!!!" % variable_name, - 3, - ) - return "zeuz_failed" - else: - Shared_Resources.Show_All_Shared_Variables() - return "passed" - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - @logger def save_attribute_values_in_list(step_data): """ @@ -3138,63 +2751,6 @@ def Validate_Text(step_data): return CommonUtil.Exception_Handler(sys.exc_info()) -@logger -def Validate_Url(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - url = selenium_driver.current_url - expected = "" - - for row in step_data: - if str(row[1]).strip() == "action": - expected = str(row[2]).strip() - - if str(expected).startswith("*"): - expected = expected[1:] - if expected in url: - CommonUtil.ExecLog(sModuleInfo, "Expected URL partially matched", 1) - return "passed" - else: - CommonUtil.ExecLog( - sModuleInfo, "Expected URL didn't match partially", 3 - ) - return "zeuz_failed" - else: - if expected == url: - CommonUtil.ExecLog(sModuleInfo, "Expected URL matched", 1) - return "passed" - else: - CommonUtil.ExecLog(sModuleInfo, "Expected URL didn't match", 3) - return "zeuz_failed" - - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - -# Method to sleep for a particular duration -@logger -def Sleep(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - if 1 < len(step_data) >= 2: - CommonUtil.ExecLog( - sModuleInfo, - "Please provide single row of data for only sleep. Consider using wait instead", - 3, - ) - return "zeuz_failed" - else: - tuple = step_data[0] - seconds = int(tuple[2]) - CommonUtil.ExecLog(sModuleInfo, "Sleeping for %s seconds" % seconds, 1) - time.sleep(seconds) - return "passed" - # return result - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - def generate_scroll_offset(direction: str, pixel: int) -> str: if direction == "down": @@ -3468,534 +3024,6 @@ def Select_Deselect(step_data): return CommonUtil.Exception_Handler(sys.exc_info()) -@logger -def validate_table(data_set): - """ Compare the table provided in step data with the one found on the web page """ - # Compare a webpage table with one specified in the step data - # All inputs have the sub-field set as "table parameter" - # Valid table parameters: - # > ignore rows: Ignores the comma delimited rows specified in the Value field - # > ignore columns: Ignores the comma delimited columns specified in the Value field - # > case: Value=Sensitive: This is the default, and values must match exactly. Value=insensitive: Perform case insensitive matching - # > exact: True (default) do nothing. False= Infer which cells to ignore. This is similar to ignore rows/cols, but can ignore specific cells if the user does not specify them. Mutually exclusive of ignore rows/cols - global selenium_driver - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - - # Initialize variables - have_table = False # Tells us if we read a table from the step data - case_sensitive = True # Case sensitive search - coordinates_exact = True # Table coordinates should match by default - ignore_rows = [] # List of rows to ignore/skip - ignore_cols = [] # List of columns to ignore/skip - user_table = {} # Constructed user-defined table - webpage_table = {} # Constructed webpage table - exact_table = True # Require exact table match - table_type = "" # Type of table (css/html) - - # Parse data set - try: - for row in data_set: - field, subfield, value = ( - row[0], - row[1], - row[2], - ) # Put data row in understandable variables - - if subfield == "action": - if value.strip().lower() in ("css", "html"): - table_type = value - else: - CommonUtil.ExecLog( - sModuleInfo, - "Invalid table type in Value on Action line. Should be 'html' or 'css'", - 3, - ) - return "zeuz_failed" - elif ( - subfield == "table parameter" - ): # Inspect the table parameters (element parameters go to a different section) - - # Parse table instructions - if ( - field == "ignore row" or field == "ignore rows" - ): # User specified list of rows to ignore - ignore_rows = value.split( - "," - ) # Get rows as comma delimited string and store in list - ignore_rows = list(map(int, ignore_rows)) # Convert to integers - elif ( - field == "ignore column" or field == "ignore columns" - ): # User specified list of columns to ignore - ignore_cols = value.split( - "," - ) # Get columns as comma delimited string and store in list - ignore_cols = list(map(int, ignore_cols)) # Convert to integers - elif ( - field == "coordinates" - ): # Check if user specifies if table coordinates should match - if ( - value.lower().strip() == "identical" - ): # Table coordinates should match - coordinates_exact = True - elif ( - value.lower().strip() == "nonidentical" - ): # Table coordinates don't have to match - coordinates_exact = False - elif field == "case": # User specified case sensitivity - if ( - value.lower().strip() == "exact" - or value.lower().strip() == "sensitive" - ): # Sensitive match (default) - case_sensitive = True - elif ( - value.lower().strip() == "insensitive" - ): # Insensitive match - we'll convert everything to lower case - case_sensitive = False - elif field == "exact": # User specified type of table matching - if ( - value.lower().strip() == "true" - or value.lower().strip() == "yes" - ): # Exact table match, but user can specify rows/columns to ignore - exact_table = True - elif ( - value.lower().strip() == "false" - or value.lower().strip() == "no" - ): # Not an exact match for all cells, only match the ones the user specified - exact_table = False - else: - CommonUtil.ExecLog( - sModuleInfo, - "Unknown Value for table parameter 'exact'. Should be true or false.", - 3, - ) - return "zeuz_failed" - - # Create user-defined table - else: - try: - table_row, table_col = ("", "") - table_row, table_col = field.split( - "," - ) # Field should be in the format of ROW,COL - if ( - table_row != "" and table_col != "" - ): # Check to ensure this was a table cell identifier - may not be - if ( - case_sensitive == False - ): # User specified case insensitive serach - value = ( - value.lower() - ) # Prepare this table by setting all cell values to lowercase - user_table[ - "%s,%s" % (table_row, table_col) - ] = value # Save value using the row,col as an identifier - have_table = True # Indicate we have at least one cell of a table specified - else: - CommonUtil.ExecLog( - sModuleInfo, "Unknown Field for table parameter", 3 - ) - return "zeuz_failed" - except: # Row may have been blank, or some other issue - return CommonUtil.Exception_Handler( - sys.exc_info(), None, "Unknown Field for table parameter" - ) - - # Ensure we have a table from the user - if have_table == False: - CommonUtil.ExecLog( - sModuleInfo, - "No table values found, or they were not entered in the format of row,column (Eg: 1,2). Please create a table as defined in the documentation", - 3, - ) - return "zeuz_failed" - CommonUtil.ExecLog( - sModuleInfo, - "Table parameters - Case Sensitive: %s - ignore_rows: %s - ignore_cols: %s - exact: %s" - % ( - str(case_sensitive), - str(ignore_rows), - str(ignore_cols), - str(exact_table), - ), - 0, - ) - except Exception: - return CommonUtil.Exception_Handler( - sys.exc_info(), None, "Error while parsing the data set" - ) - - # Get table from web page - if table_type == "html": # HTML type table - webpage_table = get_webpage_table_html( - data_set, ignore_rows, ignore_cols, case_sensitive - ) # Produces an array that should match the user array - elif table_type == "css": # CSS type table - webpage_table = get_webpage_table_css( - data_set, ignore_rows, ignore_cols, case_sensitive - ) # Produces an array that should match the user array - CommonUtil.ExecLog(sModuleInfo, "Webpage table : %s" % webpage_table, 0) - CommonUtil.ExecLog(sModuleInfo, "Step data table: %s" % user_table, 0) - if webpage_table in failed_tag_list: - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your element with given data.", 3 - ) - return "zeuz_failed" - - # If user did not specify any rows or columns to ignore, we will infer that rows and columns NOT defined are meant to be ignored - # We do this by modifying the webpage table to remove rows and columns that don't match - if ( - exact_table == False and ignore_rows == [] and ignore_cols == [] - ): # If user did not specify anything to ignore - CommonUtil.ExecLog( - sModuleInfo, "Inferring which cells from the webpage table to ignore", 0 - ) - unmatched_cells = [] - for ( - ids - ) in ( - webpage_table - ): # For each table cell on the user table - basically looking for items that are specified, but not found - if ( - ids not in user_table - ): # if cell from user table not found in webpage table - unmatched_cells.append( - ids - ) # Keep list of cell IDs we want to trim from the webpage table - CommonUtil.ExecLog( - sModuleInfo, "Removing inferred cells: %s" % str(unmatched_cells), 0 - ) - for ids in unmatched_cells: # Remove these cells from the webpage table - if ( - ids in webpage_table - ): # Check if the ID exists in case the user specified something that's not actually in the webpage table - del webpage_table[ids] - - if ( - coordinates_exact == False - ): # If user specifies that cells locations do not have to match - unmatched_cells = [] - for ids in user_table: - if user_table[ids] not in webpage_table.values(): - unmatched_cells.append(user_table[ids]) - - if len(unmatched_cells) > 0: - CommonUtil.ExecLog( - sModuleInfo, - "Not all elements exist in webpage table - %s" % str(unmatched_cells), - 3, - ) - return "zeuz_failed" - else: - CommonUtil.ExecLog(sModuleInfo, "Elements exist in webpage table", 1) - return "passed" - - # Check if arrays match - failed_matches = [] - for ids in webpage_table: # For each table cell on the webpage table - if ids in user_table: # If that table cell is also in the user defined table - if ( - webpage_table[ids] != user_table[ids] - ): # Check if the values of these two cells match - failed_matches.append( - '%s:"%s" != %s:"%s"' - % (ids, user_table[ids], ids, webpage_table[ids]) - ) # Record the unmatched cells - else: # Not in user table - failed_matches.append("Cell %s is not defined in the step data" % ids) - - for ( - ids - ) in ( - user_table - ): # For each table cell on the user table - basically looking for items that are specified, but not found - if ( - ids not in webpage_table - ): # if cell from user table not found in webpage table - failed_matches.append("Cell %s is not found in the webpage table" % ids) - - # If any failed matches, list them in the log, so the user can see and exit - if len(failed_matches) > 0: - CommonUtil.ExecLog( - sModuleInfo, "Tables do not match - %s" % str(failed_matches), 3 - ) - return "zeuz_failed" - - CommonUtil.ExecLog(sModuleInfo, "Tables match", 1) - return "passed" - - -@logger -def validate_table_row_size(data_set): - """ Save row size in a share variable of the table provided in step data""" - - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - # Initialize variables - expected_row = "" # variable where the row size will be saved - table_type = "" # Type of table (css/html) - - # Parse data set - - for row in data_set: - field, subfield, value = ( - row[0], - row[1], - row[2], - ) # Put data row in understandable variables - - if subfield == "action": - table_type, expected_row = str(value).split(",") - - if table_type == "" or expected_row == "": - CommonUtil.ExecLog( - sModuleInfo, - "No table type or expected row is given.. table type should be html or css, expected row is a number which is the expected row size", - 3, - ) - return "zeuz_failed" - - # Get table from web page - table = LocateElement.Get_Element(data_set, selenium_driver) - - if table in failed_tag_list: - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your table with given data.", 3 - ) - return "zeuz_failed" - - all_rows = [] - if table_type == "html": # HTML type table - all_rows = table.find_elements("tag name", - "tr" - ) # Get element list for all rows - elif table_type == "css": # CSS type table - all_rows = WebDriverWait(table, WebDriver_Wait).until( - EC.presence_of_all_elements_located((By.XPATH, "*")) - ) - - row_size = len(all_rows) - - CommonUtil.ExecLog(sModuleInfo, "Webpage table row size: %s" % row_size, 1) - CommonUtil.ExecLog(sModuleInfo, "Expected table row size: %s" % expected_row, 1) - - if int(row_size) != int(expected_row): - CommonUtil.ExecLog(sModuleInfo, "Row sizes don't match", 3) - return "zeuz_failed" - - CommonUtil.ExecLog(sModuleInfo, "Row sizes match", 1) - return "passed" - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info(), None) - - -@logger -def validate_table_column_size(data_set): - """ Save row size in a share variable of the table provided in step data""" - global selenium_driver - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - try: - # Initialize variables - expected_col = "" # variable where the row size will be saved - table_type = "" # Type of table (css/html) - - # Parse data set - - for row in data_set: - field, subfield, value = ( - row[0], - row[1], - row[2], - ) # Put data row in understandable variables - - if subfield == "action": - table_type, expected_col = str(value).split(",") - - if table_type == "" or expected_col == "": - CommonUtil.ExecLog( - sModuleInfo, - "No table type or expected column is given.. table type should be html or css, expected column is a number which is the expected row size", - 3, - ) - return "zeuz_failed" - - # Get table from web page - table = LocateElement.Get_Element(data_set, selenium_driver) - - if table in failed_tag_list: - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your table with given data.", 3 - ) - return "zeuz_failed" - - all_rows = [] - all_cols = [] - if table_type == "html": # HTML type table - all_rows = table.find_elements("tag name", - "tr" - ) # Get element list for all rows - if len(all_rows) > 0: - all_cols = all_rows[0].find_elements("tag name", - "td" - ) # Get element list for all columns in this row - if ( - len(all_cols) == 0 - ): # No type columns, so check if there were header type columns, and use those instead - all_cols = all_rows[0].find_elements("tag name", - "th" - ) # Get element list for all header columns in this row - elif table_type == "css": # CSS type table - all_rows = WebDriverWait(table, WebDriver_Wait).until( - EC.presence_of_all_elements_located((By.XPATH, "*")) - ) - for row_obj in all_rows: # For each row - if row_obj.is_displayed() != False: - # Get elements for each column - all_cols = WebDriverWait(row_obj, WebDriver_Wait).until( - EC.presence_of_all_elements_located((By.XPATH, "*")) - ) - break - - col_size = len(all_cols) - - CommonUtil.ExecLog(sModuleInfo, "Webpage table column size: %s" % col_size, 1) - CommonUtil.ExecLog( - sModuleInfo, "Expected table column size: %s" % expected_col, 1 - ) - - if int(col_size) != int(expected_col): - CommonUtil.ExecLog(sModuleInfo, "Column sizes don't match", 3) - return "zeuz_failed" - - CommonUtil.ExecLog(sModuleInfo, "Column sizes match", 1) - return "passed" - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info(), None) - - -@logger -def get_webpage_table_html(data_set, ignore_rows=[], ignore_cols=[], retain_case=True): - """ Find an HTML table given the elements, extract the text and return as a dictionary containing lists holding the data """ - # data_set: Contains user defined identifiers used to get the element of table - # ignore_rows: List containing rows to ignore - # ignore_cols: List containing columns to ignore - # retain_case: Set to true to keep data exactly as is. Set to false to set it to lower case which is useful for case insensitive matching - - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - # Get element representing entire table - table = LocateElement.Get_Element(data_set, selenium_driver) - if table in failed_tag_list: - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your element with given data.", 3 - ) - return "zeuz_failed" - - master_text_table = {} - table_row = 0 - tr_list = table.find_elements("tag name", "tr") # Get element list for all rows - for tr in tr_list: # For each row element - table_row += 1 - table_col = 0 - td_list = tr.find_elements("tag name", - "td" - ) # Get element list for all columns in this row - if ( - len(td_list) == 0 - ): # No type columns, so check if there were header type columns, and use those instead - td_list = tr.find_elements("tag name", - "th" - ) # Get element list for all header columns in this row - for td in td_list: # For each column element - table_col += 1 - value = str( - td.text - ).strip() # Save the text from this cell (also removing any HTML tags that may be in it) - if retain_case == False: - value = value.lower() # change cell text to lower case - master_text_table[ - "%s,%s" % (table_row, table_col) - ] = value # Put value from cell in dictionary - - return master_text_table # Return table text as dictionary - except Exception: - return CommonUtil.Exception_Handler( - sys.exc_info(), None, "Error while parsing the table" - ) - - -@logger -def get_webpage_table_css(data_set, ignore_rows=[], ignore_cols=[], retain_case=True): - """ Find a CSS table given the elements, extract the text and return as a dictionary containing lists holding the data """ - # data_set: Contains user defined identifiers used to get the element of table - # ignore_rows: List containing rows to ignore - # ignore_cols: List containing columns to ignore - # retain_case: Set to true to keep data exactly as is. Set to false to set it to lower case which is useful for case insensitive matching - - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - # Get element representing entire table - table = LocateElement.Get_Element(data_set, selenium_driver) - if table in failed_tag_list: - CommonUtil.ExecLog( - sModuleInfo, "Unable to locate your element with given data.", 3 - ) - return "zeuz_failed" - - # Get element for all rows - all_rows = WebDriverWait(table, WebDriver_Wait).until( - EC.presence_of_all_elements_located((By.XPATH, "*")) - ) - - master_text_table = {} - table_row = 0 - for row_obj in all_rows: # For each row - table_row += 1 - if row_obj.is_displayed() != False: - if table_row not in ignore_rows: # Skip rows the user wants to ignore - try: - # Get elements for each column - col_element = WebDriverWait(row_obj, WebDriver_Wait).until( - EC.presence_of_all_elements_located((By.XPATH, "*")) - ) - - table_col = 0 - for column_obj in col_element: # For each column on the row - table_col += 1 - if ( - table_col not in ignore_cols - ): # Skip columns the user wants to ignore - value = str( - column_obj.text - ).strip() # Save the text from this cell (also removing any HTML tags that may be in it) - if retain_case == False: - value = ( - value.lower() - ) # change cell text to lower case - master_text_table[ - "%s,%s" % (table_row, table_col) - ] = value # Put value from cell in dictionary - - except: # This will crash for single column tables or lists - table_col = 1 # Likely only one column - value = str( - row_obj.text - ).strip() # Save the text from this cell (also removing any HTML tags that may be in it) - if retain_case == False: - value = value.lower() # change cell text to lower case - master_text_table[ - "%s,%s" % (table_row, table_col) - ] = value # Put value from cell in dictionary - - return master_text_table # Return table text as dictionary - except Exception: - return CommonUtil.Exception_Handler( - sys.exc_info(), None, "Error while parsing the table" - ) - - @logger def Tear_Down_Selenium(step_data=[]): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME @@ -4153,69 +3181,6 @@ def Get_Current_URL(step_data): return "passed" -##@Riz and @Sreejoy: More work is needed here. Please investigate further. -@logger -def Get_Plain_Text_Element(element_parameter, element_value, parent=False): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - if parent == False: - all_elements_with_text = selenium_driver.find_elements_by_xpath(".//*") - else: - all_elements_with_text = parent.find_elements_by_xpath(".//*") - - # Sequential logical flow - if element_parameter == "plain_text": - index = 0 - full_list = [] - for each in all_elements_with_text: - text_to_print = None - try: - text_to_print = each.text - except: - False - if text_to_print == element_value: - full_list.append(each) - break - index = index + 1 - return_element = full_list[len(full_list) - 1] - - elif element_parameter == "partial_plain_text": - index = 0 - full_list = [] - for each in all_elements_with_text: - text_to_print = None - try: - text_to_print = each.text - except: - False - if element_value in text_to_print: - full_list.append(each) - break - index = index + 1 - return_element = full_list[len(full_list) - 1] - - else: - CommonUtil.ExecLog( - sModuleInfo, - "Value invalid. Only 'plain_text', 'partial_plain_text' allowed", - 3, - ) - return "zeuz_failed" - - return return_element - - except Exception: - errMsg = "Could not get the element by plain text search" - return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) - - -@logger -def get_driver(): - global selenium_driver - return selenium_driver - - # Method to open a new tab @logger def open_new_tab(step_data): @@ -4234,88 +3199,6 @@ def open_new_tab(step_data): return CommonUtil.Exception_Handler(sys.exc_info()) -# Method to switch to a new tab -@deprecated -@logger -def switch_tab(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - CommonUtil.ExecLog(sModuleInfo, "Try our new action named 'Switch window/tab'", 2) - global selenium_driver - try: - tab = 1 - for each in step_data: - if each[1] == "action": - tab = int(str(each[2])) - - CommonUtil.ExecLog(sModuleInfo, "Switching to Tab %d in Browser" % tab, 1) - windows = selenium_driver.window_handles - selenium_driver.switch_to.window(windows[tab - 1]) - CommonUtil.ExecLog( - sModuleInfo, "Switched to Tab %s Successfully in Browser" % tab, 1 - ) - - return "passed" - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - -# Method to switch to a new tab -@deprecated -@logger -def switch_window(step_data): - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - CommonUtil.ExecLog(sModuleInfo, "Try our new action named 'Switch Window/Tab'", 2) - global selenium_driver - try: - switch_by_title_condition = False - switch_by_index_condition = False - for left, mid, right in step_data: - left = left.lower().strip() - if left == "window title": - switch_by_title = right - switch_by_title_condition = True - elif left == "window index": - switch_by_index = right.strip() - switch_by_index_condition = True - - if switch_by_title_condition: - all_windows = selenium_driver.window_handles - window_handles_found = False - for each in all_windows: - selenium_driver.switch_to.window(each) - if switch_by_title == (selenium_driver.title): - window_handles_found = True - CommonUtil.ExecLog(sModuleInfo, "switched your window", 1) - break - if window_handles_found == False: - CommonUtil.ExecLog(sModuleInfo, "unable to find your given title among the windows", 3) - return False - else: - return True - - elif switch_by_index_condition: - check_if_index = ["0", "1", "2", "3", "4", "5"] - if switch_by_index in check_if_index: - window_index = int(switch_by_index) - window_to_switch = selenium_driver.window_handles[window_index] - selenium_driver.switch_to.window(window_to_switch) - return True - else: - CommonUtil.ExecLog( - sModuleInfo, - "Invalid index provided. Please provide number between 0 to 5", - 3, - ) - return False - else: - CommonUtil.ExecLog(sModuleInfo, "Wrong data set provided. Choose between window title or window index", 3) - return False - - except Exception: - CommonUtil.ExecLog(sModuleInfo, "unable to switch your window", 3) - return CommonUtil.Exception_Handler(sys.exc_info()) - - @logger def switch_window_or_tab(step_data): """ @@ -5033,34 +3916,6 @@ def playwright(dataset): return CommonUtil.Exception_Handler(sys.exc_info()) -@logger -def if_element_exists(data_set): - """ Click on an element """ - - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - variable_name = "" - value = "" - - for left, mid, right in data_set: - if "action" in mid: - value, variable_name = right.split("=") - value = value.strip() - variable_name = variable_name.strip() - - Element = LocateElement.Get_Element(data_set, selenium_driver) - if Element in failed_tag_list: - Shared_Resources.Set_Shared_Variables(variable_name, "false") - else: - Shared_Resources.Set_Shared_Variables(variable_name, value) - return "passed" - except Exception: - errMsg = ( - "Failed to parse data/locate element. Data format: variableName = value" - ) - return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) - @logger def check_uncheck_all(data_set): @@ -5221,44 +4076,6 @@ def insert(string, str_to_insert, index): -@logger -def slider_bar(data_set): - """Set certain value to a slider bar - you must provide a number between 0 - 100 - """ - - sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME - global selenium_driver - try: - value = "" - - for left, mid, right in data_set: - if "action" in mid: - value = int(right.strip()) - # if value not in range(0, 100): - # CommonUtil.ExecLog(sModuleInfo, "Failed to parse data/locate element. You must provide a number between 0-100", 3) - # return "zeuz_failed" - Element = LocateElement.Get_Element(data_set, selenium_driver) - if Element == "zeuz_failed": - CommonUtil.ExecLog(sModuleInfo, "Could not find the element", 3) - return "zeuz_failed" - else: - CommonUtil.ExecLog(sModuleInfo, f"Moving the slider by %{value} ", 1) - move = ActionChains(selenium_driver) - height_width = Element.size - ele_width = int((height_width)["width"]) - ele_height = int((height_width)["height"]) - x_cord_to_tap = ((value/100) * ele_width) - y_cord_to_tap = (ele_height/2) - - move.move_to_element_with_offset(Element, x_cord_to_tap, y_cord_to_tap).click().perform() - CommonUtil.ExecLog(sModuleInfo, f"Successfully set the slider to %{value}", 1) - - return "passed" - except Exception: - return CommonUtil.Exception_Handler(sys.exc_info()) - - @logger def multiple_check_uncheck(data_set): """ Check or uncheck multiple web elements """ @@ -5367,6 +4184,45 @@ def multiple_check_uncheck(data_set): return "passed" + +@logger +def slider_bar(data_set): + """Set certain value to a slider bar + you must provide a number between 0 - 100 + """ + + sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME + global selenium_driver + try: + value = "" + + for left, mid, right in data_set: + if "action" in mid: + value = int(right.strip()) + # if value not in range(0, 100): + # CommonUtil.ExecLog(sModuleInfo, "Failed to parse data/locate element. You must provide a number between 0-100", 3) + # return "zeuz_failed" + Element = LocateElement.Get_Element(data_set, selenium_driver) + if Element == "zeuz_failed": + CommonUtil.ExecLog(sModuleInfo, "Could not find the element", 3) + return "zeuz_failed" + else: + CommonUtil.ExecLog(sModuleInfo, f"Moving the slider by %{value} ", 1) + move = ActionChains(selenium_driver) + height_width = Element.size + ele_width = int((height_width)["width"]) + ele_height = int((height_width)["height"]) + x_cord_to_tap = ((value/100) * ele_width) + y_cord_to_tap = (ele_height/2) + + move.move_to_element_with_offset(Element, x_cord_to_tap, y_cord_to_tap).click().perform() + CommonUtil.ExecLog(sModuleInfo, f"Successfully set the slider to %{value}", 1) + + return "passed" + except Exception: + return CommonUtil.Exception_Handler(sys.exc_info()) + + @logger def resize_window(step_data): """Action to resize window size""" @@ -5399,10 +4255,3 @@ def resize_window(step_data): except Exception: return CommonUtil.Exception_Handler(sys.exc_info(), None, "Error resizing window") - - - - - - -