Example #1
0
 def do_sleep(self, str_arg):
     """
     sleep for given seconds, can be float
     e.g. sleep 2.5
     @param str_arg: the time argument (string)
     """
     # printLog(self.threadName + "[running command 'sleep %s']" % str_arg)
     self.vc.sleep(float(validateDigit(str_arg)))
Example #2
0
 def do_changeDeviceTime(self, str_arg=""):
     """
     change device time
     usage: changeDeviceTime <min>
     e.g. changeDeviceTime 60  # adjust to 60 minutes later
     @param str_arg: time in minutes (string)
     """
     # self.resultFlag=change_phone_time(int(self.validateDigit(str_arg)), self.deviceId)
     cmd = "python {}/changePhoneTime.py {}".format(CORE_DIR, validateDigit(str_arg))
     print self.sh.getShellCmdOutput(cmd)
Example #3
0
 def do_freshInstallApp(self, str_arg=""):
     """
     remove and install app with the specified build number(optional).
     @param str_arg: the build number (optional)
     """
     if len(str_arg) > 0:
         buildnum = validateDigit(str_arg)
     else:
         buildnum = self.test_buildnum
     self.do_removeApp()
     self.do_sleep("1")
     self.do_installApp(buildnum)
Example #4
0
 def do_testMonkeyTest(self, str_arg):
     """
     run Monkey test for the given count times (default is 500)
     e.g. testMonkeyTest 5000
     @param str_arg: count times
     """
     if len(str_arg) == 0:
         count = 500
     else:
         count = validateDigit(str_arg)
     printLog(self.threadName + "run monkey test.")
     self.resultFlag = self.runMonkeyTest(APP_PKG_NAME, count)
     return self.resultFlag
Example #5
0
 def do_installApp(self, str_arg=""):
     """
     sample implementation: install app with the specified build number(optional) on device
     @param str_arg: the build number (optional)
     @return: result (boolean)
     """
     if len(str_arg) > 0:
         buildnum = validateDigit(str_arg)
     else:
         buildnum = self.test_buildnum
     target = path.join(LOCAL_BUILD_ROOT_PATH, APP_VERSION, "{}-{}.apk".format(PRODUCT_SHORT_NAME, buildnum))
     if path.isfile(target):
         self.installApp(target)
         return True
     else:
         printLog(self.threadName + "CANNOT ACCESS/FIND BUILD FILE at %s" % target, logging.ERROR)
         return False
Example #6
0
    def do_longpress(self, str_arg):
        """
        long press a UI element by view id, a point or text
        format: 1. longpress <view id> [seconds]
                2. longpress <parent view id>(child path) [seconds]
                3. longpress text/<target text> [seconds]
                4. longpress (100,200) [seconds]

        2015-08-27: add format2 support
        2014-02-17: initial version
        @param str_arg: auguments
        """
        arg = validateString(str_arg)
        # if arg.startswith(r'('):
        # raise ValueError('Bad argument, You may want to use longpress2 with coordinates as auguments.')
        x = 0
        y = 0
        seconds = 2000
        try:
            if arg.startswith(r'('):
                point, sec = arg.split(')')
                if len(sec) > 0:
                    seconds = int(validateDigit(sec))
                x, y = self.__getPointXY(point + ')')
                if not isinstance(x, int):
                    raise ValueError('bad x type: not int.')
            elif arg.startswith('id') or arg.startswith('text'):
                if ' ' in arg:
                    view_id, sec = arg.split(' ')
                    if len(sec) > 0:
                        seconds = int(validateDigit(sec.strip()))
                else:
                    view_id = arg
                # get the target view
                tv = self.__getView(view_id)
                if tv:
                    if DEBUG:
                        printLog('Found view %s.' % arg, logging.DEBUG)
                        print tv.__tinyStr__()
                        print tv.getPositionAndSize()
                    x, y = tv.getCenter()
                    if not isinstance(x, int):
                        raise ValueError('Bad center coordinate: not int.')
                else:
                    printLog('Target view %s not found.' % arg, logging.ERROR)
                    self.resultFlag = False
                    return
            else:
                raise ValueError('bad argument in longpress().')
            # perform long press
            if self.adbc.getSdkVersion() >= 19:
                printLog(self.threadName + "[running longTouch %s, %s...]" % (x, y))
                self.adbc.longTouch(x, y, seconds)

            # solution for API level > 17:
            # http://stackoverflow.com/questions/11142843/how-can-i-use-adb-to-send-a-longpress-key-event
            elif self.adbc.getSdkVersion() > 17:
                cmd = 'adb shell input touchscreen swipe %s %s %s %s %d' % (x, y, x, y, seconds)
                printLog(self.threadName + "[running cmd %s...]" % cmd)
                if call(cmd, shell=True) != 0:
                    printLog("LONGPRESS FAILED: Failed to execute command '%s'." % cmd, logging.ERROR)
                    self.resultFlag = False
            else:
                printLog("LONGPRESS FAILED: API < 18 is not supported yet.", logging.ERROR)
                self.resultFlag = False

        except Exception, e:
            printLog(self.threadName + 'LONGPRESS FAILED:%s' % e.message, logging.WARNING)
            traceback.print_exc()
            self.resultFlag = False
Example #7
0
 def do_interval(self, str_arg):
     """
     set sleep interval between each action
     """
     self.INTERVAL = float(validateDigit(str_arg))