2017-05-04 4 views
0

Je dois expresso vérifier un message toast pop-up lorsque l'utilisateur cliquez sur un bouton. par exemple. il affichera 'ajouté au favori' ou 'supprimer du favori', les chaînes qui sont en dessous de string.xml. Le message de toast peut varier, donc je peux seulement vérifier si le message de toast contientChaîne ... Ci-dessous j'ai ajouté le code d'espresso que j'ai essayé mais cela ne fonctionne pas. Quelqu'un a une meilleure idée?expresso toast message message pour le texte du message partiel

onView(withText(containsString("added to favorite"))).inRoot(withDecorView(not(mActivityTestRule.getActivity().getWindow().getDecorView()))).check(matches(isDisplayed())); 

//string.xml 
<string name="message_add_favorite">%1$s %2$s added to favorite.</string> 
    <string name="message_remove_favorite">%1$s %2$s removed from favorite</string> 

//logcat 
Started running tests 

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: a string containing "added to favorite" 

View Hierarchy: 
+>LinearLayout{id=-1, visibility=VISIBLE, width=749, height=129, has-focus=false, has-focusable=false, 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, x=0.0, y=0.0, child-count=1} 
| 
+->AppCompatTextView{id=16908299, res-name=message, visibility=VISIBLE, width=669, height=49, has-focus=false, has-focusable=false, 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, x=40.0, y=40.0, text=Pizza Smith @ Galaxis removed from favourites, input-type=0, ime-target=false, has-links=false} 
| 
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 com.korvac.liquid.presentation.intro.DiscountTest.test_08FavoriteTest(DiscountTest.java:161) 
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:1846) 
+0

exactement ce qui ne fonctionne pas? Quelle exception obtenez-vous? (Je l'ai essayé dans une application de démonstration et il semble fonctionner très bien) – stamanuel

+0

@stamanuel ajouter dans logcat, pendant le test, je peux voir le message toast avec xxx ajouté à la fenêtre pop-up – kggoh

Répondre

0

Vous pouvez essayer cette onView(allOf(withText(containsString("added to favorite")))).check(matches(isDisplayed()));