我正在使用Appium框架测试我的Android应用程序.我有一个Android屏幕,其视图没有id(我不想添加...),所以我想使用Xpath.
这是UI Automator Viewer中屏幕的样子:

我想得到所有的相对布局(用红色标记 - 十六项)
我尝试了以下方法:
List<WebElement> webElementslist =
mAppDriver.findElementsByXPath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ViewAnimator[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]");
Run Code Online (Sandbox Code Playgroud)
但我没有收到任何物品.
我在网上搜索并找到了下一个xpath教程,尝试了更多选项,但又没有成功.
http://www.zvon.org/comp/r/tut-XPath_1.html#intro
非常感谢任何帮助.
在Android Ui测试中,我想在对话框中单击一个微调项目,但它会弹出以下错误:
va.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus. Otherwise, something is seriously wrong. Selected Root:
Root{application-window-token=android.view.ViewRootImpl$W@2dac97c7, window-token=android.view.ViewRootImpl$W@2dac97c7, has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#10 ty=1 fl=#81810100 pfl=0x8 wanim=0x1030461 surfaceInsets=Rect(0, 0 - 0, 0) mwfl=0x0}, decor-view-string=MultiPhoneDecorView{id=-1, visibility=VISIBLE, width=1600, height=2560, has-focus=true, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, …Run Code Online (Sandbox Code Playgroud) android automated-tests android-espresso android-uiautomator
当我在 Android Studio 中运行 UIAutomator 时,有时会出现崩溃。
W/ActivityManager: Crash of app com.example.testsample running instrumentation ComponentInfo{com.example.testsample.test/android.support.test.runner.AndroidJUnitRunner}
07-16 19:19:34.191 7834-7850/? W/Binder: Binder call failed.
java.lang.SecurityException: Calling from not trusted UID!
at android.app.UiAutomationConnection.throwIfCalledByNotTrustedUidLocked(UiAutomationConnection.java:427)
at android.app.UiAutomationConnection.shutdown(UiAutomationConnection.java:324)
at android.app.IUiAutomationConnection$Stub.onTransact(IUiAutomationConnection.java:209)
at android.os.Binder.execTransact(Binder.java:570)
Run Code Online (Sandbox Code Playgroud)
但并不是每次都显示。当没有显示时我可以成功运行。谁能帮我?谢谢。
如何在UiAutomator Android中的事件点击之间提供延迟.
第一个事件是在EditText中输入一个URL:
new UiObject(new UiSelector().text("Search here")).setText("abc.com");
getUiDevice.waitForIdle(15000);
Run Code Online (Sandbox Code Playgroud)
这里我在webview中加载一个网页.所以当url加载完成时,我需要检查第二个事件.
第二个事件是检查对象的内容描述:
UiObject curClass = new UiObject(new UiSelector().className("android.widget.RelativeLayout"));
UiObject yCur = curClass.getChild(new UiSelector().description("ye"));
getCurCol();
public void getCurCol() throws UiObjectNotFoundException {
try {
if (yCur.getContentDescription() != null)
report.append("Success");
} catch (Exception e) {
System.err.println("\nCaught Exception: " + e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
但这似乎并没有起作用.
我只是希望应用程序在检查第二个事件之前等待一段时间.
我知道这三种方法是为UI Automator的延迟提供的 -
public void waitForIdle(long timeout)
public void waitForIdle()
public boolean waitForWindowUpdate(String packageName, long timeout)
Run Code Online (Sandbox Code Playgroud)
但我不知道如何使用这些方法.
请给我一个如何使用这些的例子.
任何帮助,将不胜感激.
谢谢!
这仅发生在AVD管理器内的AVD设备上.从Genymotion捕获uiautomatorviewer截图时,我从未收到此错误.
尝试在AS中的Android设备监视器中捕获时...它给了我更多详细信息:原因:获取UI层次结构时出错

在KitKat中,如果焦点放在webview上,我们就可以从UIAutomator转储中获取webview视图层次结构.我想知道是否有替代功能用于获取棒棒糖版本的webview视图层次结构,或者该版本中是否丢失了该功能?
我知道围绕这个有很多问题,但我找不到任何可以帮助我的东西:(
我尝试使用Espresso为Android应用程序生成UI-Test.在击败依赖性问题之后(因为某些库在不同版本中被包含两次作为来自其他库的依赖)我仍然无法创建工作测试...
我知道IdlingResource,但正如我所读到的,espresso等待开箱即用,直到主线程和AsyncTaskPool空闲,然后再运行任何测试.
为了与它取得联系,我创建了一个包含两个活动的简单应用程序,一个启动画面和一个主要活动.在启动mainActivity之前,splashscreen包含等待三秒钟的内容
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
}
}, 3000);
Run Code Online (Sandbox Code Playgroud)
我也尝试使用AsyncTask,但似乎没有任何工作正常,因为每个测试都失败了.
该测试仅检查视图上是否显示包含已定义文本的TextView:
onView(withText("DummyText")).check(matches(notNullValue()));
Run Code Online (Sandbox Code Playgroud)
我认为创建一个简单的测试并不困难......
因为我要测试api> = 16我需要浓缩咖啡.仅仅对我来说,我使用uiAutomator检查它(我知道这是为了api> = 18)但是有一些智能逻辑可以等待某些东西显示.....并且完美地工作......
testing android automated-tests android-espresso android-uiautomator
我正在用adb测试我的应用程序,但是当我执行"uiautomator的转储视图层次结构"时,我收到此错误:
获取UI层次结构时出错获取UI层次结构XML文件时出错:com.android.ddmlib.SyncException:远程对象不存在!
我的adb版本是1.0.36,我的android版本是6.0.1.
仅当在界面中存在运动中的动态元素时才会启动此错误.
先感谢您.
我在Pixel设备上尝试Android P预览,目前遇到使用UiAutomator框架编写的仪器测试问题.
每当使用UiAutomator通过以下代码模拟按钮点击时:
onView(withId(R.id.button_activity_login)).perform(click())
Run Code Online (Sandbox Code Playgroud)
我遇到一个带有消息的AlertDialog
Detected problems with API compatibility (visit g.co/dev/appcompat for more info)
Run Code Online (Sandbox Code Playgroud)
这导致了这个链接:
这打破了UiAutomator测试,因为我的测试目前不考虑每个动作之间的额外AlertDialog.
这只发生在UiAutomator的按钮点击,而不是Espresso的.我相信UiAutomator可能会在引擎盖下使用一些反射来实现跨应用程序测试功能(事先不知道UI组件的文本或ID),而Espresso负责处理被测试应用程序内的所有内容.
这有点奇怪,因为UiAutomator是Google自己在开发者网站上建议的测试框架(https://developer.android.com/training/testing/ui-automator.html#ui-automator-apis).有没有人经历过或解决过以下问题?
我正在尝试编写可以部署在目标设备上的Android应用程序/服务.该应用程序可用作钩子来远程控制目标设备.从Jelly Bean版本开始,可以使用UI Automator实现,它提供了类似的功能.但是,似乎UI Automator只能通过ADB接口使用.在设备上运行的应用程序无法直接使用UI Automator(???).我试图找到一个可以在没有亚行帮助的情况下工作的解决方案.例如,挂钩可以将套接字监听为protobuf服务器.客户端可以向钩子发送命令以远程控制和设备.我查看了Andorid SDK源代码.看起来唯一的方法是使用android辅助功能API.我想知道是否有更好的方法?