def _runTestcase(self, *args, **kwds): try: deviceInfo = args[0]['deviceInfo'] testcase = args[0]['testcase'] testcase.testcaseResult.deviceInfo = json.dumps(deviceInfo.toDict()) TestcaseResultDao().insert(testcase.testcaseResult) uninstallCommand = "adb -s %s uninstall %s" % (deviceInfo.serial, testcase.package) TestcaseResultDao().update(testcase.testcaseResult, callCommand(uninstallCommand)) installCommand = "adb -s %s install %s" % (deviceInfo.serial, testcase.apkpath) TestcaseResultDao().update(testcase.testcaseResult, callCommand(installCommand)) for prepare in testcase.prepares: prepare = self._replaceMacro(prepare, deviceInfo, testcase); TestcaseResultDao().update(testcase.testcaseResult, callCommand(prepare)) for command in testcase.commands: command = self._replaceMacro(command, deviceInfo, testcase); TestcaseResultDao().update(testcase.testcaseResult, callCommand(command)) TestcaseResultDao().update(testcase.testcaseResult, callCommand("adb -s %s uninstall %s" % (deviceInfo.serial, testcase.package))) testcase.testcaseResult.isEnd = 1 testcase.testcaseResult.isSuccess = 1 TestcaseResultDao().update(testcase.testcaseResult) finally: DeviceManager().resetDevice(deviceInfo)
def refresh(self, isFirst=False): tempAvailableDeviceList = [] tempUnavailableDeviceList = [] tempProcessingDeviceList = [] try: self._lock.acquire() adb_dvc = callCommand("adb devices")[1:] for dvc_info in adb_dvc: try: dvc_info = dvc_info.strip() if not dvc_info: continue serial = dvc_info.split()[0] if dvc_info.split()[1] == 'device': if isFirst: DeviceUtils.unlockDevice(serial) if DeviceUtils.isDeviceLocked(serial): tempProcessingDeviceList.append(DeviceInfo(serial)) else: tempAvailableDeviceList.append(DeviceInfo(serial)) else: tempUnavailableDeviceList.append(DeviceInfo(serial, False)) except Exception, e: print e self._deviceInfoList.available_device_list = tempAvailableDeviceList self._deviceInfoList.unavailable_device_list = tempUnavailableDeviceList self._deviceInfoList.processing_device_list = tempProcessingDeviceList
def pullFileFromDevice(serial, source, target): callCommand('adb -s %s pull %s %s' % (serial, source, target))
def getMemoryParameterBySerial(serial): memory_result = callCommand('adb -s %s shell df | grep data' % serial)[0].strip().split() return memory_result[1], memory_result[3]
def getSimStateBySerial(serial): service_state = callCommand('adb -s %s shell dumpsys telephony.registry | grep mServiceState' % serial)[0].strip().split()[0].split('=')[1] return int(service_state) == 1;
def getResolutionBySerial(serial): resolution_cmd = 'adb -s %s shell dumpsys display | grep DisplayDeviceInfo' % serial rlt = callCommand(resolution_cmd)[0].strip() return rlt[rlt.find(':') + 1:rlt.find('}')].split(',')[0].strip()
def getEditionBySerial(serial): return callCommand('adb -s %s shell getprop ro.build.version.release' % serial)[0].strip()
def unlockDevice(serial): callCommand('adb -s %s shell rm %s' % (serial, DeviceUtils.processlock))
def isDeviceLocked(serial): processlock = DeviceUtils.processlock return callCommand('adb -s %s shell ls %s | grep %s' % (serial, processlock[0:processlock.rindex('/') + 1], processlock[processlock.rindex('/') + 1:]))
def pushFileToTargetPath(serial, source, target): callCommand('adb -s %s push %s %s' % (serial, source, target))
def lockDevice(serial): callCommand('adb -s %s shell touch %s' % (serial, DeviceUtils.processlock))
def getSimStateBySerial(serial): service_state = callCommand( 'adb -s %s shell dumpsys telephony.registry | grep mServiceState' % serial)[0].strip().split()[0].split('=')[1] return int(service_state) == 1
def getProductBySerial(serial): return callCommand("adb -s %s shell getprop ro.product.model" % serial)[0].strip()