Android Espresso perform(click())不';行不通
我正在使用浓缩咖啡和mockito为Android应用程序编写测试。在我尝试对视图或按钮执行单击操作的少数情况下,在测试完成之前,单击操作不会注册 在活动中:Android Espresso perform(click())不';行不通,android,android-espresso,Android,Android Espresso,我正在使用浓缩咖啡和mockito为Android应用程序编写测试。在我尝试对视图或按钮执行单击操作的少数情况下,在测试完成之前,单击操作不会注册 在活动中: public void leavePageClicked(View v) { Log.i(TAG, "Leaving page with url: "+url); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); start
public void leavePageClicked(View v) {
Log.i(TAG, "Leaving page with url: "+url);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
}
布局:
<Button
android:id="@+id/leaveApplicationButton"
style="@style/purple_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginStart="40dp"
android:layout_marginTop="45dp"
android:onClick="leavePageClicked"
android:text="@string/leave_application"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/urlTextView"/>
测试:
@规则
公共意图测试规则意图测试规则=
新的IntentsTestRule(LeavingPageActivity.class,true,false);
@以前
公共作废设置(){
Context targetContext=InstrumentationRegistry.getInstrumentation()
.getTargetContext();
意向意向=新意向(targetContext,LeavingPageActivity.class);
intent.putExtra(LeavingPageActivity.EXTRA_URL,“http://www.google.com");
intentsTestRule.launchActivity(intent);
}
@之后
公共空间清理(){
intentsTestRule.finishActivity();
}
@试验
public void testLeavePageClick(){
有意(
hasAction(意图、行动和视图)
)).响应(新的Instrumentation.ActivityResult(Activity.RESULT_OK,null));
onView(带id(R.id.leaveApplicationButton)).perform(单击());
预期(全部)(
hasAction(意图、行动和视图),
hasData(“http://www.google.com")
));
}
Log.i(标记,“使用url离开页面:“+url”);从来没有用logcat写过
11-22 13:31:36.339 24319-24337/com.app.test I/TestRunner: started: testLeavePageClick(com.app.test.LeavingPageActivityTest)
11-22 13:31:36.339 24319-24319/com.app.test I/MonitoringInstr: Activities that are still in CREATED to STOPPED: 0
11-22 13:31:36.339 24319-24337/com.app.test I/ActivityTestRule: Launching activity: ComponentInfo{com.app.test/com.app.test.activities.LeavingPageActivity}
11-22 13:31:36.339 24319-24381/com.app.test D/MonitoringInstr: execStartActivity(context, ibinder, ibinder, activity, intent, int, bundle
11-22 13:31:36.379 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: PRE_ON_CREATE
11-22 13:31:36.389 24319-24319/com.app.test W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: CREATED
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: STARTED
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: RESUMED
11-22 13:31:36.569 24319-24319/com.app.test D/Atlas: Validating map...
11-22 13:31:36.599 24319-24383/com.app.test I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: TEST SBA AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.00.006.014 + c1105519 ()
OpenGL ES Shader Compiler Version: E031.25.03.00
Build Date: 01/23/15 Fri
Local Branch:
Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.00.006.014
Local Patches: NONE
Reconstruct Branch: NOTHING
11-22 13:31:36.699 24319-24337/com.app.test D/InputManagerEventInjectionStrategy: Creating injection strategy with input manager.
11-22 13:31:36.729 24319-24319/com.app.test I/ViewInteraction: Performing 'single click' action on view with id: com.app.test:id/leaveApplicationButton
11-22 13:31:37.000 24319-24319/com.app.test I/ViewInteraction: Checking 'android.support.test.espresso.intent.Intents$2@148c4653' assertion on view is a root view.
11-22 13:31:37.040 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: PAUSED
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: failed: testLeavePageClick(com.app.test.LeavingPageActivityTest)
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: ----- begin exception -----
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents.
IntentMatcher: (has action: is "android.intent.action.VIEW" and has data: is <http://www.google.com>)
Matched intents:[]
Recorded intents:[]
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:580)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:314)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
at android.support.test.espresso.intent.Intents.intended(Intents.java:185)
at android.support.test.espresso.intent.Intents.intended(Intents.java:167)
at com.app.test.LeavingPageActivityTest.testLeavePageClick(LeavingPageActivityTest.java:74)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at android.support.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1976)
Caused by: junit.framework.AssertionFailedError: Wanted to match 1 intents. Actually matched 0 intents.
IntentMatcher: (has action: is "android.intent.action.VIEW" and has data: is <http://www.google.com>)
Matched intents:[]
Recorded intents:[]
at junit.framework.Assert.fail(Assert.java:50)
at android.support.test.espresso.intent.VerificationModes$Times.verify(VerificationModes.java:85)
at android.support.test.espresso.intent.Intents.internalIntended(Intents.java:280)
at android.support.test.espresso.intent.Intents$2.check(Intents.java:188)
at android.support.test.espresso.ViewInteraction$SingleExecutionViewAssertion.check(ViewInteraction.java:415)
at android.su
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: ----- end exception -----
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: finished: testLeavePageClick(com.app.test.LeavingPageActivityTest)
11-22 13:31:36.339 24319-24337/com.app.test I/TestRunner:started:testLeavePageClick(com.app.test.LeavingPageActivityTest)
11-22 13:31:36.339 24319-24319/com.app.test I/MonitoringInstr:仍在创建中的活动已停止:0
11-22 13:31:36.339 24319-24337/com.app.test I/ActivityTestRule:启动活动:组件信息{com.app.test/com.app.test.activities.LeavingPageActivity}
11-22 13:31:36.339 24319-24381/com.app.test D/MonitoringInstr:execStartActivity(上下文、ibinder、ibinder、活动、意图、int、bundle
11-22 13:31:36.379 24319-24319/com.app.test D/LifecycleMonitor:生命周期状态更改:com.app.test.activities。LeavingPageActivity@2e635cc7in:在创建时预先设置
11-22 13:31:36.389 24319-24319/com.app.test W/art:Android 4.1之前的方法Android.graphics.PorterDuffColorFilter Android.support.graphics.drawable.VectorDrawableCompat.UpdatentFilter(Android.graphics.PorterDuffColorFilter,Android.content.res.ColorStateList,Android.graphics.PorterDuff$Mode)将错误地重写android.graphics.drawable.drawable中的包私有方法
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor:生命周期状态更改:com.app.test.activities。LeavingPageActivity@2e635cc7在:创建
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor:生命周期状态更改:com.app.test.activities。LeavingPageActivity@2e635cc7在:开始
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor:生命周期状态更改:com.app.test.activities。LeavingPageActivity@2e635cc7在:恢复
11-22 13:31:36.569 24319-24319/com.app.test D/Atlas:验证地图。。。
11-22 13:31:36.599 24319-24383/com.app.test I/Adreno EGL::EGL 1.4高通公司构建:测试SBA AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.00.006.014+c1105519()
OpenGL ES着色器编译器版本:E031.25.03.00
建造日期:2015年1月23日星期五
本地分行:
远程分支:refs/tags/AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.00.006.014
本地修补程序:无
重建分支:没有
11-22 13:31:36.699 24319-24337/com.app.test D/InputManagerReventInjectionStrategy:使用input manager创建注入策略。
11-22 13:31:36.729 24319-24319/com.app.test I/ViewInteraction:对id为com.app.test:id/leaveApplicationButton的视图执行“单击”操作
11-22 13:31:37.000 24319-24319/com.app.test I/ViewInteraction:检查“android.support.test.espresso.intent.Intents”$2@148c4653'视图上的断言是根视图。
11-22 13:31:37.040 24319-24319/com.app.test D/LifecycleMonitor:生命周期状态更改:com.app.test.activities。LeavingPageActivity@2e635cc7在:暂停
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner:失败:testLeavePageClick(com.app.test.LeavingPageActivityTest)
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner:----开始异常-----
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner:android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError:想要匹配1个意图。实际匹配0个意图。
IntentMatcher:(具有操作:is“android.intent.action.VIEW”,并且具有数据:is)
匹配意图:[]
记录的意图:[]
位于dalvik.system.VMStack.getThreadStackTrace(本机方法)
位于java.lang.Thread.getStackTrace(Thread.java:580)
位于android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
位于android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
位于android.support.test.espresso.ViewInteraction.waitFor和HandleInteractionResults(ViewInteraction.java:314)
11-22 13:31:36.339 24319-24337/com.app.test I/TestRunner: started: testLeavePageClick(com.app.test.LeavingPageActivityTest)
11-22 13:31:36.339 24319-24319/com.app.test I/MonitoringInstr: Activities that are still in CREATED to STOPPED: 0
11-22 13:31:36.339 24319-24337/com.app.test I/ActivityTestRule: Launching activity: ComponentInfo{com.app.test/com.app.test.activities.LeavingPageActivity}
11-22 13:31:36.339 24319-24381/com.app.test D/MonitoringInstr: execStartActivity(context, ibinder, ibinder, activity, intent, int, bundle
11-22 13:31:36.379 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: PRE_ON_CREATE
11-22 13:31:36.389 24319-24319/com.app.test W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: CREATED
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: STARTED
11-22 13:31:36.559 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: RESUMED
11-22 13:31:36.569 24319-24319/com.app.test D/Atlas: Validating map...
11-22 13:31:36.599 24319-24383/com.app.test I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: TEST SBA AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.00.006.014 + c1105519 ()
OpenGL ES Shader Compiler Version: E031.25.03.00
Build Date: 01/23/15 Fri
Local Branch:
Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.00.006.014
Local Patches: NONE
Reconstruct Branch: NOTHING
11-22 13:31:36.699 24319-24337/com.app.test D/InputManagerEventInjectionStrategy: Creating injection strategy with input manager.
11-22 13:31:36.729 24319-24319/com.app.test I/ViewInteraction: Performing 'single click' action on view with id: com.app.test:id/leaveApplicationButton
11-22 13:31:37.000 24319-24319/com.app.test I/ViewInteraction: Checking 'android.support.test.espresso.intent.Intents$2@148c4653' assertion on view is a root view.
11-22 13:31:37.040 24319-24319/com.app.test D/LifecycleMonitor: Lifecycle status change: com.app.test.activities.LeavingPageActivity@2e635cc7 in: PAUSED
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: failed: testLeavePageClick(com.app.test.LeavingPageActivityTest)
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: ----- begin exception -----
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents.
IntentMatcher: (has action: is "android.intent.action.VIEW" and has data: is <http://www.google.com>)
Matched intents:[]
Recorded intents:[]
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:580)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:314)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
at android.support.test.espresso.intent.Intents.intended(Intents.java:185)
at android.support.test.espresso.intent.Intents.intended(Intents.java:167)
at com.app.test.LeavingPageActivityTest.testLeavePageClick(LeavingPageActivityTest.java:74)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at android.support.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1976)
Caused by: junit.framework.AssertionFailedError: Wanted to match 1 intents. Actually matched 0 intents.
IntentMatcher: (has action: is "android.intent.action.VIEW" and has data: is <http://www.google.com>)
Matched intents:[]
Recorded intents:[]
at junit.framework.Assert.fail(Assert.java:50)
at android.support.test.espresso.intent.VerificationModes$Times.verify(VerificationModes.java:85)
at android.support.test.espresso.intent.Intents.internalIntended(Intents.java:280)
at android.support.test.espresso.intent.Intents$2.check(Intents.java:188)
at android.support.test.espresso.ViewInteraction$SingleExecutionViewAssertion.check(ViewInteraction.java:415)
at android.su
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: ----- end exception -----
11-22 13:31:37.050 24319-24337/com.app.test I/TestRunner: finished: testLeavePageClick(com.app.test.LeavingPageActivityTest)
try {
android.support.test.espresso.intent.Intents.init();
...
scrollView.scrollTo(0, viewToScrollTo.getTop());
sleep(1000);
onView(withId(R.id.view_quote_button)).check(matches(isDisplayed()));
onView(withId(R.id.view_quote_button)).perform(click());
android.support.test.espresso.intent.Intents.intended(allOf(
hasAdultsQuoteEntry(adultCount),
hasChildrenEntry(childrenCount)));
...