Thanks to @sam69 this is how I could achieve verifying text inside toast message
-
Tried to capture element identifier through Appium Desktop but it’s not possible as Toast Message stays for very short time and it’s not possible to capture exactly in Appium Desktop inspector
-
With help of Charles, slowed down network to minimum speed
-
Later used ARC technique to get page source when toast message is shown
If you don’t know about ARC, do check my blog “https://vikramviknowledgesharing.wordpress.com/2017/01/01/appium-mobile-automation/” > section “>>> Method 2: ( Appium Ruby Console ) <<<”
-
below is the code to get page source
public boolean isToastMessageDisplayed(){ boolean isToastMessageSeen = false; String xml1 = getDriver().getPageSource(); Utils.waitFor(200); String xml2 = getDriver().getPageSource(); Utils.waitFor(200); String xml3 = getDriver().getPageSource(); Utils.waitFor(200); String xml4 = getDriver().getPageSource(); if( xml1.contains("SUCCESS") && xml1.contains("User updated successfully") ) { System.out.println("Toast message displayed 1: " + "SUCCESS" + " User updated successfully"); return true; }else if( xml2.contains("SUCCESS") && xml2.contains("User updated successfully") ){ System.out.println("Toast message displayed 2: " + "SUCCESS" + " User updated successfully"); return true; }else if( xml3.contains("SUCCESS") && xml2.contains("User updated successfully") ){ System.out.println("Toast message displayed 3: " + "SUCCESS" + " User updated successfully"); return true; }else if( xml4.contains("SUCCESS") && xml2.contains("User updated successfully") ){ System.out.println("Toast message displayed 4: " + "SUCCESS" + " User updated successfully"); return true; } return isToastMessageSeen; }
As you don’t know exact moment of toast message arrival on screen, you need to capture page source multiple times