@author: jerrychen ''' import fuhuTest import threading import os import re import csv import signal import time from subprocess import call, Popen, PIPE from FuhuTestModule import LogcatMonitor THROTTLE = 200 TIME = 350 FILE = fuhuTest.getCurrentDir(__file__) APK_PATH = FILE + '/APKVerificationTool' class ScreenRecord(threading.Thread): def __init__(self, timelimit, name, orientation): threading.Thread.__init__(self) call(['adb', 'shell', 'mkdir', 'sdcard/test_video']) self.p = False if orientation == '0': self.proc = Popen(['adb', 'shell', 'screenrecord', '--rotate', '--bit-rate', '1000000', '--time-limit', '180', 'sdcard/test_video/' + name + '.mp4'] , stdout=PIPE, stderr=PIPE) else: self.proc = Popen(['adb', 'shell', 'screenrecord', '--bit-rate', '1000000', '--time-limit', '180', 'sdcard/test_video/' + name + '.mp4'] , stdout=PIPE, stderr=PIPE) self.pid = self.proc.pid
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()
@author: jerrychen ''' import fuhuTest import threading import os import re import csv import signal from subprocess import call, Popen, PIPE, check_output from FuhuTestModule import LogcatMonitor PACKAGES = [] THROTTLE = 200 TIME = 700 FILE = fuhuTest.getCurrentDir(__file__) class ScreenRecord(threading.Thread): def __init__(self, timelimit, name, orientation): threading.Thread.__init__(self) call(['adb', 'shell', 'mkdir', 'sdcard/test_video']) self.p = False if orientation == '0': self.proc = Popen(['adb', 'shell', 'screenrecord', '--rotate', '--bit-rate', '1000000', '--time-limit', '180', 'sdcard/test_video/' + name + '.mp4'] , stdout=PIPE, stderr=PIPE) else: self.proc = Popen(['adb', 'shell', 'screenrecord', '--bit-rate', '1000000', '--time-limit', '180', 'sdcard/test_video/' + name + '.mp4'] , stdout=PIPE, stderr=PIPE) self.pid = self.proc.pid def stop(self):