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函數(shù)
???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方法的使用
直接使用并填寫需要匹配的內容
匹配成功:
匹配失斨孟薄: