We can test without source code as well. Please check the below video for more details
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.
Hey guys, can anyone help with a Java example for 3. Increase resolutions of all screenshots ?
Thanks a lot,
What i have so far | File screen = ((TakesScreenshot) AndroidDriverAppium.driver).getScreenshotAs(OutputType.FILE);
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
try {
String result = instance.doOCR(screen);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
For who using Python, Can do that with the help of pyautogui Library this is piece of code that's help
toaster_image = toaster image file path
screenshot_image = screenshot image file path [ taken by Appium ]
from pyautogui import locate
class ClassName:
def compareImage (self, toaster_image, screenshot_image):
result = locate(str(toaster_image), str(screenshot_image))
if result is None:
return False
else:
return True
Has anyone have a clue to how to use Toast on Appium 1.6.3?
Android - Uiautomator2
Add ability to verify TOAST messages (these can't be interacted with, only
text retrieval allowed)
It looks like it's supported but there's very few threads out there that are helpful.
Hi Dear Hamza
I have follow your suggestion:
1-pip install tesseract
2-pip install pytesseract
3-pip install pillow
4-pip install tesseract-ocr
then I do not know how to start the codes to take capture of the elements inside the toast?
I might need your help on the detailed steps for that!!!
thanks very much and appreciated.
import org.bytedeco.javacpp.*;
import static org.bytedeco.javacpp.lept.*;
import static org.bytedeco.javacpp.tesseract.*;
public class BasicExample {
public static void main(String[] args) {
BytePointer outText;
TessBaseAPI api = new TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api.Init(null, "eng") != 0) {
System.err.println("Could not initialize tesseract.");
System.exit(1);
}
// Open input image with leptonica library
PIX image = pixRead(args.length > 0 ? args[0] : "/usr/src/tesseract/testing/phototest.tif");
api.SetImage(image);
// Get OCR result
outText = api.GetUTF8Text();
System.out.println("OCR output:\n" + outText.getString());
// Destroy used object and release memory
api.End();
outText.deallocate();
pixDestroy(image);
}
}
Appium Directly does not give any API to read toast message we need to do it using tess4j jar. First we need to take screen shot and then we need to read the text from screen shot using tess4j API.
static String scrShotDir = “screenshots”;
File scrFile;
static File scrShotDirPath = new java.io.File("./"+ scrShotDir+ “//”);
String destFile;
static AndroidDriver driver = null;
public String readToastMessage() throws TesseractException {
String imgName = takeScreenShot();
String result = null;
File imageFile = new File(scrShotDirPath, imgName);
System.out.println(“Image name is :” + imageFile.toString());
ITesseract instance = new Tesseract();
File tessDataFolder = LoadLibs.extractTessResources(“tessdata”); // Extracts
// Tessdata
// folder
// from
// referenced
// tess4j
// jar
// for
// language
// support
instance.setDatapath(tessDataFolder.getAbsolutePath()); // sets tessData
// path
result = instance.doOCR(imageFile);
System.out.println(result);
return result;
}
/**
- Takes screenshot of active screen
-
@return ImageFileName
*/
public String takeScreenShot() {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
SimpleDateFormat dateFormat = new SimpleDateFormat(“dd-MMM-yyyy__hh_mm_ssaa”);
new File(scrShotDir).mkdirs(); // Create folder under project with name
// “screenshots” if doesn’t exist
destFile = dateFormat.format(new Date()) + “.png”; // Set file name
// using current
// date time.
try {
FileUtils.copyFile(scrFile, new File(scrShotDir + “/” + destFile)); // Copy
// paste
// file
// at
// destination
// folder
// location
} catch (IOException e) {
System.out.println(“Image not transfered to screenshot folder”);
e.printStackTrace();
}
return destFile;
}
For more details Refer this video - https://www.youtube.com/watch?v=lM6-ZFXiSls20