app自动化时,各种不期待的d层d窗,升级广告等时有飞出,由于d窗具有不定时,不定页面等很多不确定性。有的d窗很不友好,不×掉,很难进行下一步 *** 作,造成 测试用例失败。而判断是否有d窗,d层很麻烦。
研究一下 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);
}
}
}
那么我们可以利用这个长监听,干点点掉d窗的事儿会不会很爽,d窗一d出,就把他点掉,点掉,点掉。
其实在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
}
});
在这个类中我们加入自己的d窗监听
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中d窗中有如下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 监听解决各种非期待d窗,d层,ddd等问题全部内容,希望文章能够帮你解决Appium UiWatchers 监听解决各种非期待d窗,d层,ddd等问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)