Appium iOS8.0 Notification Allow 弹出框解决办法

深圳-Max · 2015年02月12日 · 最后由 深圳-Max 回复于 2015年03月06日 · 1904 次阅读
本帖已被设为精华帖!

话说,我们的应用升级了,xcode 也升级了,开发把所有都升级了。。结果就是我的老版本的模拟器对有些输入框无法输入了。。。

各种搜。。。
Appium bug? (https://github.com/appium/appium/issues/4286) 要 1.3.6 解决,现在才 1.3.5,查看版本历史,基本要 1 个月以后了。。。
老大说了,年前要解决这个问题。。。

好吧,换 iOS8.0 试试,不错,可以输入了,哇哈哈,全换 iOS8.0,就此正题开始了。。。

应用启动后就弹出了 *** Would like to Send You Notifications .......

尝试 1:识别 alert,写代码点掉他
抓取是没有问题的,XPath,name。。。都可以,结果就是执行的时候找不到,不到,不到到。。。
原来这个是系统的,无法操作

尝试 2:capabilities 设置 autoAcceptAlerts
capabilities 设置连接 https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

autoAcceptAlerts Accept iOS privacy access permission alerts (e.g., location, contacts, photos) automatically if they pop up. Default is false.

看起来不错,添加,执行,哇哈哈,果然 KO 了它, 各种执行,太完美了,,, 就在此时,没错,刚 KO 的 alert,完全没有了,对没错,完全没有了,就连我自己 app 弹出来的 alert 也自动被 KO 了,太完美了,我都不用干活了,app 自己 alert 的信息完全不给我验证的机会啊。。。

问题来了,怎么只点系统的 alert,而漏掉 app 自己的链接,给我个验证的机会
尝试 3: 设置 autoAcceptAlerts, 等 app 开起来关掉 系统 alert 后,关闭 autoAcceptAlerts
哇哈哈,太完美了,简直无法直视啊。。。
开干,set, start,update,等等,好像没有 update,这是一条路走到黑啊(别笑话我,内部了解不透彻。。)

路都死了?继续各种搜。。。
冬天来了,春天也该来了,挖到宝了
https://github.com/appium/appium/issues/4178
内容大概就是,这个,那个,然后。。。(还是自己看吧,我 E 文太烂,就不解释了)

尝试 4:capabilities 设置 waitForAppScript
waitForAppScript The ios automation script used to determined if the app has been launched, by default the system wait for the page source not to be empty. The result must be a boolean e.g. true;, target.elements().length > 0;, $.delay(5000); true;

设置 waitForAppScript 为 $.delay(5000); $.acceptAlert(); true; 大概意思就是等待 appOK 的时候执行设置的 js
执行,系统 alert 被 KO, 然后,然后,App 的 alert 保留,太完美了,完美了,美了。

就这样吧,理解有错误的,往大神指点。

Max.Bai@20150212

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 7 条回复 时间 点赞
匿名 #1 · 2015年02月12日

这个屌炸天,我也正好有个类似问题,明天用这方法去试试😄

可以根据弹出窗标题来判断。在 uiautomation 中直接实现。

#2 Appium 系统弹出框抓不到, uiautomation 怎么弄?

#3 楼 @229max uiautomation 也抓不到~

很久以前,我用 sikuli 搞这个,simulator 上跑的,真机就不知道了。

匿名 #6 · 2015年03月05日

@ 229max
配置
capabilities.setCapability("waitForAppScript","$.delay(5000); $.acceptAlert(); true;");
会自动关掉 alert 吗?

我使用的是 ios7.1 模拟器,增加了上述配置,但是也不会自动关闭窗口,还需要 appDriver.switchTo().alert().accept();
来操作关闭呢。
但是如果没有 waitForAppScript 配置的时候 appDriver.switchTo().alert().accept();会失败。

@liqing380

  1. 我 iOS8.0 加了 java apabilities.setCapability("waitForAppScript","$.delay(5000); $.acceptAlert(); true;"); 文中图片的窗口会在弹出后自动被关掉

2.iOS7.1 好像没有这样的窗口吧,我是没有遇到过

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