为什么要 exit?
如果是在做测试不应该告诉上一级结果吗
开发知道什么,测试也就需要知道什么
有时候甚至更多,不然怎么发现更好逼格 (滑稽) 的 bug
其实还是去啃一本操作系统原理的书吧 (linux/android),如果是做 app 或者网站的话
弄明白个大概就行
抓 log,报 bug 给 appium
python3 不用添加 u
IDE/Project 的编码和你 terminal 的编码没关系.
举个例子,如果你用的是中文版 windows,那大多数情况下你 cmd 的编码是 gbk,所以当你需要 print 东西到 cmd 之前,需要转成 gbk
至于你现在看到的窗口,看上去是 appium 起的,你得查看起的这个 terminal 的输出编码是什么
当然有,所有 python 内部处理用 str(py3)/unicode(py2),所有输出转换到对应编码
capabilities.setCapability("automationName","uiautomator2")
把 log 存成文件看
打开 cmd
把 python.exe 拖进去
输入空格
把你的脚本也拖进去
回车
依然看不出问题来,尝试升级 appium 到最新,然后用 uiautomator2
文件用 utf8 存
文件内申明 utf8
print 前把内容 encode 成你 cmd 的显示编码
引号用半角而不是全角
后续操作的代码呢
目前这些没看出有什么问题
错误贴完整,代码贴上来
顺便是 ide 报错还是运行时报错
yymobile 下建一个__init__.py
然后 from yymobile.public.readconfig import xxx
大小写自己注意
贴上整个项目的文件 tree
整个项目作为一个包的话,需要从该项目根目录开始 import 路径
appium xxx xx xxx &
python? 如果是的话,怎么还在用 os.system
改换 subprocess 了
“但是点击后就无法继续对 APP 进行操作了”,比如?
最好 show me the code
把 err 用 gbk 解码打印出来看看你就知道原因了
顺便练练英语吧,如果你想知道 pty 参数问题的原因
https://github.com/fabric/fabric/issues/395
pty/tty = false
The bash shell launched connects to the stdout/stderr/stdin of the started process and is kept running until there is nothing attached to the sockets and it's children have exited. A good deamon process will ensure it doesn't wait for it's children to exit, fork a child process and then exit. When in this mode no SIGHUP will be sent to the child process by SSH. I believe this will work correctly for most scripts executing a process that handles deamonizing itself and doesn't need to be backgrounded. Where init scripts use '&' to background a process then it's likely that the main problem will be whether the backgrounded process ever attempts to read from stdin since that will trigger a SIGHUP if the session has been terminated.
pty/tty = true*
If the init script backgrounds the process started, the parent BASH shell will return an exit code to the SSH connection, which will in turn look to exit immediately since it isn't waiting on a child process to terminate and isn't blocked on stdout/stderr/stdin. This will cause a SIGHUP to be sent to the parent bash shell process group, which since job control is disabled in non-interactive mode in bash, will include the child processes just launched. Where a daemon process explicitly starts a new process session when forking or in the forked process then it or it's children won't receive the SIGHUP from the BASH parent process exiting. Note this is different from suspended jobs which will see a SIGTERM.
I suspect the problems around this only working sometimes has to do with a slight race condition. If you look at the standard approach to deamonizing - http://www.itp.uzh.ch/~dpotter/howto/daemonize, you'll see that in the code the new session is created by the forked process which may not be run before the parent exits, thus resulting the random sucess/failure behaviour mentioned above. A sleep statement will allow enough time for the forked process to have created a new session, which is why it works for some cases.
pty/tty = true and job control is explicitly enabled in bash
SSH won't connect to the stdout/stderr/stdin of the bash shell or any launched child processes, which will mean it will exit as soon as the parent bash shell started finished executing the requested commands. In this case, with job control explicitly enabled, any processes launched by the bash shell with '&' to background them will be placed into a separate session immediately and will not receive the SIGHUP signal when the the parent process to the BASH session exits (SSH connection in this case).
如果看不明白的话我可以简单解释下
统一 print 写法,要么都函数式要么都作为函数调用 (推荐后者)
用 except Exception as e 替代逗号的写法
不要捕获"Exception",你应该要知道要调用的函数会抛出什么异常
ssh_client 尝试使用 with,而不是手动指定何时关
尝试使用 format 来格式化字符串而不是%
既然函数内尝试捕获了异常,但依然像正常状态一样返回了一个不可用的实例,建议要么不要捕获异常,要么捕获之后加打印,然后把异常抛出交给上一级处理
感兴趣的话试用看看 argparse 来原做某些按需的处理,很多时候脚本不要做交互式的才更好用
支持模糊,但是你还是先搞清楚当前 job 的 workspace 是哪里吧
看插件文档了么?看到右边的问号了么?
试试 python -m pytest test_x.py
manifest 里权限申请了么
测试 apk 装的时候用-g 参数,这样默认所有权限直接授权,不用动态申请了,或者不用到 M/N/O 的特性的话,指定编译的 sdk 为 L 也可以绕过
有耐心的话,可以参考我的这个实现:
https://github.com/264768502/adb_wrapper/blob/master/adb_wrapper/base_wrapper.py
主要看_command_blocking 这个函数
兼容了 py2 和 py3
具体原理可以参考一下 sf 的回答
http://stackoverflow.com/questions/2715847/python-read-streaming-input-from-subprocess-communicate/17698359#17698359
uiautomator2.0 作为 apk,安装起来肯定也受限于安卓系统的安全管理策略
如果有方法可以跳过这个,那岂不是一个很大的漏洞
所以每个魔改系统都有自己的策略,想要一招搞定所有系统,难
另外,如果实在不想 root,可以用障碍辅助服务
比如每个手机预先安装类似酷市场的酷安装,然后去障碍辅助里开启