我想使用Espresso按下面按钮,但我不确定如何.我应该获得资源ID吗?或者如何设置AlertDialog的ID?
@RunWith(AndroidJUnit4.class)
public class ApplicationTest {
@Rule
public ActivityTestRule<LoadingActivity> mActivityRule =
new ActivityTestRule<>(LoadingActivity.class);
@Test
public void loginClickMarker() {
//Doesn't work:
onView(withText("GA NAAR INSTELLINGEN")).perform(click());
}
}
public class PopupDialog {
public static void showGPSIsDisabled(Context context, String msg, final PopupDialogCallback popupDialogCallback) {
new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.location_turned_off))
.setMessage(msg)
.setPositiveButton(context.getString(R.string.go_to_settings), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
popupDialogCallback.hasClicked();
}
}).show();
}
}
Run Code Online (Sandbox Code Playgroud)
android.support.test.espresso.NoMatchingViewException:找不到层次结构中的视图匹配:with text:is"GA NAAR INSTELLINGEN"
我正在使用Espresso和UIAutomator来编写我的测试用例.我正在测试外部存储权限,当它被拒绝时以及何时被允许.我有不同的测试用例,都需要在测试用例开始时撤销权限.但是,某些测试用例应该并且确实会导致授予权限,因此我需要在执行下一个测试时撤消权限.我一直在搜索,我遇到的最接近的事情是使用pm管理器执行adb shell命令来撤销权限.但是,通过这样做,我将收到以下错误,由于"进程崩溃",Instrumentation运行失败.有没有什么办法可以确保在每个测试用例开始时撤销权限?如果没有,如何解决有关测试权限的问题?提前谢谢你的帮助!
这是我目前在每个测试用例之前撤消权限的代码片段(不起作用):
@Before
public void setUp() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getInstrumentation().getUiAutomation().executeShellCommand(
"pm revoke " + getTargetContext().getPackageName()
+ " android.permission.WRITE_EXTERNAL_STORAGE");
}
}
Run Code Online (Sandbox Code Playgroud)
尝试使用上面的代码段撤消权限时出现相应的错误消息:
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Process crashed.''.
Run Code Online (Sandbox Code Playgroud)
android android-testing android-permissions android-espresso android-uiautomator
我的理解是UIAutomator无法在uiautomatorviewer中自动化任何NAF = true的元素.我搜索了高低,但我不能为我的生活找到NAF代表的东西.有人知道吗?
每当我尝试UiAutomation在任何测试中使用时getInstrumentation().getUiAutomation(),该进程都会因此异常而崩溃:
java.lang.SecurityException: Permission Denial: getIntentSender() from pid=30334, uid=2000, (need uid=1000) is not allowed to send as package android
at android.os.Parcel.readException(Parcel.java:1540)
at android.os.Parcel.readException(Parcel.java:1493)
at android.app.IUiAutomationConnection$Stub$Proxy.disconnect(IUiAutomationConnection.java:225)
at android.app.UiAutomation.disconnect(UiAutomation.java:240)
at android.app.Instrumentation.finish(Instrumentation.java:197)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:575)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1837)
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?我正在使用Gradle通过Android Studio,尝试各种版本,直接调用它adb,即使没有任何外部依赖(显然至少有SDK 18)...总是崩溃.
这是我发现的唯一官方示例:https://www.youtube.com/watch?v =_SlBHUW0ybM
当我在Android Studio中运行检测测试时,我发现应用程序之后仍然在设备上.但是我无法从使用gradlew的命令行中做到这一点.我的目的是运行测试,保存例如/ data/data/MyApp/cache/screenshots中的屏幕截图,然后下载这些屏幕截图adb pull.
./gradlew connectedAndroidTest
Run Code Online (Sandbox Code Playgroud)
导致应用程序被卸载.我也试过了
./gradlew connectedAndroidTest -x uninstallAndroidTest
Run Code Online (Sandbox Code Playgroud)
但这没有任何区别.导致卸载的原因是什么,我该如何避免?
我想通过使用从浏览器获取文本 uiautomator
我该怎么做?
我已经解析了结构,chrome只有android.View.view
我试过使用getText()函数,但它没有帮助.
任何帮助赞赏.
也许有人知道如何通过调用一些chrome实例...或任何其他方法来实现它.
任何解决方案,有信息,如何将android浏览器页面保存为html /文本就足够了,或者如何选择整页.(触摸/长按文字除外).

