自動化アプリは、ポップは随時不定のページを持っているので、飛行時に爆弾層ポップ、広告やその他のアップグレードのすべての種類を期待し、不確実性の多くないとき。アウト×ではない、非常にフレンドリーないくつかのポップには、次のステップは、失敗したテストケースで、その結果、困難です。そしてポップがあるかどうかを決定する、弾性層が非常に面倒です。
その後、原則appiumとモバイル通信見つけることは難しいことではありません見て、あなたが電話AppiumBootstrap.jarの実行appiumを押すと、コードのように作品があると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()