0

I want to test "Add new item" activity in my application. When user fills data incorrectly and then press OK button - the toast (issues list) is displayed. My question is: How can I check that toast is not shown?

Thanks!

IgorOK
  • 1,652
  • 4
  • 18
  • 36

4 Answers4

2

I know its an old post but just in case anyone comes across this question, this is the a better way: solo.waitForText(text); // put here the toast text

Karim
  • 766
  • 7
  • 9
1
    //wait up to a second for the toast
    Date date = new Date();
    TextView toast;
    long elapsed;
    do{
        elapsed = new Date().getTime() - date.getTime();
        toast = (TextView)solo.getView(android.R.id.message);
    }while(elapsed<1000&&toast!=null);

    assertEquals(toast.getText().toString(), "Your ticket(s) has been purchased successfully");

This is an extension of the answer given by Aleksandr M in case the Toast takes a while to appear. For example, if the toast is the result of a time consuming operation.

Jose Ponce
  • 36
  • 3
0

Simply assign a flag variable where you handle the onClick event of your OK Button which issues the Toast. Set that flag to true,and then later check, if the flag is false, the Toast was never shown.

Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108
0

this one is works for me

TextView toast = (TextView) solo.getView(android.R.id.message);
assertEquals("toast is not showing", toast.getText().toString(), solo.getString(R.string.error_invalid_phone));
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143