# file--------------------------------------------------- def Push_File(self): # 将某个内容放到模拟器或真机的某个路径文件内 # 注意:dest_path 是指模拟器或真机的文件目录,不要傻乎乎写电脑路径 # 问题①:pycharm 报 Read-only file system;系统的读写权限问题 # 问题①参考https://blog.csdn.net/weixin_40117614/article/details/83345525 # 解决方案: 前提条件:cmd 进入 adb目录 # ①执行:adb root 获取root权限 # ②执行:adb disable-verity 关闭 system 分区的 verity特性 # ③执行:adb reboot 重启 # ④执行:adb root 获取root权限 # ⑤执行:adb remount # 执行完⑤,显示remount successful ,然后需要重启模拟器,再用pycharm去跑self.driver.push_file() # 问题②:pycharm报 'Appium_Device' object has no attribute 'driver' 就是appium连接失败 # 解决方案: 进入cmd 执行adb remount 显示remount successful 就可以了 dest_path = '/storage/emulated/0/Pictures/push_file.txt' dest_path1 = '/storage/emulated/0/Pictures/local_file.txt' # Args: # destination_path: the location on the device/simulator where the local file contents should be saved # base64data: file contents, encoded as base64, to be written # to the file on the device/simulator # source_path: local file path for the file to be loaded on device #用法一:#某个确定的内容传到模拟机或真机上 data = bytes('This is the contents of the file to push to the device.', 'utf-8') self.driver.push_file(dest_path, base64.b64encode(data).decode('utf-8')) # 注意date需要编码成base64,再解码成utf-8形式显示内容;如果只是encode成base64 会报Object of type bytes is not JSON serializable # 就是解码的形式没有设定 #用法二:#本地的文件内容传到模拟机或真机上 source_path = 'D:\Local_text.txt' self.driver.push_file(dest_path1,source_path=source_path) # 必须注明是给source_path传参,即黄色字体 source_path= 不可省略
执行结果:
2.self.driver.pull_file()
def Pull_File(self): # 将某个设备(模拟器或真机)目录下的文件内容获取出来 file_base64 = self.driver.pull_file('/storage/emulated/0/Pictures/push_file.txt') print(base64.b64decode(file_base64).decode('utf-8')) # 注意file_base64是用base64编码的str类型,所以选需要decode下base64,然后在decode成utf-8
执行结果:
3.self.driver.pull_folder()def Pull_Folder(self):#把路径下的文件夹内容获取出来 folder_base64 = self.driver.pull_folder('/storage/emulated/0/Android/data/com.fullyrun.yingpar/1103210508030976#yingpar/core_log') print(base64.b64decode(folder_base64))
执行结果: