使用appium自动化应用程序时如何处理Android设备中的toast生成? [英] How to handle toast generate in android device while automating an app using appium?

查看:35
本文介绍了使用appium自动化应用程序时如何处理Android设备中的toast生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Appium 和 Webdriver 自动化一个 android 应用程序.当我提供无效凭据登录应用程序时,会出现一个吐司,我想断言此吐司的文本.此外,我无法使用 android uiautomatorviewr 捕获此吐司的屏幕截图.我如何在 android 中处理吐司?任何想法!

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

推荐答案

是的,但只能使用 uiautomator2,只需在功能中传递参数并使用以下代码:

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

这篇关于使用appium自动化应用程序时如何处理Android设备中的toast生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