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_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 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)
Exemplo n.º 4
0
def sequential_actions(
    dependency,
    run_time_params,
    step_data,
    test_action_info,
    file_attachment,
    temp_q,
    screen_capture,
    device_info,
    debug_actions=None,
):
    try:
        sTestStepReturnStatus = sa.Sequential_Actions(
            step_data,
            test_action_info,
            dependency,
            run_time_params,
            temp_q,
            screen_capture,
            device_info,
            debug_actions,
        )
        return CommonUtil.Result_Analyzer(sTestStepReturnStatus, temp_q)
    except Exception:
        return CommonUtil.Exception_Handler(sys.exc_info(), temp_q)
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_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 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())
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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())
Exemplo n.º 10
0
def view_info_about_colligo(
    dependency, run_time_params, step_data, file_attachment, temp_q, screen_capture
):
    try:
        sTestStepReturnStatus = NETAutomation.view_info_about_colligo(step_data)
        return CommonUtil.Result_Analyzer(sTestStepReturnStatus, temp_q)
    except Exception:
        return CommonUtil.Exception_Handler(sys.exc_info(), temp_q)
Exemplo n.º 11
0
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 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 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)
Exemplo n.º 14
0
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_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)
Exemplo n.º 16
0
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())
def get_list_udid():
    """ Returns a list of UDID's for connected IOS devices """

    sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
    CommonUtil.ExecLog(sModuleInfo, "Started", 0)
    try:
        cmd = "idevice_id -l"
        output = run_program(cmd)
        if output == None:
            return ""
        output = output.strip().split("\n")
        return output
    except Exception:
        return CommonUtil.Exception_Handler(sys.exc_info())
def Enter_Password_UIAutomator(password, serial=""):
    """ This function can evolve a lot more. For time being we are just looking for button with text and clicking for UNLOCKING only"""

    sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
    try:

        # click buttons
        if serial != "":  # Prepare serial number with command line switch
            from uiautomator import (
                Device,
            )  # putting it here for now as this module was missing before.  We can move it at the top after some time

            d = Device(serial)
            serial_with_id = "-s %s" % serial
        else:
            from uiautomator import device as d

            serial_with_id = ""

        button_list = list(password)

        subprocess.check_output(
            "adb %s shell input keyevent 82" % (serial_with_id),
            shell=True,
            encoding="utf-8",
        )  # Wakeup device
        time.sleep(0.5)
        subprocess.check_output(
            "adb %s shell input keyevent 82" % (serial_with_id),
            shell=True,
            encoding="utf-8",
        )  # Get to Unlock window
        time.sleep(0.5)

        for each_button in button_list:

            d(text=each_button).click()

        subprocess.check_output(
            "adb %s shell input keyevent KEYCODE_ENTER" % serial_with_id,
            shell=True,
            encoding="utf-8",
        )  # Press ENTER key.  Note all phones do not require
        CommonUtil.ExecLog(sModuleInfo, "Successfully entered your password",
                           1)
        return "passed"

    except Exception:
        errMsg = "Unable to unlock device"
        return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def get_device_wifi_info(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 dumpsys wifi" % serial,
                                         shell=True,
                                         encoding="utf-8")
        CommonUtil.ExecLog(sModuleInfo, "%s" % output, 0)
        return output

    except Exception:
        errMsg = "Unable to get device wifi info"
        return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def get_android_sdk(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 getprop ro.build.version.sdk" % serial,
            shell=True,
            encoding="utf-8",
        )
        CommonUtil.ExecLog(sModuleInfo, "%s" % output, 0)
        return output

    except Exception:
        errMsg = "Unable to get android sdk"
        return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
def take_screenshot(UDID=""):
    """ Captures a screenshot of the device, and returns the filename """

    sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
    CommonUtil.ExecLog(sModuleInfo, "Started", 0)
    try:
        cmd = "idevicescreenshot"
        if UDID != "":
            cmd + " -u" + UDID  # User specified id, so append that to the command
        output = run_program(cmd)
        if output == None:
            return ""
        output = output.split(" ")[3]  # Get just the filename
        return output
    except Exception:
        return CommonUtil.Exception_Handler(sys.exc_info())
def ios_shutdown(UDID=""):
    """ Turns off the device """

    sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
    CommonUtil.ExecLog(sModuleInfo, "Started", 0)
    try:
        cmd = "idevicediagnostics shutdown"
        if UDID != "":
            cmd + " -u" + UDID  # User specified id, so append that to the command
        output = run_program(cmd)
        if output == None:
            return ""
        output = output.split(" ")[3]  # Get just the filename
        return output
    except Exception:
        return CommonUtil.Exception_Handler(sys.exc_info())
Exemplo n.º 23
0
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 []
Exemplo n.º 24
0
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 []
Exemplo n.º 25
0
def Bypass():
    while True:
        user_info_object = {'project': 'zeuz', 'team': 'zeuz'}
        oLocalInfo = CommonUtil.MachineInfo()
        testerid = (oLocalInfo.getLocalUser()).lower()
        print("[Bypass] Zeuz Node is online: %s" % testerid)
        RunProcess(testerid, user_info_object)
def reset_android(serial=""):
    """ Resets the specified device, or the only device connected """

    sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
    try:
        CommonUtil.ExecLog(sModuleInfo, "Resetting device %s" % serial, 0)
        if serial != "":
            serial = (
                "-s %s" % serial
            )  # Prepend the command line switch to add the serial number
        subprocess.check_output("adb %s reboot" % serial,
                                shell=True,
                                encoding="utf-8")  # Send reset
    except Exception:
        return CommonUtil.Exception_Handler(sys.exc_info(), None,
                                            "Error while resetting device")
def get_device_info(UDID=""):
    """ Returns list of device information """

    sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
    CommonUtil.ExecLog(sModuleInfo, "Started", 0)
    try:
        cmd = "ideviceinfo"
        if UDID != "":
            cmd + " -u" + UDID  # User specified id, so append that to the command
        output = run_program(cmd)
        if output == None:
            return ""
        output = output.strip().split("\n")
        return output
    except Exception:
        return CommonUtil.Exception_Handler(sys.exc_info())
def take_screenshot(image_name, 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 shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > %s/%s.png"%(folder_path,image_name), shell=True)
        os.system("adb %s shell screencap -p /sdcard/%s.png" %
                  (serial, image_name))
        os.system("adb %s pull /sdcard/%s.png" % (serial, image_name))
        CommonUtil.ExecLog(sModuleInfo,
                           "Screenshot taken as %s.png" % image_name, 0)
        return "Screen shot taken"

    except Exception:
        errMsg = "Unable to take screenshot"
        return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
Exemplo n.º 29
0
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 install_app(apk_path, 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 install -r %s" %
                                         (serial, apk_path),
                                         shell=True,
                                         encoding="utf-8")
        CommonUtil.ExecLog(sModuleInfo, "Installed app located %s" % apk_path,
                           0)
        return output

    except Exception:
        errMsg = "Unable to install app located %s" % apk_path
        return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)