Tag: android espresso

点击边界/坐标

我知道Espresso可以通过UiAutomator的方式点击 。 (x和y坐标)我已经通过文档阅读,但我似乎无法find它。 任何帮助表示赞赏。 谢谢 编辑 我发现这个链接 ,但没有例子如何使用它,我主要关心的是UiController是或如何使用它。

使用Espresso来测试可绘制的变化

我是新来Espresso测试,但似乎没有任何方法来测试可绘制的更改。 我有一个教程是一个ImageView Drawable幻灯片’塞进’一个半透明的TextView 。 在我的测试中,我想确保按下下一个按钮时,正确的Drawable已经插入教程的ImageView 。 没有默认的Matcher来检查Drawable ,所以我开始使用https://stackoverflow.com/a/28785178/981242写我自己的。 不幸的是,由于无法检索ImageView的活动Drawable的id,所以无法完成matchesSafely()实现。 这不是测试活动Drawable的唯一用例。 人们通常使用的工具是什么?

Espresso,当NestedScrollView或RecyclerView在CoordinatorLayout中时,滚动不起作用

它看起来像CoordinatorLayout打破了Espresso的行为,如scrollTo()或RecyclerViewActions.scrollToPosition() 。 问题与NestedScrollView 对于这样的布局: … … 如果我尝试使用ViewActions.scrollTo()滚动到NestedScrollView内的任何视图,我发现第一个问题是,我得到一个PerformException 。 这是因为这个动作只支持ScrollView而NestedScrollView不能扩展它。 这个问题的解决方法在这里解释,基本上我们可以在scrollTo()复制代码,并改变约束来支持NestedScrollView 。 这似乎工作,如果NestedScrollView不是在CoordinatorLayout但只要你把它放在一个CoordinatorLayout滚动操作失败。 问题与RecyclerView 对于相同的布局,如果我将NestedScrollView替换为RecyclerView ,滚动也会出现问题。 在这种情况下,我使用RecyclerViewAction.scrollToPosition(position) 。 不像NestedScrollView ,在这里我可以看到一些滚动发生。 但是,它看起来像滚动到错误的位置。 例如,如果我滚动到最后一个位置,它将显示倒数第二,但不是最后一个。 当我将RecyclerView移出CoordinatorLayout ,滚动就像它应该的那样工作。 目前,由于这个问题,我们无法为使用CoordinatorLayout的屏幕编写Espresso测试。 任何人遇到同样的问题或知道解决方法?

我如何从ID中提取文本?

在我的测试中, 我检查我登陆的每个页面的标题文本。 例如,我可以将文本与“登录”(例如R.id.toolbar_text )相匹配,查看它是否通过或失败。 但是,我想知道它是否失败,我在R.id.toolbar_text对象中有什么文本。 在Espresso Android中可以使用getText()选项吗? 我如何从ID中提取文本?

如何在android expresso的回收站视图下获取完整的文本

目前,我试图测试正确的数据是否显示为我的espresso UI测试的一部分,为此我有一个Recycler视图,在下面我有一堆线性布局,每个线性布局有一些文本视图,每个都有一个文本。 我正在寻找的是如何使用espresso函数将全部10个文本视图和线性布局的整个文本转换为字符串。 我正在使用kotlin作为我的编程语言。

如何使用espresso测试DeepLinks

我想为我所有的深层链接添加测试,启动它们并查看是否启动了所需的活动,并断言活动中显示的内容。 我该怎么做? 编辑 我结束了测试只是深入链接匹配,如https://medium.com/@singwai/testing-deep-linking-with-espresso-and-burst-5e1bdb3c5e29说。 在kotlin: @Throws(Exception::class) fun test_deepLink_isResolvedBy(url: String, canonicalActivityName: String) { val appContext = InstrumentationRegistry.getTargetContext() val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) val resolvedActivities = appContext.packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL) val resolverActivityMissing = resolvedActivities.none { it.activityInfo.packageName == appContext.packageName && it.activityInfo.name == canonicalActivityName } if (resolverActivityMissing) { fail(“$url is not resolved for $canonicalActivityName”) } } 然后我检查是否有活动解决我的url,并测试每个活动在自己的测试。

无法导入AndroidJUnit4和ActivityTestRule

我试图做一个仪器测试的类。 这个类在androidTest文件夹app\src\androidTest\java\… 。 但是, AndroidJUnit4和ActivityTestRule无法解析。 在import语句中, import android.support.test.runner.AndroidJUnit4单词“runner”是红色的。 考试class在Kotlin。 我试图删除它,并在Java中创建一个,但仍不能导入AdnroidJUnit4。 我读了一些类似的问题,但没有find解决我的情况。 这两个是项目和应用程序build.gradle文件:我的gradle文件有什么问题吗? 应用程序build.gradle: apply plugin: ‘com.android.application’ apply plugin: ‘kotlin-android’ apply plugin: ‘kotlin-kapt’ android { compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { applicationId “com.sample.me” minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName “1.0” archivesBaseName = “$applicationId-$versionName-$versionCode” testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner” // For room compat multiDexEnabled true javaCompileOptions { annotationProcessorOptions { arguments = […]

java.lang.NoClassDefFoundError:kotlin.jvm.internal.Intrinsics – newApplication

问题 我只是试图将自定义的AndroidJUnitRunner类从Java转换到Kotlin。 码 CustomTestRunner.java public class CustomTestRunner extends AndroidJUnitRunner { @Override public Application newApplication(ClassLoader cl, String className, Context context) throws IllegalAccessException, ClassNotFoundException, InstantiationException { return super.newApplication(cl, TestApp.class.getName(), context); } } CustomTestRunner.kt – (导致错误 – 请参阅下面的堆栈跟踪) class CustomTestRunner : AndroidJUnitRunner() { override fun newApplication(cl: ClassLoader, className: String, context: Context): Application { return super.newApplication(cl, TestApp::class.java.name, context) } […]

Android Espresso IntentsMatcher适用于新设备,但不算旧

我有一个Espresso单元测试,似乎在较新的设备上工作,但在API 17设备上失败。 这是测试: Intents.init() [… more setup] onView(withId(R.id.username)) .perform(typeText("username")) .perform(closeSoftKeyboard()) onView(withId(android.R.id.button1)).perform((click())) // This part fails intended(hasComponent(AcceptedActivity::class.java.name)) 错误是: android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents. 我已经试过在intended被调用之前睡了1000毫秒的线程,但这似乎没有帮助。 任何想法,为什么它成功的一些设备,但不是旧的?

应用; 曾经使用过不同的AppComponent; 在预先验证期间

我在一台设备上运行我的espresso测试时出现问题 – 出现以下错误: W/dalvikvm(10180): Class resolved by unexpected DEX: Lorg/ligi/passandroid/App;(0x43876120):0x660f9000 ref [Lorg/ligi/passandroid/AppComponent;] Lorg/ligi/passandroid/AppComponent;(0x43876120):0x64e2f000 W/dalvikvm(10180): (Lorg/ligi/passandroid/App; had used a different Lorg/ligi/passandroid/AppComponent; during pre-verification) D/AndroidRuntime(10180): Shutting down VM W/dalvikvm(10180): threadid=1: thread exiting with uncaught exception (group=0x433101a0) E/MonitoringInstrumentation(10180): Exception encountered by: Thread[main,5,main]. Dumping thread state to outputs and pining for the fjords. E/MonitoringInstrumentation(10180): java.lang.IllegalAccessError: Class ref in pre-verified […]