Appium 求助,通过 Appium 将图片 push 到 ios 设备中

Ying,Ruoyuan · 2016年07月27日 · 最后由 Ying,Ruoyuan 回复于 2016年07月29日 · 1432 次阅读

最近做自动化测试需要将图片 push 到设备中来检测显示情况,尝试调用 Appium 的方法:

driver.push_file(remote_path, data.encode('base64'))

但是在 ios 设备上碰到了报错:

    self._driver.push_file(remote_path, data.encode('base64'))
  File "build/bdist.macosx-10.11-intel/egg/appium/webdriver/webdriver.py", line 474, in push_file
    self.execute(Command.PUSH_FILE, data)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
    self.error_handler.check_response(response)
  File "build/bdist.macosx-10.11-intel/egg/appium/webdriver/errorhandler.py", line 29, in check_response
    raise wde
WebDriverException: Message: Method has not yet been implemented

请问这个报错是因为将文件 push 到 ios 设备的 API 还没有实现吗?还是我调用的方法有错误?
如果是 API 还没有实现,各位大牛有什么好的方法来实现将图片 push 到设备的方法?

共收到 7 条回复 时间 点赞

如果是 java 可以用 runtime.exec("adb push ......")

#1 楼 @yzx200712256 ,我用的是 ios 设备碰到这个问题,似乎不可以用 adb 命令呢

好吧,再试一试这个 api 吧,这个 api 我之前试过貌似是可以的啊,我记得。
要不你再确认一下,看一下这个 sample (http://www.2cto.com/kf/201501/368019.html)

#3 楼 @yzx200712256 这还是 android 的

#5 楼 @sanlengjingvv ,感谢,很有用;
我试了下,碰到了另外一个问题,push 图片进去后,图片在手机上不显示;我尝试在沙盒中删除一张原本的图片,这张图片显示似乎也没什么问题,但是上传图片的时候会提示不存在,所以我推测可能是没有做类似于 remount 的动作导致图片显示不出来;
请问下有类似于 Android 的 adb shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///storage/sdcard0,这种刷新 remount 下让图片显示的命令吗?或者有其他的什么动作需要做才能使图片正常显示?

我看了 driver 里面的 pull 和 push 方法的介绍,方法里似乎也没有提示说 Android only,请问有人在 ios 上用过这个方法吗?

def pull_file(self, path):
    """Retrieves the file at `path`. Returns the file's content encoded as
    Base64.

    :Args:
     - path - the path to the file on the device
    """
    data = {
        'path': path,
    }
    return self.execute(Command.PULL_FILE, data)['value']

def pull_folder(self, path):
    """Retrieves a folder at `path`. Returns the folder's contents zipped
    and encoded as Base64.

    :Args:
     - path - the path to the folder on the device
    """
    data = {
        'path': path,
    }
    return self.execute(Command.PULL_FOLDER, data)['value']

def push_file(self, path, base64data):
    """Puts the data, encoded as Base64, in the file specified as `path`.

    :Args:
     - path - the path on the device
     - base64data - data, encoded as Base64, to be written to the file
    """
    data = {
        'path': path,
        'data': base64data,
    }
    self.execute(Command.PUSH_FILE, data)
    return self
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册