How to use execute_adb_shell method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

PicClassfyUtil.py

Source:PicClassfyUtil.py Github

copy

Full Screen

...7import os8import shutil9from common import FilePathUtil, excel_util, Logger10from wxfriend import WxConfig11def execute_adb_shell(command, deviceId='98882048434756494f'):12 shell = f'adb -s {deviceId} {command}'13 exe_shell(shell)14def getImiDefault():15 shell = f' adb shell ime list -a'16 Logger.println(f"【exec_shell().shell={shell}】")17 linesStr = list(os.popen(shell).readlines())18 for line in linesStr:19 Logger.println(f"{line}")20 if 'IME' in line:21 replace = line.replace(':', '')22 Logger.println(f"【().找到默认输入法:{replace}】")23 return replace24def setImiDefault():25 default = getImiDefault()26 shell = f' adb shell ime set {default}'27 Logger.println(f"【exec_shell().shell={shell}】")28 linesStr = list(os.popen(shell).readlines())29 for line in linesStr:30 Logger.println(f"{line}")31 if 'IME' in line:32 replace = line.replace(':', '')33 Logger.println(f"【().已经恢复默认输入法:{replace}】")34 return replace35def exe_shell(shell):36 Logger.println(f"【exec_shell().shell={shell}】")37 linesStr = list(os.popen(shell).readlines())38 for line in linesStr:39 Logger.println(f"{line}")40def stop_server():41 shell = f'adb kill-server'42 Logger.println(f"【exec_shell().shell={shell}】")43 exe_shell(shell)44def start_server():45 shell = f'adb start-server '46 Logger.println(f"【exec_shell().shell={shell}】")47 exe_shell(shell)48def export():49 full_dir = FilePathUtil.get_full_dir('wxfriend', 'pic')50 weixinPath = FilePathUtil.get_full_dir('wxfriend', 'pic', 'WeiXin')51 if os.path.exists(weixinPath):52 try:53 shutil.rmtree(weixinPath)54 except:55 pass56 deviceId = WxConfig.getAppiumConfig()["deviceName"]57 if deviceId:58 execute_adb_shell(f'pull /sdcard/Pictures/WeiXin/ {full_dir}', deviceId=deviceId)59 else:60 Logger.println(f"【().未找到设备】")61def classify(full_dir):62 # 2.excel获取朋友圈所有说说的md5以及图片的保存起始时间值63 Logger.println(f"【().full_dir={full_dir}】")64 array = excel_util.excel2array(full_dir)65 count = 066 for index, item in enumerate(array):67 content_md5 = item['content_md5']68 start = int(item['start'])69 end = int(item['end'])70 count = int(item['count'])71 if count > 0:72 # Logger.println(f"【classify().item={item}】")73 # 3.根据起始时间值以及md5值分类好图片74 full_dir = FilePathUtil.get_full_dir('wxfriend', 'pic', 'WeiXin')75 des_dir = FilePathUtil.get_full_dir('wxfriend', 'pic', 'WeiXinCopy', content_md5)76 files = FilePathUtil.move_files_by_time(full_dir, des_dir, start, end)77def classify_from(source_full):78 # 2.excel获取朋友圈所有说说的md5以及图片的保存起始时间值79 full_dir = FilePathUtil.get_lastmodify_file(80 FilePathUtil.get_full_dir("wxfriend", "excel", "pic"))81 Logger.println(f"【().full_dir={full_dir}】")82 array = excel_util.excel2array(full_dir)83 count = 084 for index, item in enumerate(array):85 content_md5 = item['content_md5']86 start = int(item['start'])87 end = int(item['end'])88 count = int(item['count'])89 if count > 0:90 # Logger.println(f"【classify().item={item}】")91 # 3.根据起始时间值以及md5值分类好图片92 des_dir = FilePathUtil.get_full_dir('wxfriend', 'pic', 'WeiXinCopy', content_md5)93 files = FilePathUtil.move_files_by_time(source_full, des_dir, start, end)94 # Logger.println(f"【{index}.{content_md5}(图片数量={count},实际图片数量={len(files)}】")95 # startfile(FilePathUtil.get_full_dir('wxfriend', 'pic'))96def main():97 export()98 full_dir = FilePathUtil.get_lastmodify_file(99 FilePathUtil.get_full_dir("wxfriend", "excel", "pic"))100 classify(full_dir)101def deletePictures():102 Logger.println(f"【deletePictures===========开始删除手机图片缓存========================】")103 deviceId = WxConfig.getAppiumConfig()["deviceName"]104 if deviceId:105 execute_adb_shell('shell rm -r /sdcard/Pictures/WeiXin', deviceId=deviceId)106 Logger.println(f"【deletePictures===========删除图片缓存执行完成=================】")107if __name__ == '__main__':108 setImiDefault()109 # if __name__ == '__main__':110 # main()111 # execute_adb_shell('rm -r /sdcard/Pictures/WeiXin')112 # des_dir = FilePathUtil.get_full_dir('wxfriend', 'pic', 'WeiXinCopy')113 # if os.path.exists(des_dir):114 # shutil.rmtree(des_dir)115 # export()116 # full_dir = FilePathUtil.get_lastmodify_file(117 # FilePathUtil.get_full_dir("wxfriend", "excel", "pic"))...

