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!
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!
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
//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.
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.
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));