简体   繁体   English

如何从android中的Toast中提取文本进行验证?

[英]How to Extract text from Toast in android for validation?

I am using espresso for ui testing of an android app.我正在使用 espresso 对 android 应用程序进行 ui 测试。 It has feature of logging in. While logging in, if user enters wrong username or password, a toast appears saying "Incorrect username or password".它具有登录功能。登录时,如果用户输入了错误的用户名或密码,则会出现提示“用户名或密码不正确”。 I want that text for validation.我想要该文本进行验证。 I am writing the tests in android test folder.我正在 android 测试文件夹中编写测试。

I am new to android app testing.我是 Android 应用程序测试的新手。 Need help!需要帮忙!

In order to get the text/message of a Toast using Espresso testing framework, you can use onView() method to check the Toast message view and then try the withText() method to obtain the text of the corresponding view.为了使用 Espresso 测试框架获取 Toast 的文本/消息,您可以使用onView()方法检查 Toast 消息视图,然后尝试withText()方法获取相应视图的文本。

Hope this was helpful for you!希望这对你有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM