How to handle toast generate in android device while automating an app using appium?


How to handle toast generate in android device while automating an app using appium?



I am trying to automate an android app using Appium and Webdriver. When i give invalid credentials to login into the app a toast appears, i want to assert the text of this toast.Also, I can't capture the screen shot of this toast using android uiautomatorviewr. How can i handle toast in android? Any Idea!!





Officially you cannot without some major hack arounds. github.com/appium/appium/issues/968 " bootstraponline commented on Oct 2, 2014 It's closed because Google needs to add this to uiautomator. Selendroid works for toasts."
– gorbysbm
Mar 14 '15 at 18:10




1 Answer
1



Yes it is possible but only using uiautomator2, just pass the argument in the capability and use the below code:


DesiredCapabilities caps = DesiredCapabilities.android();
caps.setCapability("automationName", "uiautomator2");
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");

WebElement toastView = _ForgetPasswordDriver.findElement(By.xpath("//android.widget.Toast[1]"));

String actual_toast_msg = toastView.getAttribute("name").trim();






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV