def collectLogcat(self,filePath): cmd = "logcat" logcatContent = command.executeCommandOnDevice(cmd) if logcatContent is not None: self.writeToFile(filePath,logcatContent,'w') else: print("logcat is not collected properly")
def collectDmesgLogs(self,filePath): cmd = "shell dmesg" fileContent = command.executeCommandOnDevice(cmd) if fileContent is not None: self.writeToFile(filePath,fileContent) else: print("dmesg log is not collected properly")
def getDeviceID(self): deviceId = None cmd = "devices" output = command.executeCommandOnDevice(cmd) if output is not None: for line in output.splitlines(): reObj = re.search(r'(\w+).*device\b', line) if reObj: deviceId = reObj.group(1).strip() return deviceId
def getDeviceProperty(self,property): cmd = "shell getprop" output = command.executeCommandOnDevice(cmd) if output is not None: lines = output.splitlines() for line in lines: if property in line: (key,value) = line.split(':') patternObj = re.search(r'\[(.*)\]',value) if patternObj: return patternObj.group(1) else: print("property is not found in getprop list") return None
def deleteResourceFromDevice(self,resourcePath): cmd = "shell rm -rf {}".format(resourcePath) command.executeCommandOnDevice(cmd)
def doesResourceExists(self, filePath): cmd = "ls {}".format(filePath) output = command.executeCommandOnDevice(cmd) if 'No such file or directory' in output: return False return True
def unInstallApp(self, packageName): cmd = "uninstall {}".format(packageName) command.executeCommandOnDevice(cmd)
def installApp(self,apkPath): cmd = "install -r -g {}".format(apkPath) command.executeCommandOnDevice(cmd)
def reboot(self): cmd = "reboot" command.executeCommandOnDevice(cmd)
def pullFiles(self,source,destination): if self.doesResourceExists(source): cmd = "pull {} {}".format(source,destination) command.executeCommandOnDevice(cmd) else: print("Resource doesn't exists on the device, Hence pulling failed")
def pushFiles(self,source,destination): cmd = "push {} {}".format(source,destination) command.executeCommandOnDevice(cmd)
def remount(self): cmd = "remount" command.executeCommandOnDevice(cmd)
def getInstalledApps(self): cmd = "shell pm list packages" packageList = command.executeCommandOnDevice(cmd) if packageList is not None: return packageList
def scrollDown(self,speed=60): x1, y1 = self.getCoOrdinates(50, 25) x2, y2 = self.getCoOrdinates(50, 75) cmd = "shell input touchscreen swipe {} {} {} {} {}".format(x1,y1,x2,y2,speed) command.executeCommandOnDevice(cmd)
def captureScreenshot(self,imageFileName): imageFilePath = "/scard/{}".format(imageFileName) cmd = "shell screencap -p {}".format(imageFilePath) command.executeCommandOnDevice(cmd)
def startCollectLogcat(self, filePath): cmd = "logcat -c" command.executeCommandOnDevice(cmd) logcatPid = self.collectLogcat(filePath) if logcatPid is not None: return logcatPid