Pre-requisites:
Appium version -> 1.13.0
Libraries: (Added to MAVEN Dependencies)
tess4j.jar -> 4.3.1
jna.jar -> 5.3.1
lept4j -> 1.10.0
Device Specification:
OS - Ubuntu 16.04
OS Type - 64 bit
ECLISPE CONSOLE:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'tesseract':
libtesseract.so: cannot open shared object file: No such file or directory
libtesseract.so: cannot open shared object file: No such file or directory
Native library (linux-x86-64/libtesseract.so) not found in resource path ([file:/home/<username>/workspace/Appium/target/classes/, ...])
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:302)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:455)
at com.sun.jna.Library$Handler.<init>(Library.java:192)
at com.sun.jna.Native.loadLibrary(Native.java:646)
at com.sun.jna.Native.loadLibrary(Native.java:630)
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:85)
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:42)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:426)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:222)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:194)
at mobile_app.Toastmessages.OCR(Toastmessages.java:80)
at mobile_app.Toastmessages.main(Toastmessages.java:46)
Suppressed: java.lang.UnsatisfiedLinkError: libtesseract.so: cannot open shared object file: No such file or directory
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:191)
... 11 more
Suppressed: java.lang.UnsatisfiedLinkError: libtesseract.so: cannot open shared object file: No such file or directory
at com.sun.jna.Native.open(Native Method)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:204)
... 11 more
CODE: (for capturing Screenshot & creating a folder)
public class Toastmessages{
public void takeScreenshot(){
// Create a folder name to store Screenshots.
String destDir = "Screenshots";
// Capture the Screenshot.
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// Set Date Format to set it as the Screenshot File Name.
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm--yyyy");
// Create folder under project (for storing the Screenshots)
new File(destDir).mkdirs();
// Create a file name using Date Format.
String destFile = dateFormat.format(new Date()) + ".png";
try {
FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
scrPath = destDir + "/" + destFile;
} catch (IOException e) {
e.printStackTrace();
}
}
public static String OCR(String Imgpath){
String result = null;
File imgfile = new File(Imgpath);
ITesseract inst = new Tesseract();
try {
result = inst.doOCR(imgfile);
} catch (Exception e) {
System.err.println(e.getMessage());
}
return result;
}
public static void main(){
Toastmessages tmsg = new Toastmessages();
tmsg.takeScreenshot();
String Text = OCR(scrPath);
System.out.println(Text);
Assert.assertTrue(Text.contains("Activity1 will continue"), "Activity will continue");
}
}