我正在创建一个自动化测试项目,我有问题从AutoCompleteTextView中选择项目.
您可以看到它的快照和视图[全部展开].AutoCompleteTextView的下拉列表不会出现在视图树中,也无法使用鼠标进行选择.
我尝试过以下方法从AutoCompleteTextView适配器中选择项目表单:
UiScrollable locationList = new UiScrollable(new UiSelector().scrollable(true));
locationList.scrollTextIntoView(location);
UiScrollable locationList = new UiScrollable(locationEditText.getSelector());
locationList.scrollTextIntoView(location); 这里的locationEditText是我的AutoCompleteTextView
UiObject selectedLocation = locationList.getChild(new UiSelector().text(location));
selectedLocation.click(); 从locationList,它不会选择传递字符串的项目.
editLocationResId = "android:id/text1";
UiObject selectedLocation = new UiObject(new UiSelector().resourceId(editLocationResId));
selectedLocation.click(); 来自adpter textview的id也不起作用.
任何人都可以帮我从uiautomator中的AutoCompleteTextView中选择项目吗?或者更多的方法获得欲望输出.
如何使用UiAutomator API关闭特定的Android应用程序?就像手动按下"最近"按钮并滑动要关闭的应用程序一样.
我想运行一个参数化的Instrumentation Test,它具有不同的语言环境,可以使用所有支持的语言运行相同的测试.
观察到的行为是,对于每个后续运行,活动都将具有第一次测试运行的本地化标题.因此,无论我的手机使用哪种语言,标题都将针对第一个参数化测试运行进行正确本地化,并且对于每个后续版本仍然相同.
虽然覆盖区域设置本身适用于任何资源,它会工作只有一次的活动标题,如果设置由AndroidManifest.xml.
活动似乎得到了他们的标题设置attach,无论调用附件似乎是缓存应用程序首次启动的区域设置中的标题.
final void attach(Context context, ActivityThread aThread,
Instrumentation instr, IBinder token, int ident,
Application application, Intent intent, ActivityInfo info,
---> CharSequence title, Activity parent, String id,
NonConfigurationInstances lastNonConfigurationInstances,
Configuration config, String referrer, IVoiceInteractor voiceInteractor) {
attachBaseContext(context);
Run Code Online (Sandbox Code Playgroud)
由于资源总是被正确地本地化,因此解决方法是调用setTitle(R.string.title)或只是getActionBar().setTitle(R.string.setTitle),但我不想仅为了测试目的而更改活动.
问题:如何在第一次测试运行后更改活动的标题?如上所述,这似乎被缓存并且没有正确更新,并且杀死应用程序以重新启动它将无法进行检测测试.
整个测试项目可以在GitHub上找到(Localization.java包含当前失败的单元测试和此处描述的问题)并且正在使用参数化单元测试UIAutomator.
我们的目标是在不了解应用程序本身(UIAutomator)的情况下拍摄一批截图,并且不需要为测试修改应用程序.
我在每次测试之前都成功地更改了语言环境,并通过执行以下操作正确显示了我的文本,同时我还有多个断言确保资源实际上是正确的语言环境.
public LocalizationTest(Locale locale) …Run Code Online (Sandbox Code Playgroud) android android-activity android-testing android-instrumentation android-uiautomator
当我在命令提示符下运行以下命令时,我收到以下错误。
命令: C:\Users\ob>uiautomatorviewer
错误:
-Djava.ext.dirs=..\lib\x86_64;..\lib is not supported.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Run Code Online (Sandbox Code Playgroud)