最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Appium自動化測試中獲取Toast信息操作

 更新時(shí)間:2022年02月15日 09:29:26   作者:測試之路king  
本文主要介紹了Appium自動化測試中獲取Toast信息操作,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Toast簡介

Toast是Android中用來顯示顯示信息的一種機(jī)制,和Dialog不一樣的是,Toast是沒有焦點(diǎn)的,而且Toast顯示的時(shí)間有限,過一定的時(shí)間就會自動消失。

Toast 定位

Appium 1.6.3開始支持識別Toast內(nèi)容,主要是基于UiAutomator2,因此需要在Capablity配置參數(shù)

啟動參數(shù)配置

desired_caps['automationName']='uiautomator2'

環(huán)境

  • Appium-Python-Client: 2.1.2
  • selenium: 4.1.0
  • Appium:v1.20.2

測試應(yīng)用

  • 網(wǎng)易云課堂

測試設(shè)備

  • 夜神模擬器 Android 7.1.2

測試場景

  • 進(jìn)入登錄界面輸入用戶名和錯(cuò)誤的密碼,獲取Toast內(nèi)容

代碼實(shí)現(xiàn)

# _*_ coding:utf-8 _*_

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

desired_caps = {
? ? "platformName": "Android",
? ? "platformVersion": "7.1.2",
? ? "udid": "127.0.0.1:62001",
? ? "appPackage": "com.netease.edu.study",
? ? "appActivity": "com.netease.edu.study.activity.ActivityWelcome",
? ? "noReset": True,
? ? 'automationName': 'uiautomator2'
}

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
driver.implicitly_wait(30)

# 點(diǎn)擊我的菜單
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/tab_account").click()

# 點(diǎn)擊登錄注冊按鈕
driver.find_element(AppiumBy.XPATH, "http://*[@text='登錄/注冊']").click()

# 點(diǎn)擊手機(jī)號碼登錄
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/login_phone_login").click()

# 輸入手機(jī)號碼
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/tv_phone_num").send_keys("132****475")

# 輸入錯(cuò)誤密碼
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/tv_phone_pwd").send_keys("wy12345")

# 點(diǎn)擊登錄按鈕
driver.find_element(AppiumBy.ID, "com.netease.edu.study:id/button").click()

# 獲取toast提示
toast_text = driver.find_element(AppiumBy.XPATH, "http://*[@class=\"android.widget.Toast\"]").text
print(toast_text)

執(zhí)行結(jié)果:

說明

toast 獲取主要使用一個(gè)通用的class屬性獲取,通過xpath的方式://*[@class="android.widget.Toast"]

toast信息存在是否存在判斷封裝

代碼

def is_toast_exist(driver,text,timeout=20,poll_frequency=0.5):
? ? '''is toast exist, return True or False
? ? :Agrs:
? ? ?- driver - 傳driver
? ? ?- text ? - 頁面上看到的文本內(nèi)容
? ? ?- timeout - 最大超時(shí)時(shí)間,默認(rèn)20s
? ? ?- poll_frequency ?- 間隔查詢時(shí)間,默認(rèn)0.5s查詢一次
? ? :Usage:
? ? ?is_toast_exist(driver, "看到的內(nèi)容")
? ? '''
? ? try:
? ? ? ? toast_loc = ("xpath", ".//*[contains(@text,'%s')]"%text)
? ? ? ? WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
? ? ? ? return True
? ? except:
? ? ? ? return False

toast信息內(nèi)容獲取

代碼

def is_toast_exist(driver,timeout=20,poll_frequency=0.5):
? ? '''is toast exist, return toast_text or None
? ? :Agrs:
? ? ?- driver - 傳driver
? ? ?- timeout - 最大超時(shí)時(shí)間,默認(rèn)20s
? ? ?- poll_frequency ?- 間隔查詢時(shí)間,默認(rèn)0.5s查詢一次
? ? :Usage:
? ? ?is_toast_exist(driver)
? ? '''
? ? try:
? ? ? ? toast_loc = ("xpath", "http://*[@class=\"android.widget.Toast\"]")
? ? ? ? WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
? ? ? ? toast_text = driver.find_element(AppiumBy.XPATH, "http://*[@class=\"android.widget.Toast\"]").text
? ? ? ? return toast_text
? ? except:
? ? ? ? return None

到此這篇關(guān)于Appium自動化測試中獲取Toast信息操作的文章就介紹到這了,更多相關(guān)Appium 獲取Toast內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

淮阳县| 利津县| 苗栗市| 清河县| 衡南县| 寿阳县| 建湖县| 台中县| 綦江县| 曲水县| 扎鲁特旗| 盐池县| 潼关县| 福州市| 临夏县| 龙山县| 谷城县| 丹凤县| 醴陵市| 乐昌市| 安仁县| 龙里县| 科尔| 惠来县| 星座| 钟祥市| 霸州市| 朝阳县| 遂溪县| 肥城市| 鸡泽县| 平邑县| 滕州市| 贡山| 连江县| 陆河县| 湘潭县| 永丰县| 应城市| 凌云县| 孝昌县|