This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
45 / 45
Jan 2019
5 months later
1 month later

Hello
I have try the above link and created the example with tess4j 3.2.1. when i execute the example it take the screenshot and convert the image to text but not the toast message of the image .please help me out ?
Below is image and output result:
1

27 days later

Has anyone have a clue to how to use Toast on Appium 1.6.3?

Appium release notes59

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.

Please refer this sample java test case to verify toast message.

13 days later
12 days later

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.

1 month later

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);
}

}

Can you please the detailed video where the dll placing is also defined? this video has a very limited understanding but didn't worked when i tried this

7 months later

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

6 months later

How to verify toast messages using ruby lib in BDD framework ?

In Ruby I’m looking for toast like this:

toast = driver.find_element(:xpath, "//android.widget.Toast[1]")

then you can use .text to get toast text like:

if toast.text == "Hello"

I am Can verify toast with this, But if i use uiautomator2, I am not able o identify few elements

22 days later

I’m using:
io.appium 6.1.0
selenium-java 3.11.0
guava 24.0-jre.

Try this:
String xmlFormat = driver.getPageSource();
if(xmlFormat.contains(“Your Toast Message Here”)){
System.out.println("Toast message displayed: "+yourToastMessage);
}

  • The first line of instruction will give the xml format of the app page. In this, I got the toast message in one of the tags. It works for me.
    You can put the getPageSource instruction after the desired activity, and since toast messages generally have 2 seconds of timeOut, so the above method will work.

I tried your method but for me is not working.
I don’t think you have a toast message there as far as the getPageSource will find the message you looking for.
Normally if getPageSource is finding the element/text we should be able to identify the element like the rest elements.

Hi @Zuzeac,

We need to check if the xmlFormat string contains the toast message. Whether getPageSource() method is able to capture the exact XML DOM at the time of the toast message getting displayed is dependent on how you tweak wait times to ensure the exact toast message is captured.
You need to give some TimeOut.MILLISECONDS.sleep(200) or 500 before the page source is captured.
Also, the capture has to be done before the toast message vanishes away.
I think the standard of any toast message time out is 2 seconds.

Please let me know after doing it if you are still facing any problems.
More than this, I need to see your code what you are exactly trying to achieve.

Thanks … Cheers :slight_smile:

1 month later

Try this:

long startTime = System.currentTimeMillis(); //fetch starting time
boolean neededStatus;
do{
xmlFormat = driver.getPageSource();
neededStatus = xmlFormat.contains(“Needed”);
}while(!(neededStatus) && (((System.currentTimeMillis()-startTime) <= (5*1000))));

‘5’ is for 5 seconds to wait till the toast message is displayed. Generally standard timeout of a toast message is 2 seconds. You can keep this value around 2 to 5 seconds.

Let me know if this works !

4 months later