Appium UiWatchers 监听解决各种非期待弹窗,弹层,弹弹弹等问题
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 监听解决各种非期待弹窗,弹层,弹弹弹等问题的更多相关文章
- 利用UiWatchers 监听解决安卓自动化各种自动化各种非期待弹窗,弹层,升级,广告,对话框,来电等问题
app自动化时,各种不期待的弹层弹窗,升级广告等时有飞出,由于弹窗具有不定时,不定页面等很多不确定性.有的弹窗很不友好,不×掉,很难进行下一步操作,造成 测试用例失败.而判断是否有弹窗,弹层很麻烦.研 ...
- 配置静态监听解决ORA-12514错误的案例(转)
今天做Linux下DG配置的时候,遇到一个现象,tnsname.ora文件配置都正常,tnsping也正常,监听也正常,但是仍然报ORA-12514错误: SQL> set lin 130 ...
- 转载:oracle11G 已开启监听,但远程连接依旧无监听解决过程
1.连接数据库显示无监听程序,首先查看服务器的oracle监听服务是否开启,服务名称:OracleOraDb11g_home1TNSListener(具体环境中可能不完全一样,但是认准TNSListe ...
- oracle11G 已开启监听,但远程连接依旧无监听解决过程
1.连接数据库显示无监听程序,首先查看服务器的oracle监听服务是否开启,服务名称:OracleOraDb11g_home1TNSListener(具体环境中可能不完全一样,但是认准TNSListe ...
- 关于 edittext 软键盘退出监听解决办法
edittext 有个onCreateInputConnection 的方法,通过它可以自定义一个输入法连接器,那里连接器里面有个方法(finishComposingText)能监听输入完成的动作. ...
- 配置静态监听解决ORA-12514错误的案例
今天做Linux下DG配置的时候,遇到一个现象.tnsname.ora文件配置都正常,tnsping也正常,监听也正常.可是仍然报ORA-12514错误: SQL> set lin 130 pa ...
- cocos2d-x JS 弹出对话框触摸监听(吞噬点击事件遮挡层)
在游戏中,我们经常会碰到一些弹窗,这些弹窗禁止点透,也就是禁止触摸事件传递到底层,我们称之为遮挡层,这些遮挡层,需要开发遮挡层,我们首先得了解cocos2d-js的触摸传递机制. 根据官方文档,我们可 ...
- vue 弹窗时 监听手机返回键关闭弹窗(页面不跳转)
[注]: popstate 事件 a.当活动历史记录条目更改时,将触发popstate事件. b.如果被激活的历史记录条目是通过对history.pushState()的调用创建的,或者受到对his ...
- Oracle非默认监听的处理会遇到的问题以及处理方法
第一种情况:只是修改默认端口 1.当前监听状态: C:\Windows\system32>lsnrctl status LSNRCTL for 64-bit Windows: Version 1 ...
随机推荐
- LeetCode 1143. Longest Common Subsequence
原题链接在这里:https://leetcode.com/problems/longest-common-subsequence/ 题目: Given two strings text1 and te ...
- 实现redis缓存,缓存穿透简单原理
String get(String key) { String value = redis.get(key); if (value == null) { if (redis.setnx(key_mut ...
- SpringBoot终章(整合小型进销系统)
在前面的章节中我们学习Spring的时候可以看到配置文件比较多,所以我们有了SpringBoot 1. 引入依赖 <dependencies> <dependency> < ...
- asp.net web开发——文件的上传和下载
HTML部分 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.a ...
- less简介及其编译原理
一.less环境安装 ①首先需要在电脑上安装nodejs,一般会内置npm,利用以下命令可以检测: ②利用npm在线安装less,运行 npm install –g less ③查看是否安装成功,L ...
- 洛谷P4343 [SHOI2015]自动刷题机
题目 易得该题目中的\(n\)和\(k\)具有单调性,满足二分的性质,因此该题目而已用二分来枚举\(n\),然后对于每个\(n\)模拟出它所对应的\(k\),然后注意注意代码细节,并且当当前\(k\) ...
- 时间time模块
time模块: import time --时间模块 --time : 三种不同的时间格式,可以相互转换 时间戳(timestamp): --从1970年1月1日00:00:00开始按秒计算的偏移量 ...
- 【洛谷】P1449 后缀表达式
P1449 后缀表达式 分析: 简单的模拟题. 熟练容器stack的话很容易解决. stack,栈,有先进后出的特性. 比如你有一个箱子,你每放进第一个数时,就往箱底放,放第二个数时就在第一个数的上面 ...
- Prometheus监控神技--自动发现配置
一.自动发现类型 在上一篇文中留了一个坑: 监控某个statefulset服务的时候,我在service文件中定义了个EP,然后把pod的ip写死在配置文件中,这样,当pod重启后,IP地址变化,就监 ...
- 移动端 - adb shell常见问题汇总
一.如何执行adb命令? 答:如果没有配置SDK的环境变量的话,那就先用cd命令进入adb所在文件目录(即F:\android-sdk-windows\platform-tools)后,再执行adb命 ...