Я написал этот код:
import java.awt.Image;
import java.awt.image.RenderedImage;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
// class and method declaration omitted
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//store screenshot at a specidfied location
File targetFile=new File("C:\\Users\\Srujan\\eclipse-workspace\\Batch98Appium\\images\\kiran.png");
FileUtils.copyFile(scrFile,targetFile );
System.out.println(targetFile.toString());
// URL url1 = new URL(targetFile.toString());
Image image = ImageIO.read(targetFile);
// we are asking it to recognize the characers present in the image and we are asking to it to read the contnet and to store the content in a variable
String s = new OCR().recognizeCharacters((RenderedImage) image);
//below cmd is simply printing the information
System.out.println("Text From Image : \n"+ s);
if (s.contains("Monitored switch is on")) {
System.out.println("toastr verified successfully");
} else {
System.out.println("toastr not verified successfully");
}
Я добавил jar как зависимости Maven:
Java OCR API 15.3.0.1
java-клиент 6.1.0
Появляется следующая ошибка компиляции:
Строка s = новое OCR (). Распознавать символы ((RenderedImage) изображение);
OCR () .Recog ... OCR не может быть преобразован в тип.