Quality Testing

Quality is delighting customers

Can you please help me, how to verify Toast Message, I have written below code. 
Please check and correct me, anything wrong.
GetToastMessage.java
public class GetToastMessage extends CaptureScreenshot
{
AndroidDriver<AndroidElement> driver;
String destFile = null;
static String scrShotDir = "screenshots";
File scrFile;
static File scrShotDirPath = new java.io.File("./"+scrShotDir+"//");
public void imageconversion(String filePath) throws IOException, TesseractException       
    {
Screenshot image = new Screenshot();
image.takeScreenShot(driver);
ITesseract instance = new Tesseract();
//file path is the image which you need to convert to text
File imageFile = new File("D:\\screenshots");
BufferedImage img = null;
img = ImageIO.read(imageFile);
BufferedImage blackNWhite = new BufferedImage(img.getWidth(),img.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
Graphics2D graphics = blackNWhite.createGraphics();
graphics.drawImage(img, 0, 0, null);
//path where your downloaded tessdata exists
        instance.setDatapath("E://ocr");
        
        //What language you required to convert,( e.g. English)
        instance.setLanguage("eng"); 
        
        String result = instance.doOCR(blackNWhite);
        System.out.println(result);
        
       }
}
Screenshot.java
public class Screenshot 
{
static String scrShotDir = "screenshots";
File scrFile;
String destFile;
static File scrShotDirPath = new java.io.File("./"+scrShotDir+"//");
public String takeScreenShot(AndroidDriver<AndroidElement> driver) 
{
File scrFile = driver.getScreenshotAs(OutputType.FILE);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy_hh_mm_ssaa");
new File(scrShotDir).mkdir();
destFile = dateFormat.format(new Date()) + ".png";
try 
{
FileUtils.copyFile(scrFile, new File(scrShotDir + "/" + destFile));
}catch (IOException e)
{
System.out.println("Image not transfered to sceenshot folder"+"\n");
e.printStackTrace();
}
return destFile;
}
}
TestCase.java (added below code)
String ocrText = null;
GetToastMessage toastMessage = new GetToastMessage();
toastMessage.imageconversion(ocrText);
When I ran the test case, it is throwing null pointer exception @ this line  "  File scrFile = driver.getScreenshotAs(OutputType.FILE) " in Screenshots class.

Views: 243

Reply to This

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service