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?
Asked
Active
Viewed 534 times
0
-
My test devices platformVersion=6.0.1,API Level=23 – JimWu Feb 22 '17 at 08:39
3 Answers
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.

akhilesh gulati
- 128
- 8
-
-
-
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
-
-
-
So there is any suggest of below my script to get toast message ? thanks – JimWu Feb 23 '17 at 08:34
-
-
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);

akhilesh gulati
- 128
- 8
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']"))));

Sravan
- 591
- 1
- 4
- 16