Appium 关于 Appium V1.7.2 新增的唯一安卓可执行 mobile 命令 shell 的疑问

jackloo · 2018年01月28日 · 最后由 小叮当猫猫 回复于 2019年03月03日 · 2427 次阅读

关于 mobile: shell 在更新日志中说明,是从 1.7.1 升级到 1.7.2 中 “Add --relaxed-security, and mobile: shell access to adb”,并搜索 github 中 appium 库,找到需要配置 desiredcapabilities 中 relaxedSecurityEnabled 为 true,但实际执行无效。

TesterHome 社区有没有 Appium 项目组的大牛,能否跟进了解一下这个 mobile: shell 到底如何使用

我的 python 代码:
###
···python
def AndroidAppEmulator(platformVersion, appActivity, appPackage):
caps = {}
caps['relaxedSecurityEnabled'] = True
caps['automationName'] = 'UiAutomator2'
caps['platformName'] = 'Android'
caps['platformVersion'] = platformVersion
caps['deviceName'] = 'Android Emulator'
caps['appPackage'] = appPackage
caps['appActivity'] = appActivity
caps['unicodeKeyboard'] = True
caps['resetKeyboard'] = True
return WebDriver('http://127.0.0.1:4723/wd/hub', caps)

driver = learnappium.AndroidAppEmulator('7.1.1','.DialtactsActivity','com.android.dialer')
opts={'command':'am',
'args':['start','-N','com.android.calculator2/.Calculator']}
driver.execute_script('mobile: shell', opts)


报错信息如下:
###
···
  File "C:/Users/jack/PycharmProjects/AppiumTest/learnappium/Test06.py", line 9, in <module>
    print(driver.execute_script('mobile: shell', opts))
  File "C:\Users\jack\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium-3.8.0-py3.6.egg\selenium\webdriver\remote\webdriver.py", line 546, in execute_script
    'args': converted_args})['value']
  File "C:\Users\jack\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium-3.8.0-py3.6.egg\selenium\webdriver\remote\webdriver.py", line 311, in execute
    self.error_handler.check_response(response)
  File "C:\Users\jack\AppData\Local\Programs\Python\Python36\lib\site-packages\appium_python_client-0.26-py3.6.egg\appium\webdriver\errorhandler.py", line 29, in check_response
  File "C:\Users\jack\AppData\Local\Programs\Python\Python36\lib\site-packages\appium_python_client-0.26-py3.6.egg\appium\webdriver\errorhandler.py", line 24, in check_response
  File "C:\Users\jack\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium-3.8.0-py3.6.egg\selenium\webdriver\remote\errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Appium server must have relaxed security flag set in order to run any shell commands
···
共收到 4 条回复 时间 点赞

关键报错:
Appium server must have relaxed security flag set in order to run any shell commands

说得很明白,must have relaxed security flag set

官方文档里有一句很重要:

How To Execute Shell Commands On The Remote Device
It is possible to execute any command on the remote Android device or an emulator under test and get the output from it. This action might be potentially insecure and is disabled on the server side by default. One must provide the --relaxed-security command line argument while starting the server in order to enable remote shell commands execution (and other insecure features, which are disabled by default). An exception will be thrown if the relaxed security has not been enabled on the server side and one tries to invoke mobile: shell endpoint on the client side.

必须是在 server 端启动的时候设置 flag: --relaxed-security

然后,try it。

参考:http://appium.readthedocs.io/en/latest/en/writing-running-appium/android/android-shell/

大东 回复

caps['relaxedSecurityEnabled'] = True
代码里已经有了,还是不行。

大东 回复

appium --relaxed-security -U udid
这样试了可以,thanks

appium -a %s -p %s --session-override --relaxed-security --log %s(ios 运行)
或者安卓去掉参数运行:
appium --session-override --relaxed-security

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册