Full Screen

Full Screen

adb_helper.py

Source:adb_helper.py Github

copy

Full Screen

...21 self.adbstrategy = STFAdb(self.udid)22 else:23 self.adbstrategy = adb_local_helper(self.udid)24 pass25 def execute_adb_shell(self, cmd, timeout=30):26 return self.adbstrategy.execute_adb_shell(cmd, timeout)27 def pull_file(self, path_to_file, target_file, timeout=60):28 self.adbstrategy.adb_pull(path_to_file, target_file, timeout=timeout)29 def install_app(self, app_path, has_permission=False, timeout=30):30 self.adbstrategy.install_app(app_path, has_permission, timeout)31 def uninstall_app(self, package_name, timeout=30):32 self.adbstrategy.uninstall_app(package_name, timeout)33 def remove_sdkcard_apk(self):34 return self.execute_adb_shell("rm /sdcard/Download/*.apk")35 def start_page_by_schema(self, schema):36 return self.execute_adb_shell("am start -a android.intent.action.VIEW "37 "-d %s --activity-clear-task" % schema)38 def get_devices_ip_address(self):39 l = self.execute_adb_shell('ip addr | grep global')40 reg = re.compile('\d+\.\d+\.\d+\.\d+')41 return re.findall(reg, l[1])[0]42 def get_device_brand(self):43 cmd = "getprop ro.product.brand"44 # (execute_result, stdout, stderr) = self.adb_helper.adbstrategy.execute_adb_shell(cmd,timeout=30)45 (execute_result, stdout, stderr) = self.execute_adb_shell(cmd, timeout=30)46 Logger.INFO("brand type is: {}".format(stdout))47 # brand = stdout.split("\n")[0]48 brand=stdout.decode("utf-8")49 #brand = stdout.split("\n")50 brand = brand.split("\n")51 print(len(brand))52 if len(brand)<=2:53 brandname = brand[0]54 else:55 brandname = stdout.split("\r\n")[3]56 #.split("\r")[0]57 return brandname58if __name__ == '__main__':59 adb_helper = AdbHelper("1fa2b4c2", isSTF=False)...

Full Screen

Full Screen

adb_strategy.py

Source:adb_strategy.py Github

copy

Full Screen

...17 self.udid = udid18 pass19 def adb_pull(self, path_to_file, target_file):20 pass21 def execute_adb_shell(self, cmd,timeout):22 pass23 def install_app(self, app_path, has_permission, timeout):24 pass25 def uninstall_app(self, package_name, timeout):26 pass27 def execute_local_shell(self, cmd, timeout=None):28 pass29 def _kill_proc_by_timer(self, proc):30 if proc is not None:31 proc.kill()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful