1

Like many others, i've been trying to solve the problem of toast accumulation.

I finally decided to keep track of the current displayed toast and cancel it when another arrives (there's some more logic involved), but i could have use only one toast and change it message. What i want to know is this... Is there a way to TEST this behaviour? Im currently using Robotium and tried different things, but unfortunately the methods to check for toasts (solo.waitForText and solo.searchForText) aren't helping me as i can't make something like

assertTrue(solo.waitForText(text));
//maybe even some sleep here
assertFalse(solo.searchText(text);

Has anyone done something like this? Is there a way to test this using Robotium? using somethig else?

Community
  • 1
  • 1
acrespo
  • 1,134
  • 1
  • 10
  • 33
  • what do you mean aren't helping? does the test fail? what happens? – user2511882 Jan 21 '14 at 21:01
  • Exactly. Sorry, test fails at second assert, as it matches the text from the toast, when you would want the toast gone. Does it make sense? – acrespo Jan 21 '14 at 22:02
  • Wait until the toast has disappeared before doing the second assert. Something like: while(solo.waitForText("my toast"); and then assertFalse(..) – Renas Jan 22 '14 at 06:06
  • Actually while(solo.searchText("my toast"); would be better to use in this case. – Renas Jan 22 '14 at 06:11
  • Mmm, interesting... have you tried that approach? I mean in working piece of code. I wonder whether if that `while` might catch many accumulated toast if they were to pop up... Because that's what we are testing against. – acrespo Jan 22 '14 at 14:09

1 Answers1

2

You can use a robotium condition to wait for the text to disappear. Here's a method I use for that.

private void waitForTextToDisappear(final String text, int wait) {
    Condition textNotFound = new Condition() {

        @Override
        public boolean isSatisfied() {
            return !solo.searchText(text);
        }
    };
    assertTrue("Text gone: " + text, solo.waitForCondition(textNotFound, wait));
}
Dave C
  • 928
  • 6
  • 12