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

查看:143
本文介绍了使用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天全站免登陆