我有正在测试的应用程序,并且想将file
推送到我的android
设备(真实设备)中
这是我尝试过的:
self.driver.push_file('/mnt/sdcard/Pictures/photo.png', r'C:\photo.png')
因此该操作通过了,我可以在file
上看到device
,但是它的size
是1kb
,当我尝试打开它时,我有这个{{ 1}}:
我们似乎不支持此文件格式
我做错了什么?
答案 0 :(得分:1)
请注意,使用 Appium 和 Python 语言,当您调用self.driver.push_file()方法时,第二个参数是文件的内容base64 (而不是计算机上文件的路径)。
这意味着您首先必须读取文件,将其转换为base64(并使用utf-8对其进行解码),然后再将其传递给此方法:
import base64
...
with open(r'C:\photo.png','rb') as file:
driver.push_file('/mnt/sdcard/Pictures/photo.png',
base64.b64encode(file.read()).decode('utf-8'))
或者,您可以简单地使用以下命令(仅将source_path=
添加到您的代码段中):
self.driver.push_file('/mnt/sdcard/Pictures/photo.png', source_path=r'C:\photo.png')
..因为push_file()方法最近已更新为还支持源路径(请参见Pull #270):
def push_file(self, destination_path, base64data=None, source_path=None)
我当然会建议使用source_path
参数:)