Verifying Toast

Hi,
I am new to appium and automation testing.
i’m testing a native android app and in the app there are a lot of Toast reactions.
is there a way to verify those toasts via appium?
I heard it can be done by moving to selendroid mode. is is true?
and if it is, how do i do it?

I was able to get toast messages working via the following general steps:

  1. Perform action to trigger the toast message to appear on screen
  2. Take x number of screenshots
  3. Increase resolutions of all screenshots
  4. Use tessearct OCR to detect the toast message.

@alangithubtrader: Can you please explain in depth how to achieve that?

I am assuming you need help on step2?

I have a configurable value for taking the number of screenshots, let’s call this ‘x’.

Then all I do is simply loop and take x number of screenshots after step1. Then I save all these screenshots into a directory.

The reason why I take all the screenshots first and then save the screenshots after loop is done is to increase my chance of catching the toast message in my screenshots.

Does this help?

Yes thanks. It did helped.
One last question.
How to achieve step 4?

For step 4,

these links really helped me.

https://code.msdn.microsoft.com/windowsdesktop/How-to-use-Tessnet2-library-716be12f

1 Like

Here is an implementation code for this in python. It could be easily adopted to other languages

Please explain, how you used Tesseract OCR. I have downloaded but not not knowing that how to use?

Please see the link i posted above. And if you already did, what specific part of using the Tesseract OCR you’re having trouble?

I have installed Tessract ocr (version: 3.02.02). Now how i have to write in code? I am using appium+java.

After you imported the OCR lib, are you seeing the new methods provided by the Tesseract OCR library?

Hi Gourav ,

Did you find the Code in Java for verifying toast messages using Tessract ocr ?
If found could you please share the code as I am unable to get it.

Here is the Java Implementation. I personally used it across platforms and it worked like a charm.

2 Likes

HI Sahajamit,

Are your code successful for verifying toast message.

Yes It worked for me.

toast is system property,not handled by application. Toast messages can be instrument using espresso which is different instrumentation.
If test toast verification is on very high priority then you should not use appium or Uiautomator. Also one suggestion these kind of verifications need to be done in UI unit testing using Espresso or other tools which are much powerful tool than Appium (Provided you have access of application’s source code). Automation suites need to focus on regression e2e functionality, not on toast message or UI verification part.

1 Like

Priyank, I dont have source code of application? so cant we test toast?

We can test without source code as well. Please check the below video for more details

1 Like

is this possible if we use python?

What is Verify() method doing? :slight_smile: