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

懵懂的女人 提交于 2020-01-05 07:57:19

问题


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!!


回答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();


来源:https://stackoverflow.com/questions/27796537/how-to-handle-toast-generate-in-android-device-while-automating-an-app-using-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!