appium 执行adb命令

# 切换输入法 adb shell ime set io.appium.settings/.UnicodeIME
driver.execute_script('mobile: shell', {'command': 'ime set', 'args': ['io.appium.settings/.UnicodeIME']})
# 键盘事件 adb shell input keyevent 66
driver.execute_script('mobile: shell', {'command': 'input keyevent', 'args': ['66']})
# 广播刷新文件展示 adb shell am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/DCIM/test.jpg
driver.execute_script('mobile: shell', {'command': 'am broadcast', 'args': ['-a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/DCIM/test.jpg']})
# 输入文本 adb shell input text hello
driver.execute_script('mobile: shell', {'command': 'input text', 'args': ['hello']})
# 推送文件到设备,一般和广播刷新文件一起使用
with open(local_path, 'rb') as file:
    data = str(base64.b64encode(file.read()), 'utf-8')
    driver.push_file(device_path, data)
posted @ 2025-03-06 22:00  アーニャ  阅读(54)  评论(0)    收藏  举报