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

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

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

Toast簡介

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

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

測試場景

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

代碼實現(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)

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

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

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

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

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

# 點擊登錄按鈕
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 獲取主要使用一個通用的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 - 最大超時時間,默認20s
? ? ?- poll_frequency ?- 間隔查詢時間,默認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 - 最大超時時間,默認20s
? ? ?- poll_frequency ?- 間隔查詢時間,默認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)文章

最新評論

罗江县| 沙湾县| 柞水县| 喜德县| 宽城| 民勤县| 商洛市| 密云县| 乌什县| 得荣县| 邹平县| 丹东市| 昌吉市| 连平县| 普陀区| 榆树市| 贵州省| 阿克陶县| 南充市| 商河县| 尼勒克县| 瓮安县| 乌拉特后旗| 平邑县| 绥化市| 江孜县| 固始县| 昭苏县| 扬州市| 昆明市| 容城县| 罗源县| 赤水市| 布尔津县| 临泉县| 甘泉县| 原平市| 蒙阴县| 镇康县| 敦煌市| 平乡县|