Appium-Commands-Demo:Device-Files

 1.self.driver.push_file()

# 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))

执行结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值