Exemplo n.º 1
0
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 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 unlock_android(serial=""):
    """ Attempt to enter password for locked phone """
    # Caveat 1: Only works if device has PIN or PASSWORD, not if they use a pattern, or pattern as a fingerprint backup
    # Caveat 2: Only works if the user connects USB and unlocks the phone. Then, if the phone is locked, we still have an ADB connection, and can work with it.

    sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
    try:
        lock_status = ""
        if serial != "":
            serial_with_id = "-s %s" % serial
        subprocess.check_output(
            "adb %s shell svc power stayon usb" % (serial_with_id),
            shell=True,
            encoding="utf-8",
        )  # Wakeup device
        lock_status = check_if_device_is_unlocked(serial="")
        if lock_status == True:
            CommonUtil.ExecLog(
                sModuleInfo, "Device is already unlocked. No action is needed",
                1)
            return "passed"

        # 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
        # Unlock phone

        CommonUtil.ExecLog(sModuleInfo, "Attempting to unlock using adb", 1)
        subprocess.check_output(
            "adb %s shell svc power stayon usb" % (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",
        )  # Wakeup device
        time.sleep(0.5)
        subprocess.check_output(
            "adb %s shell input keyevent 82" % (serial_with_id),
            shell=True,
            encoding="utf-8",
        )  # Wakeup device
        time.sleep(0.5)
        CommonUtil.ExecLog(
            sModuleInfo,
            "Serial number of the device used - %s" % serial_with_id, 1)
        subprocess.check_output(
            "adb %s shell input text %s" % (serial_with_id, password),
            shell=True,
            encoding="utf-8",
        )  # Enter password
        time.sleep(0.5)
        subprocess.check_output(
            "adb %s shell input keyevent KEYCODE_ENTER" % serial_with_id,
            shell=True,
            encoding="utf-8",
        )  # Press ENTER key
        time.sleep(
            2)  # Give time for foreground to switch and unlock to complete

        # Unlock phone

        lock_status = check_if_device_is_unlocked(serial)
        if lock_status == True:
            CommonUtil.ExecLog(sModuleInfo,
                               "Successfully unlocked your device", 1)
            return "passed"
        else:
            CommonUtil.ExecLog(
                sModuleInfo,
                "We could not unlock using adb, we will try with uiautomator",
                1,
            )
            Enter_Password_UIAutomator(password, serial)

            lock_status = check_if_device_is_unlocked(serial)
            if lock_status == True:
                CommonUtil.ExecLog(sModuleInfo,
                                   "Successfully unlocked your device", 1)
                return "passed"

            CommonUtil.ExecLog(sModuleInfo, "We could not unlock your device",
                               3)
            return "zeuz_failed"

    except Exception:
        errMsg = "Unable to unlock device"
        return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
Exemplo n.º 4
0
#########################
#                       #
#    Global Variables   #
#                       #
#########################

MODULE_NAME = inspect.getmodulename(__file__)

# Valid image positions
positions = ("left", "right", "centre", "center")

# Recall dependency, if not already set
dependency = None
if Shared_Resources.Test_Shared_Variables(
        "dependency"):  # Check if driver is already set in shared variables
    dependency = Shared_Resources.Get_Shared_Variables(
        "dependency")  # Retreive appium driver
else:
    raise ValueError("No dependency set - Cannot run")

# Recall file attachment, if not already set
file_attachment = []
if Shared_Resources.Test_Shared_Variables("file_attachment"):
    file_attachment = Shared_Resources.Get_Shared_Variables("file_attachment")

#########################
#                       #
#   Helper Functions    #
#                       #
#########################