def setUp(self): fuhuTest.TrackingTestCase.setUp(self) if not os.path.exists(FILE + '/log/'): os.mkdir(FILE + '/log/') self.csvfile = open(FILE + '/log/' + self._serialno + '_' + self._test_time + '_' + self.id().split('_')[-1] + '.csv', 'a') self.writer = csv.writer(self.csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) # start monitor self.monitor = LogcatMonitor(self.logcatCallback, self.id().split('_')[-1], self._test_time, self._serialno, FILE) self.monitor.start()
class Test(fuhuTest.TrackingTestCase): semaphore = threading.BoundedSemaphore() errorLaunchRE = re.compile('errorCodeStr = A002') isLaunched = False def logcatCallback(self, line): fuhuTest.TrackingTestCase.logcatCallback(self, line) errorLaunchMatch = self.errorLaunchRE.search(line) if errorLaunchMatch is not None: self.isLaunched = False def setUp(self): fuhuTest.TrackingTestCase.setUp(self) if not os.path.exists(FILE + '/log/'): os.mkdir(FILE + '/log/') self.csvfile = open(FILE + '/log/' + self._serialno + '_' + self._test_time + '_' + self.id().split('_')[-1] + '.csv', 'a') self.writer = csv.writer(self.csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) # start monitor self.monitor = LogcatMonitor(self.logcatCallback, self.id().split('_')[-1], self._test_time, self._serialno, FILE) self.monitor.start() def tearDown(self): fuhuTest.TrackingTestCase.tearDown(self) self.csvfile.close() self.monitor.stop() def launchApp(self): cmd = ['adb', 'shell', 'monkey', '-p'] cmd.extend([self._package, '1']) call(cmd) def isTop(self): output = self.cmd.shell(['dumpsys', 'activity', 'a', '|', 'grep', 'Recent #0'], True, self._serialno) m = re.search('A=(?P<top_package>[\w.]+)', output) if m is not None: print m.group('top_package') + ' ==== ' + self._package if m.group('top_package') == self._package: print 'Yes on TOP' return True return False def startAppTest(self,): print 'startAppTest' cmd = ['monkey', '-p', self._package] cmd.extend(['--pct-touch', '80']) cmd.extend(['--pct-motion', '20']) cmd.extend(['--throttle', str(THROTTLE)]) cmd.extend(['-v', str(TIME)]) return self.cmd.shell(cmd, True, self._serialno) def test_MonkeyClick(self): # path = fuhuTest.getCurrentDir() + '/log/test_video' # if not os.path.exists(path): os.makedirs(path) # alreadyTest = [] # if os.path.exists(fuhuTest.getCurrentDir()+'/log/already_test_list'): # with open(fuhuTest.getCurrentDir()+'/log/already_test_list','rt') as f: # for line in f: # alreadyTest.append(line.strip()) # print str(alreadyTest) self.writer.writerow(['APK', 'PACKAGE NAME', 'TEST RESULT', 'ERROR LOG', 'TOTAL LOG']) package = dict() if not os.path.exists(APK_PATH): os.mkdir(APK_PATH) for f in os.listdir(APK_PATH): if f.find('.apk') != -1: pre = time.time() realPath = APK_PATH + '/' + f p = Popen(['aapt', 'dump', 'badging' , realPath], env={'PATH': fuhuTest.getCurrentDir(__file__) + '/exec'}, stdout=PIPE) pack = re.findall('(?<=package:\sname=\')[\w.]+', p.stdout.readline())[0] p.terminate() package[pack] = realPath print f + ' => ' + str(os.stat(realPath).st_size / (1024 * 1024)) + ' MB, ' + str(int(time.time() - pre)) + ' sec.' print len(package) for name, path in package.iteritems(): try: while True: print self.installApp(path) print name self.forceStop = False self.exceptionLog = '' self.isLaunched = True self._package = name self.launchApp() self.vc.sleep(10) self.checkScreen(self._device) if not self.isLaunched: # self.writer.writerow([self._package, 'fail','** Launch Fail **']) print '** Launch Fail **' self.uninstallApp(name) self.cmd.shell(['pm', 'clear', 'com.fuhu.nabipass'], serialno=self._serialno) # self.vc.dump() # view = self.vc.findViewById('com.fuhu.nabipass:id/positive_button') # view.touch() else: report = self.startAppTest() if report.find('** Monkey aborted due to error.') != -1: error = [path.split('/')[-1], self._package, 'fail'] error.append(report[report.find('** Monkey'):]) error.append(report[report.find('// Short Msg:'):]) self.writer.writerow(error) print self._package + ' Crash!' elif report.find('No activities found to run') != -1: self.writer.writerow([path.split('/')[-1], self._package, 'N/A', 'No activities found to run']) else: if self.forceStop: self.writer.writerow([path.split('/')[-1], self._package, 'fail', self.exceptionLog]) else: self.writer.writerow([path.split('/')[-1], self._package, 'pass']) break finally: # call(['adb', 'shell', 'rm', 'sdcard/test_video/*']) self.uninstallApp(name) self.csvfile.flush()
class Test(fuhuTest.TrackingTestCase): def logcatCallback(self, line): fuhuTest.TrackingTestCase.logcatCallback(self, line) # print line def setUp(self): fuhuTest.TrackingTestCase.setUp(self) if not os.path.exists(FILE + '/log/'): os.mkdir(FILE + '/log/') self.csvfile = open(FILE + '/log/' + self._serialno + '_' + self._test_time + '_' + self.id().split('_')[-1] + '.csv', 'a') self.writer = csv.writer(self.csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) # start monitor self.monitor = LogcatMonitor(self.logcatCallback, self.id().split('_')[-1], self._test_time, self._serialno, FILE) self.monitor.start() def tearDown(self): fuhuTest.TrackingTestCase.tearDown(self) self.csvfile.close() self.monitor.stop() def test_MonkeyClick(self): if len(str(PACKAGES).strip('[]\'')) == 0: packages = self.getPackages('-3','fuhu') else: packages = PACKAGES self.writer.writerow(['NAME', 'TEST RESULT', 'ERROR LOG','TOTAL LOG']) for package in packages: try: self._package = package self._device.press('POWER') self.vc.sleep(2) while True: t = ScreenRecord(THROTTLE * TIME / 1000, self._package, self._device.display['orientation']) t.start() self.vc.sleep(1) if t.isRunning(): break self._device.wake() self._device.unlock() cmd =['adb','-s',self._serialno, 'shell','monkey','-p'] cmd.append(self._package) cmd.append('-c') cmd.append('android.intent.category.LAUNCHER') cmd.append('--pct-touch') cmd.append('80') cmd.append('--pct-motion') cmd.append('20') cmd.append('--throttle') cmd.append(str(THROTTLE)) cmd.append('--randomize-throttle') cmd.append('-v') cmd.append(str(TIME)) report = check_output(cmd) print report if report.find('CRASH: ' + self._package) != -1: self.writer.writerow([self._package, 'fail', report[report.find('// CRASH:'):report.find('** Monkey aborted due to error.')],report]) print self._package + ' Crash!' elif report.find('No activities found to run') != -1: self.writer.writerow([self._package, 'N/A', 'No activities found to run']) t.stop() else: self.writer.writerow([self._package, 'pass']) finally: call(['adb', 'shell', 'pm', 'clear', self._package]) t.stop() while t.isRunning(): self.vc.sleep(1) call(['mkdir', FILE + '/log/test_video']) call(['adb', '-s', self._serialno, 'pull', 'sdcard/test_video', FILE + '/log/test_video']) call(['adb','-s', self._serialno ,'shell', 'rm', '-R', 'sdcard/test_video'])