How to handle toast generate in android device whi

2019-08-10 21:11发布

问题:

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