干貨| app自動化測試之Andriod微信小程序的自動化測試
隨著微信小程序的功能和生態日益完善,很多公司的小程序項目頁面結構越來越多,業務邏輯也越來越復雜。如何做好小程序的自動化測試就成為測試同學普遍面臨的一大痛點難題。
微信小程序
小程序內嵌于微信內部,頁面包含 Native 原生元素和 Web 元素,相當于混合應用。并且,小程序 Web 部分是基于騰訊的 X5 內核開發的,也是特殊的 WebView。那么,對微信小程序進行自動化測試,包括操作原生應用、WebView、基于微信官方自動化 SDK。
WebView頁面元素獲取
使用元素定位工具:
weditor
weditor安裝方式
pip install weditor
參考文檔:https://github.com/alibaba/web-editor
使用 chrome inspect 定位時,解析元素是把頁面解析為了 html 頁面,使用 weditor,則會把頁面解析為原生頁面,而 Appium 在操作元素時,也是把頁面解析成了原生去操作的(切換 webview 除外)
Mac:
adb shell dumpsys activity top| grep ACTIVITY
Windows:
adb shell dumpsys activity top| findstr ACTIVITY
from time import sleep from appium import webdriver class TestDemo: def setup(self): self.desire_cap= { 'automationName': "uiautomator2", "platformName": "Android", "deviceName": "wechat", "appPackage": "com.tencent.mm", "appActivity": ".ui.LauncherUI", "noReset": "true", 'chromeOptions': {'androidProcess': 'com.tencent.mm:appbrand0'} } # androidProcess:webview是獨立進程的,導致無法獲取,需要在 chromeOptions 添加 androidProcess 即可 self.driver=webdriver.Remote("http://127.0.0.1:4723/wd/hub",self.desire_cap) self.driver.implicitly_wait(20) def teardown(self): self.driver.quit() def test_demo(self): # 剛打開微信時,頁面加載時間未知, # 需要通過find_element觸發隱式等待,防止后續操作失敗 self.driver.find_element_by_xpath("http://*[@text='通訊錄']") size = self.driver.get_window_size() # 獲取當前屏幕的寬、高 width = size.get("width") height = size.get("height") # 滑動打開小程序頁面 self.driver.swipe((width / 2), int((height * 0.2)), (width / 2), (height * 0.8), 2000) self.driver.find_element_by_xpath("http://*[@resource-id='com.tencent.mm:id/gam' and @text='雪球']").click() sleep(5) print(self.driver.contexts,'第一次打印') self.driver.find_element_by_xpath("http://*[@content-desc='搜索股票信息/代碼']/..").click() self.driver.find_element_by_xpath('//*[@text="請輸入股票名稱/代碼"]').send_keys("阿里巴巴") text = self.driver.find_element_by_xpath('//*[@content-desc="阿里巴巴"]') assert text
模擬器:Genymotion
系統版本:8.1
微信版本:7.0.15
- 小程序:雪球
- http://appium.io/docs/en/writing-running-appium/caps/
- https://sites.google.com/a/chromium.org/chromedriver/capabilities
- https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android
小程序的測試方法有很多種,因為微信版本經常升級,webview的設置也會發生變化,所以可用的測試方法可能會因為每個版本而不同。更多可用測試方法可參考測試人論壇:https://ceshiren.com/t/topic/12403
小程序 移動APP 自動化測試
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。