Example #1
0
    def run(self):
        """
        run tester to capture logcat, start App TestRunner instance, get launch time, filter exceptions in app log
        and generate test report

        @return: number of failed testcases
        @rtype: integer
        """
        self.__reset()
        self.start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))

        # 2014-07-22, capture logcat in ASYNC mode
        printLog("Start capture adb logcat ...")
        # redirect to local drive would generate error: /system/bin/sh: can't create logcat.log: Read-only file system
        # using the android file system path would solve the problem
        # child = Popen(['adb', 'logcat', '>', '/data/data/%s' % ADBLOG_FILE])
        child = Popen("adb logcat 2>&1 > %s" % ADBLOG_FILE, shell=True)
        # truncate file after 3 seconds to get rid of old logs
        time.sleep(3)
        self.shell.truncate_file(ADBLOG_FILE)
        try:
            tr = AppTestRunner(self.test_buildnum, self.testPool, self.device)
            tr.run()
        except (AssertionError, EnvironmentError), e:
            printLog("Failed to initialize test runner {}: \n{}".format(self.device.deviceId, e.message), logging.ERROR)
            return -1
Example #2
0
 def getBuild(self):
     """
     sample implementation:
     get build file from build server and place it in the directory specified in AppTestRunner.installApp(), which is
     path.join(LOCAL_BUILD_ROOT_PATH, APP_VERSION, "{}-{}.apk".format(PRODUCT_SHORT_NAME, buildnum))
     @return: result (boolean)
     """
     result = False
     if self.test_buildnum < 0:
         return True
     if self.test_buildnum == 0:
         self.test_buildnum = AppTestRunner.getLatestBuildNumber()
         if self.test_buildnum == 0:
             printLog('[getBuild] invalid build number specified or build location not accessible.', logging.ERROR)
             return result
     local_target = path.join(LOCAL_BUILD_ROOT_PATH, APP_VERSION,
                              "{}-{}.apk".format(PRODUCT_SHORT_NAME, self.test_buildnum))
     if not path.isfile(local_target):
         # the build file is not found locally, download it from remote build server
         remote_target = path.join(BUILD_ROOT_PATH, APP_VERSION, PRODUCT_NAME + '-' + str(self.test_buildnum), BUILD_FILENAME)
         printLog('[getBuild] Downloading build %s from %s...' % (str(self.test_buildnum), remote_target), logging.INFO)
         try:
             Shell().runShellCmd('cp {} {}'.format(remote_target, local_target))
             if path.isfile(local_target):
                 printLog('[getBuild] Build %s is downloaded.' % str(self.test_buildnum), logging.INFO)
                 result = True
         except IOError, e:
             printLog('[getBuild] Build %s download failed: %s' % e.message, logging.ERROR)
Example #3
0
 def run(self, tc_file_path):
     tr = AppTestRunner(10, TestCasePool.factory([TestCase.fromFile(tc_file_path)]), TestDevice(self.serial_no))
     tr.run()