2017-05-30 4 views
0

Salut je commence une activité d'un autre en cliquant sur le bouton dans l'espresso. Tout fonctionne bien à la première fois et quand la même méthode est appelée deuxième fois je reçois une erreur comme celle-ci s'il vous plaît aidez-moi à résoudre ce problème.

C'est la méthode que je fais appel à deux endroits différents:

private void sendMailTest() { 

     onView(withId(R.id.bill_view_send_mail)).perform(scrollTo(), click()); 
//  Intents.init(); 
//  activityIntentsTestRule.launchActivity(new Intent()); 
     intended(hasComponent(SearchBillSendMailActivity.class.getName())); 
//  Intents.release(); 
     pauseTestFor(5000); 
} 

C'est ce que je reçois:

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 2 intents. 

IntentMatcher: has component: has component with: class name: is "com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity" package name: an instance of java.lang.String short class name: an instance of java.lang.String 

Matched intents: 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]]) 

Recorded intents: 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.AppointmentDiscountActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{amount=200.0, nameType=1}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2830}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2831}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2832}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2833}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]]) 
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:92) 
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56) 
at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184) 
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:158) 
at android.support.test.espresso.intent.Intents.intended(Intents.java:187) 
at android.support.test.espresso.intent.Intents.intended(Intents.java:169) 
at com.wenzins.lab.TestPrepareBill.sendMailTest(TestPrepareBill.java:341) 
at com.wenzins.lab.TestPrepareBill.validateCardWithoutAddingItems(TestPrepareBill.java:502) 
at com.wenzins.lab.TestPrepareBill.verifyInputs(TestPrepareBill.java:303) 
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.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55) 
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270) 
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:59) 
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262) 
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1867) 
Caused by: junit.framework.AssertionFailedError: Wanted to match 1 intents. Actually matched 2 intents. 

IntentMatcher: has component: has component with: class name: is "com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity" package name: an instance of java.lang.String short class name: an instance of java.lang.String 

Matched intents: 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]]) 

Recorded intents: 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.AppointmentDiscountActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{amount=200.0, nameType=1}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2830}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2831}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2832}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2833}]]) 
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]]) 
at junit.framework.Assert.fail(Assert.java:50) 
at android.support.test.espresso.intent.VerificationModes$Times.verify(VerificationModes.java:87) 
at android.support.test.espresso.intent.Intents.internalIntended(Intents.java:282) 
at android.support.test.espresso.intent.Intents$2.check(Intents.java:190) 
at android.support.test.espresso.ViewInteraction$2.run(ViewInteraction.java:170) 
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
at android.os.Handler.handleCallback(Handler.java:815) 
at android.os.Handler.dispatchMessage(Handler.java:104) 
at android.os.Looper.loop(Looper.java:194) 
at android.app.ActivityThread.main(ActivityThread.java:5637) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 

Répondre

0

Il est difficile de vous donner une réponse précise sans voir le test Espresso en question, mais si votre clic sur un bouton déclenche l'intention de com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity, ce comportement est totalement logique.

Vous pouvez résoudre le problème dans l'une de plusieurs façons:

Utilisez les temps (int fois) VerificationMode dans le cadre de l'appel Intents.intended() ou:

appel Intents.release() après la vérification de votre intention a été déclenchée après le premier clic sur le bouton.

De toute façon, postez votre test et l'état final souhaité pour une meilleure réponse.

+0

ouais j'ai essayé les deux façons mais j'ai quand même eu la même erreur. –

+0

s'il vous plaît voir les questions mises à jour –

+0

Le test complet n'est pas publié. La méthode affichée n'est pas un test complet. Quelle règle de test utilisez-vous? Y a-t-il des @ Avant/@ Après? Quoi d'autre se passe-t-il dans le cadre de ce test? Quel est l'onclick pour le bouton? – jdonmoyer