app自动化时,各种不期待的弹层弹窗,升级广告等时有飞出,由于弹窗具有不定时,不定页面等很多不确定性。有的弹窗很不友好,不×掉,很难进行下一步操作,造成 测试用例失败。而判断是否有弹窗,弹层很麻烦。
研究一下 appium和手机通信的原理就不难发现,运行appium时推送手机AppiumBootstrap.jar的中,有这么一段代码再listenForev/* * The Bootstrap class runs the socket server.

 * 
*/
public class Bootstrap extends UiAutomatorTestCase { public void testRunServer() {
Find.params = getParams();
final boolean disableAndroidWatchers = Boolean.parseBoolean(getParams()
.getString("disableAndroidWatchers"));
final boolean acceptSSLCerts = Boolean.parseBoolean(getParams().getString(
"acceptSslCerts")); SocketServer server;
try {
server = new SocketServer(4724);
server.listenForever(disableAndroidWatchers, acceptSSLCerts);
} catch (final SocketServerException e) {
Logger.error(e.getError());
System.exit(1);
} }
} 那么我们可以利用这个长监听,干点点掉弹窗的事儿会不会很爽,弹窗一弹出,就把他点掉,点掉,点掉。
其实在UiWatchers.java中,作者已经写了很多UI监听了,贴一小段代码。
public class UiWatchers {
private static final String LOG_TAG = UiWatchers.class.getSimpleName();
private final List<String> mErrors = new ArrayList<String>(); /**
* We can use the UiDevice registerWatcher to register a small script to be
* executed when the framework is waiting for a control to appear. Waiting may
* be the cause of an unexpected dialog on the screen and it is the time when
* the framework runs the registered watchers. This is a sample watcher
* looking for ANR and crashes. it closes it and moves on. You should create
* your own watchers and handle error logging properly for your type of tests.
*/
public void registerAnrAndCrashWatchers() { UiDevice.getInstance().registerWatcher("ANR", new UiWatcher() {
@Override
public boolean checkForCondition() {
UiObject window = new UiObject(new UiSelector()
.className("com.android.server.am.AppNotRespondingDialog"));
String errorText = null;
if (window.exists()) {
try {
errorText = window.getText();
} catch (UiObjectNotFoundException e) {
Log.e(LOG_TAG, "dialog gone?", e);
}
onAnrDetected(errorText);
postHandler();
return true; // triggered
}
return false; // no trigger
}
}); 在这个类中我们加入自己的弹窗监听
public void registerMyPopupWatcher() {
UiDevice.getInstance().registerWatcher("myPopup", new UiWatcher() {
@Override
public boolean checkForCondition() { //广告提示
UiObject ggPop = new UiObject(new UiSelector().resourceId("com.gift.android:id/close_view")); //站点切换
UiObject addChgPop = new UiObject(new UiSelector().resourceId("com.gift.android:id/bt_cancel")); //升级提示
UiObject upPop = new UiObject(new UiSelector().resourceId("com.gift.android:id/close")); if (upPop.exists()) {
System.out.println("you have a updateApp popup window");
try {
upPop.clickAndWaitForNewWindow();
return true; // triggered
} catch (UiObjectNotFoundException e) {
Log.e(LOG_TAG, "Exception", e);
}
}else if (ggPop.exists()) {
System.out.println("you have a popup window");
try {
ggPop.clickAndWaitForNewWindow();
return true; // triggered
} catch (UiObjectNotFoundException e) {
Log.e(LOG_TAG, "Exception", e);
}
}else if (addChgPop.exists()) {
System.out.println("you have a change site popup window");
try {
addChgPop.clickAndWaitForNewWindow();
return true; // triggered
} catch (UiObjectNotFoundException e) {
Log.e(LOG_TAG, "Exception", e);
}
}
return false; // no trigger
}
}); Log.i(LOG_TAG, "Registered myPopupPopup Watchers");
}
在listenForever的方法中去调用一下,这样我们也监听Forever了。 写完编译成AppiumBootstrap.jar包,放在\Appium\node_modules\appium\build\android_bootstrap\下面。随着appium服务启动时,推送到手机中。
跑一下看效果。
app中弹窗中有如下resourceId的,统统被点掉了。
resourceId="com.gift.android:id/close_view";
resourceId="com.gift.android:id/bt_cancel";
resourceId="com.gift.android:id/close";
转载:
https://testerhome.com/topics/12938

Appium UiWatchers 监听解决各种非期待弹窗,弹层,弹弹弹等问题的更多相关文章

  1. 利用UiWatchers 监听解决安卓自动化各种自动化各种非期待弹窗,弹层,升级,广告,对话框,来电等问题

    app自动化时,各种不期待的弹层弹窗,升级广告等时有飞出,由于弹窗具有不定时,不定页面等很多不确定性.有的弹窗很不友好,不×掉,很难进行下一步操作,造成 测试用例失败.而判断是否有弹窗,弹层很麻烦.研 ...

  2. 配置静态监听解决ORA-12514错误的案例(转)

    今天做Linux下DG配置的时候,遇到一个现象,tnsname.ora文件配置都正常,tnsping也正常,监听也正常,但是仍然报ORA-12514错误:   SQL> set lin 130 ...

  3. 转载:oracle11G 已开启监听,但远程连接依旧无监听解决过程

    1.连接数据库显示无监听程序,首先查看服务器的oracle监听服务是否开启,服务名称:OracleOraDb11g_home1TNSListener(具体环境中可能不完全一样,但是认准TNSListe ...

  4. oracle11G 已开启监听,但远程连接依旧无监听解决过程

    1.连接数据库显示无监听程序,首先查看服务器的oracle监听服务是否开启,服务名称:OracleOraDb11g_home1TNSListener(具体环境中可能不完全一样,但是认准TNSListe ...

  5. 关于 edittext 软键盘退出监听解决办法

    edittext 有个onCreateInputConnection 的方法,通过它可以自定义一个输入法连接器,那里连接器里面有个方法(finishComposingText)能监听输入完成的动作. ...

  6. 配置静态监听解决ORA-12514错误的案例

    今天做Linux下DG配置的时候,遇到一个现象.tnsname.ora文件配置都正常,tnsping也正常,监听也正常.可是仍然报ORA-12514错误: SQL> set lin 130 pa ...

  7. cocos2d-x JS 弹出对话框触摸监听(吞噬点击事件遮挡层)

    在游戏中,我们经常会碰到一些弹窗,这些弹窗禁止点透,也就是禁止触摸事件传递到底层,我们称之为遮挡层,这些遮挡层,需要开发遮挡层,我们首先得了解cocos2d-js的触摸传递机制. 根据官方文档,我们可 ...

  8. vue 弹窗时 监听手机返回键关闭弹窗(页面不跳转)

    [注]:  popstate 事件 a.当活动历史记录条目更改时,将触发popstate事件. b.如果被激活的历史记录条目是通过对history.pushState()的调用创建的,或者受到对his ...

  9. Oracle非默认监听的处理会遇到的问题以及处理方法

    第一种情况:只是修改默认端口 1.当前监听状态: C:\Windows\system32>lsnrctl status LSNRCTL for 64-bit Windows: Version 1 ...

随机推荐

  1. 检测并修改linux服务器日期

    公司的一个应用服务器license到期了,商务上短时间解决不了.只好将服务器的时间调到去年,临时将就一下. 服务器是vmware虚拟机装的centos,日期每隔一段时间会自动同步,百度了好久,也关闭不 ...

  2. Linux——查询服务器公网IP

    前言 服务器查看IP,十分简单,但是如何查看公网IP呢? 步骤 网站:http://www.cip.cc/ 命令行查询(详细): UNIX/Linux: #curl cip.cc Windows: & ...

  3. PHP程序员最容易犯的Mysql错误

    对于大多数web应用来说,数据库都是一个十分基础性的部分.如果你在使用PHP,那么你很可能也在使用MySQL—LAMP系列中举足轻重的一份子. 对于很多新手们来说,使用PHP可以在短短几个小时之内轻松 ...

  4. L3956棋盘

    1,记得之前要复习.上次先写的题是数的划分. 虽然我不想说,估计全忘了.复习就当把上次的题写了把. 应该比较稳了. 2,题中的要求. 一,所在的位置必须是有颜色的.(很明显要用bool去涂一遍) 二, ...

  5. LeetCode 787. Cheapest Flights Within K Stops

    原题链接在这里:https://leetcode.com/problems/cheapest-flights-within-k-stops/ 题目: There are n cities connec ...

  6. WinDbg常用命令系列---.cordll (控制CLR调试)

    .cordll (控制CLR调试) 简介 .cordell命令控制托管代码调试和Microsoft.NET公共语言运行库(CLR). 使用形式 .cordll [Options] 参数 Options ...

  7. 2-ESP8266 SDK开发基础入门篇--非RTOS版与RTOS版

    https://www.cnblogs.com/yangfengwu/p/11071580.html 所有的源码 https://gitee.com/yang456/Learn8266SDKDevel ...

  8. 机器学习---朴素贝叶斯与逻辑回归的区别(Machine Learning Naive Bayes Logistic Regression Difference)

    朴素贝叶斯与逻辑回归的区别: 朴素贝叶斯 逻辑回归 生成模型(Generative model) 判别模型(Discriminative model) 对特征x和目标y的联合分布P(x,y)建模,使用 ...

  9. epoch,iteration与batchsize的区别

    神经网络中epoch与iteration是不相等的 batchsize:中文翻译为批大小(批尺寸).在深度学习中,一般采用SGD训练,即每次训练在训练集中取batchsize个样本训练: iterat ...

  10. touchz,mkdir,vi的区别

    touchz:创建空白文档 mkdir:创建一个目录 vi : 创建一个编辑状态的空文档,保存退出后创建成功.