How to handle toast generate in android device whi

2019-08-10 21:23发布

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条回答
贼婆χ
2楼-- · 2019-08-10 21:24

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();
查看更多
登录 后发表回答