appium : 獲取安卓原生toast控件信息

  • 測(cè)試軟件:appium api demos # 可在github appium 項(xiàng)目?jī)?nèi)下載

  • 使用設(shè)備:安卓模擬器

  • 準(zhǔn)備工作:

    • 下載 appium-uiautomator2-driver

      cnpm install appium-uiautomator2-driver
      
    • capability內(nèi)新增:automationName

      • 簡(jiǎn)介:使用哪種自動(dòng)化引擎

        Appium(默認(rèn))或Selendroid或UiAutomator2或Espresson用于Android或XCUITestiOS或YouiEngine用于使用You.i Engine構(gòu)建的應(yīng)用程序
        
  • appium 版本:1.13.0

  • 目標(biāo)toast

    • 路徑:Api Demos → Views → Popup Menu → MAKE A POPUP!
toast.png
  • 代碼如下

    import time
    from appium import webdriver
    
    
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '5.1.1'
    desired_caps['deviceName'] = '127.0.0.1:62001'
    desired_caps['appPackage'] = 'io.appium.android.apis'
    desired_caps['appActivity'] = 'io.appium.android.apis.ApiDemos'
    desired_caps['noReset'] = "False"
    desired_caps['automationName'] = "uiautomator2"
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    
    driver.find_element_by_android_uiautomator(
        'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text'
        f'("Views").instance(0));').click()
    
    driver.find_element_by_android_uiautomator(
        'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text'
        f'("Popup Menu").instance(0));').click()
    
    driver.find_element_by_xpath('//android.widget.Button[@content-desc="Make a Popup!"]').click()
    time.sleep(1)
    driver.find_element_by_xpath("http://*[@text= 'Search']").click()
    time.sleep(1)
    print(driver.find_element_by_xpath("http://*[@class='android.widget.Toast']").text)
    
  • 測(cè)試結(jié)果


    測(cè)試結(jié)果
  • 運(yùn)行過(guò)程


    測(cè)試過(guò)程.gif

Words

Appium、appium + android、toast識(shí)別、獲取toast信息、uiautomator2、appium-uiautomator2-driver


Blog:

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容