@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?
Here is an implementation code for this in python. It could be easily adopted to other languages
https://github.com/appium/appium/issues/968#issuecomment-75641576634
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.
https://github.com/bytedeco/javacpp-presets/tree/master/tesseract1.5k
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.
I found a way for python.
First install tesseract like this:
sudo apt-get install tesseract
Then you can use it as below:
tesseract example.jpg out
install pytesseract using pip:
pip install pytesseract
install pillow if not done yet:
pip install pillow
install tesseract-ocr:
sudo apt-get install tesseract-ocr
Then use it in your python code like this:
`from PIL import Image
import pytesseract
# path to your file
im = Image.open('test.png')
print pytesseract.image_to_string(im)`
Instead of checking and putting all energy just for sake of toast messages, the same we can easily cover using espresso at Unit/Integration test level. I believe that is better approach, We need to focus on critical functionality that really need to be automated instead of such trivial use cases. That way we can better categorize test cases also implement better test practices to our work.