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方法的使用
直接使用并填写需要匹配的内容

匹配成功:

匹配失败:
