0

I tried to test getting toast message on android device with Appium 1.6.3, but it is disappointed for me,the rate to correct get toast is very low. Is there anyone help me?

JimWu
  • 5
  • 3

3 Answers3

0

1.It depends upon how dynamic data is coming. 2. If you want to get toast data while swiping than it becomes hard to get accurate data.

  • Displaying toast message after long press one button – JimWu Feb 23 '17 at 07:19
  • Now can not get toast message almost – JimWu Feb 23 '17 at 07:30
  • script as blew: toast.press(title).wait(1000).release().perform() driver.find_element_by_xpath(".//*[contains(@text,'message')]") – JimWu Feb 23 '17 at 07:31
  • on click take a screenshot and in that use OCR method to get text and than search for the desired string in the text got from the OCR – akhilesh gulati Feb 23 '17 at 07:38
  • Now appium1.6.3 has supported to identify toast message。 – JimWu Feb 23 '17 at 08:31
  • I want to solve this problem with new feature of appium 1.6.3 – JimWu Feb 23 '17 at 08:33
  • So there is any suggest of below my script to get toast message ? thanks – JimWu Feb 23 '17 at 08:34
  • No if you want I can help you out with what I am doing . – akhilesh gulati Feb 23 '17 at 11:51
  • Step 1:public static BufferedImage getTOASTSnapShot(AppiumDriver appiumDriver, String event) { BufferedImage originalImage=null; BufferedImage resizedImage=null; { try { System.out.println("Starting\n\n\n\n"); scrFile = ((TakesScreenshot) appiumDriver).getScreenshotAs(OutputType.FILE); System.out.println("after scrfile\n\n\n\n"); originalImage = ImageIO.read(scrFile); System.out.println("after originalFile\n\n\n"); } catch (Exception) { e.printStackTrace(); } } return originalImage; – akhilesh gulati Feb 24 '17 at 04:23
0
    Step 1:
public static BufferedImage getTOASTSnapShot(AppiumDriver appiumDriver, String event) {
            BufferedImage originalImage=null;
            BufferedImage resizedImage=null;
             {
                try {
                    System.out.println("Starting\n\n\n\n");
                     scrFile = ((TakesScreenshot) appiumDriver).getScreenshotAs(OutputType.FILE);
                     System.out.println("after scrfile\n\n\n\n");
                     originalImage = ImageIO.read(scrFile);
                     System.out.println("after originalFile\n\n\n");

                } catch (Exception) {
                    e.printStackTrace();
                }
            }
            return originalImage;


    Step 2 :
    public BufferedImage clickfortoast(String element)
        {
            try{
            WebElement webElement = appiumDriver.findElement(By.xpath(element));
            webElement.click();
        BufferedImage Toast=    Report.getTOASTSnapShot(appiumDriver, "Click: " );
            System.out.println("Click element: " +element);
            return Toast;
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
                return null;
            }
        }

    Step 3 :
    BufferedImage bufferedImage=dummyPage.clickfortoastimage(PROFILE_PAGE_LOGIN_TO_WALLET_PAGE_SIGN_IN);
            String result1=dummyPage.togettext_out_of_toast(bufferedImage);
            String TOAST_MESSAGE_WRONG_CREDENTIALS= "  " ;
            String mes2=" Toast message to be checked for  to be checked";
            boolean check = StringUtils.containsIgnoreCase(result1,mes1);
                System.out.println(check);
                boolean check1=StringUtils.containsIgnoreCase(result1,mes2);
0

Refer this sample code snippet to verify toast message using appium uiautomator2 driver

assertNotNull(wait.until(ExpectedConditions.presenceOfElementLocated(
            By.xpath("//*[@text='Clicked popup menu item Search']"))));

https://github.com/appium/java-client/blob/72b9e6a70d3ebfba9bf6b74813e9644b2f2a9e08/src/test/java/io/appium/java_client/android/UIAutomator2Test.java#L94

Sravan
  • 591
  • 1
  • 4
  • 16