def get_product_name(UDID=""): """ Reads the phone name """ sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME CommonUtil.ExecLog(sModuleInfo, "Started", 0) try: output = get_device_info(UDID) # Get device info in list format tmp = "" product_name = "" for line in output: if "productname" in line.lower(): tmp = line if tmp != "": tmp = tmp.split(":") product_name = tmp[1].strip() if product_name == "": CommonUtil.ExecLog( sModuleInfo, "Could not read the iOS product name the device", 3 ) return "zeuz_failed" CommonUtil.ExecLog(sModuleInfo, "%s" % product_name, 0) return product_name except Exception: return CommonUtil.Exception_Handler(sys.exc_info())
def get_devices(): """ Retrieves a list of connected devices in the format of "SERIAL_NO STATE" and returns as a list """ # State may be "device" if connected and we can talk to it, or "unauthorized" if we can't talk to it sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: # Get list of connected devices output = subprocess.check_output("adb devices", shell=True, encoding="utf-8") # Cleanup data output = output.replace("\r", "") output = output.replace("\t", " ") output = output.split("\n") output.pop(0) # Remove "list of..." string output = [ line for line in output if line != "" and "*" not in line ] # Probably better to look for two word line which only contains 'device', but this works for now # Return as list CommonUtil.ExecLog(sModuleInfo, "Connected devices: %s" % str(output), 0) return output except Exception: CommonUtil.ExecLog(sModuleInfo, "Unable to get devices", 3) return []
def get_ios_version(UDID=""): """ Reads the device version """ sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME CommonUtil.ExecLog(sModuleInfo, "Started", 0) try: output = get_device_info(UDID) # Get device info in list format tmp = "" version = "" for line in output: if "productversion" in line.lower(): tmp = line if tmp != "": tmp = tmp.split(":") version = tmp[1].strip() if version == "": CommonUtil.ExecLog( sModuleInfo, "Could not read the iOS version from the device", 3 ) return "zeuz_failed" CommonUtil.ExecLog(sModuleInfo, "%s" % version, 0) return version except Exception: return CommonUtil.Exception_Handler(sys.exc_info())
def check_tags_exist(filepath, tag, subtag): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: doc = ET.parse(filepath).getroot() for event in doc.findall(tag): if event is None: CommonUtil.ExecLog(sModuleInfo, "%s tag is not found." % tag, 3) else: CommonUtil.ExecLog(sModuleInfo, "%s tag is found." % tag, 1) for host in event.findall(subtag): if host is None: CommonUtil.ExecLog(sModuleInfo, "%s tag is not found." % subtag, 3) else: CommonUtil.ExecLog( sModuleInfo, "%s tag is found in %s." % (subtag, tag), 1) except Exception: errMsg = "%s - %s tag existence is not checked. " % (filepath, tag) return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def check_if_device_is_unlocked(serial=""): # if device is locked, current focused window always shows "StatusBar" only sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: if serial != "": serial = "-s %s" % serial # Prepare serial number with command line switch subprocess.check_output( "adb %s shell input keyevent 82" % (serial), shell=True, encoding="utf-8") # Wakeup device and bring it unlock window time.sleep(1) output = subprocess.check_output( "adb %s exec-out uiautomator dump /dev/tty" % serial, shell=True, encoding="utf-8", ) if "EMERGENCY" in output or "emergency_call_button" in output: CommonUtil.ExecLog( sModuleInfo, "Device is currently locked. We will proceed with unlock ", 2, ) return False else: CommonUtil.ExecLog(sModuleInfo, "Device is currently unlocked ", 1) return True except Exception: errMsg = "Unable to determine if device is locked or not" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def get_element_step_data(step_data): """ Function to collect user provided target and action elements from step data """ sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: file_path = False target_parameter = False target_value = False action_parameter = False action_value = False if len(step_data) >= 1: for each in step_data: if each[1] == "path": file_path = each[2] elif ((each[1] == "parent parameter") or (each[1] == "child parameter") or (each[1] == "element parameter")): continue elif each[1] == "target parameter": target_parameter = each[0] target_value = each[2] elif each[1] == "action": action_parameter = each[0] action_value = each[2] else: CommonUtil.ExecLog(sModuleInfo, "Unable to find elements requested.", 3) else: CommonUtil.ExecLog( sModuleInfo, "Data set incorrect. Please provide accurate data set(s) information.", 3, ) return "zeuz_failed" returned_data = ( file_path, target_parameter, target_value, action_parameter, action_value, ) return returned_data except Exception: errMsg = "Could not get element step data." return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def get_team_names(noerror=False): """ Retrieve all teams user has access to """ try: username = ConfigModule.get_config_value(AUTHENTICATION_TAG, USERNAME_TAG) password = ConfigModule.get_config_value(AUTHENTICATION_TAG, PASSWORD_TAG) if password == "YourUserNameGoesHere": password = password else: password = pass_decode("zeuz", password) user_info_object = {USERNAME_TAG: username, PASSWORD_TAG: password} if not check_server_online(): return [] r = RequestFormatter.Get("get_user_teams_api", user_info_object) teams = [x[0] for x in r] # Convert into a simple list return teams except: if noerror == False: CommonUtil.ExecLog("", "Error retrieving team names", 4, False) return []
def click_given_loc(loc): try: sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME app(u"ProductName").activate() x_position = loc[0] y_position = loc[1] print("moving to given position") os.system( "%s/MouseTools -x %s, -y %s" % (os.path.dirname(os.path.abspath(__file__)), x_position, y_position) ) print("execuing actual mouse left click") os.system("~/Desktop/MouseTools -leftClick") print("clicked it") print("sleeing for 1 second") time.sleep(1) print("execuing actual mouse left click") os.system("~/Desktop/MouseTools -leftClick") print("clicked it second time and now waiting for 1 second") time.sleep(1) except Exception as e: print("%s > Exception Happened (%s)" % (sModuleInfo, e)) CommonUtil.ExecLog(sModuleInfo, "Exception Happened (%s)" % e, 3) return False
def set_txt_value_by_keystroke(id_path, txt): try: sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME # set value with empty string # print("seting the value to empty") # os.system('~/Desktop/MouseTools -leftClick') print("calling set funcion to set the name to empty") set_txt_value(id_path, "") # os.system('~/Desktop/MouseTools -leftClick') # get and click location print("getting clickable location") text_field_locaion_to_click = get_clickable_location(id_path) print("found clicable locaiton") click_given_loc(text_field_locaion_to_click) time.sleep(1) # keystroke the value in print("about to type keystroke") keystroke(txt) print("done keysroking") return True except Exception as e: print("%s > Exception Happened (%s)" % (sModuleInfo, e)) CommonUtil.ExecLog(sModuleInfo, "Exception Happened (%s)" % e, 3) return False
def get_project_names(team): """ Retrieve projects for given team """ try: username = ConfigModule.get_config_value(AUTHENTICATION_TAG, USERNAME_TAG) password = ConfigModule.get_config_value(AUTHENTICATION_TAG, PASSWORD_TAG) if password == "YourUserNameGoesHere": password = password else: password = pass_decode("zeuz", password) user_info_object = { USERNAME_TAG: username, PASSWORD_TAG: password, TEAM_TAG: team, } if not check_server_online(): return [] r = RequestFormatter.Get("get_user_projects_api", user_info_object) projects = [x[0] for x in r] # Convert into a simple list return projects except: CommonUtil.ExecLog("", "Error retrieving project names", 4, False) return []
def validate_xml(filepath): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: f = StringIO("""\ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="a" type="AType"/> <xsd:complexType name="AType"> <xsd:sequence> <xsd:element name="b" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:schema> """) xmlschema_doc = etree.parse(f) xmlschema = etree.XMLSchema(xmlschema_doc) f = open(filepath) xml = f.read() f.close() valid = StringIO(xml) doc = etree.parse(valid) try: xmlschema.validate(doc) CommonUtil.ExecLog(sModuleInfo, "%s file is validated." % filepath, 1) except Exception: errMsg = "%s file is not validated." % filepath return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) except Exception: return CommonUtil.Exception_Handler(sys.exc_info())
def get_target_element(file_path, target_parameter, target_value, action_name, action_value, step_data): """ Function to get the target element(s) as per 'action' """ sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: file_tree = [] # Function to get the XML file tree file_tree = get_file_tree(file_path) driver = None driver = file_tree[0] # Function to get the elements from the XML file matching_elements = LE.Get_Element(step_data, driver) CommonUtil.ExecLog( sModuleInfo, ">>> The expected attribute value is: '%s'" % action_value, 1) # Function to update the target element returned_target_element = update_target_element( file_path, file_tree[1], matching_elements, target_parameter, target_value, action_name, action_value, ) return returned_target_element except Exception: return CommonUtil.Exception_Handler(sys.exc_info())
def check_exist(filepath): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: if os.path.isfile(filepath): CommonUtil.ExecLog(sModuleInfo, "%s file is found." % filepath, 1) return "Passed" else: CommonUtil.ExecLog(sModuleInfo, "%s file is not found." % filepath, 3) return "zeuz_failed" except Exception: errMsg = "%s file existence is not checked." % filepath return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def get_device_storage(serial=""): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: if serial != "": serial = "-s %s" % serial # Prepare serial number with command line switch output = subprocess.check_output("adb %s shell df /data" % serial, shell=True, encoding="utf-8") CommonUtil.ExecLog(sModuleInfo, "%s" % output, 0) storageList = " ".join(output.split()) storageList = storageList.split(" ") storage = storageList[6] storage = storage.replace("G", "") storage = float(storage) final_storage = 0 exp = 2 while True: gb = math.pow(2, exp) if storage < gb: final_storage = gb break exp += 1 final_storage = int(final_storage) return final_storage except Exception: errMsg = "Unableto get device storage" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def get_elem_with_role(obj_list, role_type): # there is a possiblity of having duplicate element so we need to build our list and send as list and not as obj try: sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME elem_with_role = [] for temp_obj in obj_list: try: role_name = get_role_of_element(temp_obj) # print("role of element is :") # print(role_name) # print(role_type) except: a = 1 if role_name == role_type: # print("matched") elem_with_role.append(temp_obj) # print(elem_with_role) else: a = 1 # print("didnt match") # print(elem_with_role) return elem_with_role except Exception as e: print("%s > Exception Happened (%s)" % (sModuleInfo, e)) CommonUtil.ExecLog(sModuleInfo, "Exception Happened (%s)" % e, 3) return False
def get_device_imei_info(serial=""): """ Returns the device's IMEI """ # Output: IMEI as a string sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: if serial != "": serial = "-s %s" % serial # Prepare serial number with command line switch output = subprocess.check_output("adb %s shell dumpsys iphonesubinfo" % serial, shell=True, encoding="utf-8") # Use dumpsys (Below Android v6) if output != "": output = output.split("\n")[2] output = output.split(" ")[5].strip() # Use service call (Above Android v6) else: output = subprocess.check_output( "adb shell service call iphonesubinfo 1" % serial, shell=True, encoding="utf-8", ) output = output.split( " " ) # Contains hex output, and characters that need to be removed tmp = "" for val in output: if "'" in val: tmp += val # Look for values that have a single quote, they are the ones with a portion of the IMEI chars = "\r\n.')" output = tmp.translate(None, chars) # Remove characters we don't want if len(output) != 14 and len(output) != 15: CommonUtil.ExecLog(sModuleInfo, "Could not read the IMEI from the device", 3) return "zeuz_failed" CommonUtil.ExecLog(sModuleInfo, "%s" % output, 0) return output except Exception: errMsg = "Error while trying to read IMEI from the device" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def playback_recorded_events(data_set): """Plays back the recorded events from a given file.""" sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME # Parse data set try: filepath = "" speed_factor = 1.0 for left, _, right in data_set: left = left.lower().strip() if "file path" in left: filepath = right.strip() filepath = CommonUtil.path_parser(filepath) elif "speed factor" in left: speed_factor = float(right.strip()) if filepath == "": CommonUtil.ExecLog( sModuleInfo, "A valid path to the recorded event file must be provided. If you've uploaded it into attachments with name `recording_1.zvt`," " you can use it by providing the path as `%|recording_1.zvt|%`", 3, ) return "zeuz_failed" except Exception: errMsg = "Error parsing data set" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) # Perform action try: CommonUtil.ExecLog(sModuleInfo, "Playing the events recorded in - %s" % filepath, 1) playback_chooser = ChoosePlaybackModule(filepath) playback_chooser.play(speed_factor=speed_factor) CommonUtil.ExecLog(sModuleInfo, "DONE playing back events.", 1) return "passed" except Exception: errMsg = "Failed to playback recorded events from file: %s" % filepath return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def check_for_element(data_set): """ Tests whether or not an element is visible on screen """ sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME # Parse data set try: file_name = "" for row in data_set: if row[1] == "element parameter": file_name = row[2] if file_name == "": CommonUtil.ExecLog( sModuleInfo, "Valid element not found. Expected Sub-Field to be 'element parameter', and Value to be a filename", 3, ) return "zeuz_failed" except Exception: errMsg = "Error parsing data set" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) # Perform action try: CommonUtil.ExecLog(sModuleInfo, "Performing check action on file %s" % (file_name), 0) element = LocateElement.Get_Element(data_set, gui) # (x, y, w, h) # CommonUtil.TakeScreenShot( # sModuleInfo # ) # Capture screenshot, if settings allow for it if element in failed_tag_list: CommonUtil.ExecLog(sModuleInfo, "Element not found", 3) return "zeuz_failed" else: CommonUtil.ExecLog(sModuleInfo, "Found element", 1) return "passed" except Exception: errMsg = "Error parsing data set" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def log_to_db(sModuleInfo, datasets, tag, status): CommonUtil.ExecLog(sModuleInfo, "%s Datasets: %d" % (tag, len(datasets)), status) for i, eachdataset in enumerate(datasets): CommonUtil.ExecLog(sModuleInfo, "%s Dataset: #%d" % (tag, (i + 1)), status) tuple_data = [] for eachitem in eachdataset: if isinstance(eachitem[1], str): tuple_data.append(eachitem) CommonUtil.ExecLog( sModuleInfo, "%s Tuple Data Entry Count: %d" % (tag, len(tuple_data)), status, ) for j, eachitem in enumerate(tuple_data): CommonUtil.ExecLog( sModuleInfo, "#%d : %s : %s" % ((j + 1), eachitem[0], eachitem[1]), status, ) for j, eachitem in enumerate(eachdataset): if isinstance(eachitem[1], list): CommonUtil.ExecLog( sModuleInfo, "%s Group Data Label: %s" % (tag, eachitem[0]), status ) CommonUtil.ExecLog( sModuleInfo, "%s Group Data Entry Count: %d" % (tag, len(eachitem[1])), status, ) for k, eachdata in enumerate(eachitem[1]): CommonUtil.ExecLog( sModuleInfo, "#%d : %s : %s" % ((k + 1), eachdata[0], eachdata[1]), status, )
def click_button( ElemId=None, ElemPath=None, ElemRole=None, ElemValue=None, ElemPosition=None ): try: sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME ElementName = [ Key for Key, Value in Global.Ids.items() if Value == ElemId or Value == ElemPath ] if ElemPath == None: element = Find_Element( elem_id=ElemId, elem_path=ElemPath, elem_role=ElemRole, elem_value=ElemValue, elem_position=ElemPosition, ) else: element = [ElemPath] if element != False: if element[0].enabled.get() == True: element[0].click() # print("%s > Button (%s) has been clicked" %(sModuleInfo,ElementName)) CommonUtil.ExecLog( sModuleInfo, "Button (%s) has been clicked" % ElementName, 1 ) return True else: # print("%s > Button (%s) was not enabled" %(sModuleInfo,ElementName)) CommonUtil.ExecLog( sModuleInfo, "Button (%s) was not enabled" % ElementName, 1 ) return False else: # print("%s > Button (%s) was not be found" %(sModuleInfo,ElementName)) CommonUtil.ExecLog( sModuleInfo, "Button (%s) was not be found" % ElementName, 1 ) return False except Exception as e: return CommonUtil.LogCriticalException(sModuleInfo, e)
def check_form(filepath): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: x = ET.fromstring(filepath) CommonUtil.ExecLog(sModuleInfo, "%s file is well-formed. %s" % filepath, 1) except Exception: errMsg = "%s file is not well-formed." % filepath return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def get_title_of_element(id_path): try: sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME title_of_ele = id_path.title.get() return True except Exception as e: print("%s > Exception Happened (%s)" % (sModuleInfo, e)) CommonUtil.ExecLog(sModuleInfo, "Exception Happened (%s)" % e, 3) return False
def set_txt_value(id_path, txt): try: sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME set_txt = id_path.value.set(txt) print("performed seting value to empty") return True except Exception as e: print("%s > Exception Happened (%s)" % (sModuleInfo, e)) CommonUtil.ExecLog(sModuleInfo, "Exception Happened (%s)" % e, 3) return False
def find_odbc_driver(db_type="postgresql"): """ Finds the ODBC driver to work with based on the given database type :param db_type: type of database (e.g postgres, mysql, etc.) :return: name of the driver (string) """ import pyodbc sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME db_type = db_type.lower() # Check to see if any ODBC driver is specified selected_driver = sr.Get_Shared_Variables(DB_ODBC_DRIVER, log=False) # If no ODBC driver is specified if selected_driver == "zeuz_failed": # Driver list for pyodbc to connect through the ODBC standard pyodbc_drivers = pyodbc.drivers() # Sort to get unicode items first pyodbc_drivers.sort(reverse=True, key=lambda x: "unicode" in x.lower()) for odbc_driver in pyodbc_drivers: odbc_driver_lowercase = odbc_driver.lower() if db_type == "postgresql": if ("postgre" in odbc_driver_lowercase and "unicode" in odbc_driver_lowercase): selected_driver = odbc_driver # We usually want the unicode drivers, so break once we've found it break elif ("postgre" in odbc_driver_lowercase and "ansi" in odbc_driver_lowercase): selected_driver = odbc_driver elif db_type == "mariadb": # mariadb has only one type of odbc driver if "mariadb" in odbc_driver_lowercase: selected_driver = odbc_driver break elif db_type == "mysql": if ("mysql" in odbc_driver_lowercase and "unicode" in odbc_driver_lowercase): selected_driver = odbc_driver # We usually want the unicode drivers, so break once we've found it break elif ("mysql" in odbc_driver_lowercase and "ansi" in odbc_driver_lowercase): selected_driver = odbc_driver CommonUtil.ExecLog(sModuleInfo, "[Database ODBC DRIVER]: %s" % selected_driver, 0) return selected_driver
def read_element(step_data): """ Function to read the elements from XML file """ sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: if len([step_data ]) != 1: # Verifies that length of step_data greater than one CommonUtil.ExecLog( sModuleInfo, "The information in the data-set(s) are incorrect. Please provide accurate data set(s) information.", 3, ) return "zeuz_failed" else: # Function to collect the user provided step data elements element_step_data = get_element_step_data(step_data) if (element_step_data == []) or (element_step_data in failed_tag_list): CommonUtil.ExecLog( sModuleInfo, "Unable to get the file path of: '%s'" % element_step_data[0], 3, ) return "zeuz_failed" else: # Function to get the XML file tree returned_element = get_file_tree(element_step_data[0]) CommonUtil.ExecLog(sModuleInfo, "File tree of: %s" % (element_step_data[0]), 1) CommonUtil.ExecLog(sModuleInfo, "%s" % ET.tostring(returned_element[0]), 1) return "Passed" except Exception: errMsg = "Unable to read the element(s)." return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def check_wellformed(filename): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME # filename = "/home/asci/AssetScience/recell_dse-in-test/Launcher/resource/configurations/desktop-fail-codes.xml" try: parser = make_parser() parser.setContentHandler(ContentHandler()) parser.parse(filename) CommonUtil.ExecLog(sModuleInfo, "%s is well-formed. %s" % filename, 1) except Exception: errMsg = "%s is NOT well-formed! " % filename return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def get_device_complete_info(): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: output = subprocess.check_output("adb devices -l", shell=True, encoding="utf-8") CommonUtil.ExecLog(sModuleInfo, "%s" % output, 0) return output except Exception: errMsg = "Unable to get device complete info" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def kill_adb_server(): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: output = subprocess.check_output("adb kill-server", shell=True, encoding="utf-8") CommonUtil.ExecLog(sModuleInfo, "Killing adb server", 0) return output except Exception: errMsg = "Unable to kill adb server" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def unlock_android_app(serial=""): """ Attempt to enter password for locked app. It is up to the user to put proper logic to figure out if the app is password protected. We will assume user have already checked that""" sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: # Get password if (sr.Test_Shared_Variables("device_password") == False ): # Make sure user stored password in shared variables CommonUtil.ExecLog(sModuleInfo, "Can't unlock phone - no password specified.", 3) return "zeuz_failed" password = sr.Get_Shared_Variables( "device_password") # Read device password from shared variables if serial != "": serial = "-s %s" % serial # Prepare serial number with command line switch # Unlock app subprocess.check_output("adb %s shell input keyevent 82" % (serial), shell=True, encoding="utf-8") # Wakeup device time.sleep(1) CommonUtil.ExecLog(sModuleInfo, "Serial number of the device used - %s" % serial, 1) subprocess.check_output( "adb %s shell input text %s" % (serial, password), shell=True, encoding="utf-8", ) # Enter password time.sleep(0.5) subprocess.check_output( "adb %s shell input keyevent KEYCODE_ENTER" % serial, shell=True, encoding="utf-8", ) # Press ENTER key time.sleep( 2) # Give time for foreground to switch and unlock to complete except Exception: errMsg = "Unable to unlock app" return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def connect_to_db(data_set): """ This action just stores the different database specific configs into shared variables for use by other actions. NOTE: The actual db connection does not happen here, connection to db is made inside the actions which require it. db_type input parameter <type of db, ex: postgres, mysql> db_name input parameter <name of db, ex: zeuz_db> db_user_id input parameter <user id of the os who have access to the db, ex: postgres> db_password input parameter <password of db, ex: mydbpass-mY1-t23z> db_host input parameter <host of db, ex: localhost, 127.0.0.1> db_port input parameter <port of db, ex: 5432 for postgres by default> sid optional parameter <sid of db, ex: 15321 for oracle by default> service_name optional parameter <service_name of db, ex: 'somename' for oracle by default> odbc_driver optional parameter <specify the odbc driver, optional, can be found from pyodbc.drivers()> connect to db database action Connect to a database :param data_set: Action data set :return: string: "passed" or "zeuz_failed" depending on the outcome """ sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME try: for left, _, right in data_set: if left == DB_TYPE: sr.Set_Shared_Variables(DB_TYPE, right) if left == DB_NAME: sr.Set_Shared_Variables(DB_NAME, right) if left == DB_USER_ID: sr.Set_Shared_Variables(DB_USER_ID, right) if left == DB_PASSWORD: sr.Set_Shared_Variables(DB_PASSWORD, right) if left == DB_HOST: sr.Set_Shared_Variables(DB_HOST, right) if left == DB_PORT: sr.Set_Shared_Variables(DB_PORT, right) if left == DB_SID: sr.Set_Shared_Variables(DB_SID, right) if left == DB_SERVICE_NAME: sr.Set_Shared_Variables(DB_SERVICE_NAME, right) if left == DB_ODBC_DRIVER: sr.Set_Shared_Variables(DB_ODBC_DRIVER, right) CommonUtil.ExecLog(sModuleInfo, "Trying to establish connection to the database.", 1) db_get_connection() return "passed" except Exception: traceback.print_exc() return CommonUtil.Exception_Handler(sys.exc_info())