RobotFramework集成安卓toast提示语的匹配

1、安装新版本的APPIUM如:appium-desktop-Setup-1.2.7.exe

下载地址:https://testerhome.com/topics/680

需要使用Uiautomator2才能选择到toast的信息

2、集成find toast方法到APPIUMLIBRARY

路径\Python27\Lib\site-packages\AppiumLibrary\keywords\_element.py

①导入需要用到的模块

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions

②定义find toast函数

   def find_toast(self, message):

       """Finds an element by Android Toast

       :Args:

        - message - The message for preparing.

       """

       application = self._current_application()  ##获取当前的驱动

       try:

           toast_loc = ("xpath",".//*[contains(@text,'%s')]"%message)

           WebDriverWait(application, 6,0.5).until(expected_conditions.presence_of_element_located(toast_loc))

           self._info("Toast has been found: %s ."%message)

       except:

           raise AssertionError("Not found toast")

3、启动APP时,需要切换UI选择器

需要增加的信息:automationName=Uiautomator2        noReset=true

4、find toast方法的使用

直接使用并填写需要匹配的内容

匹配成功:

匹配失败:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容