APP自动化测试总结六:微信小程序自动化测试
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from appium.webdriver.common.mobileby import MobileBy as MB from appium import webdriver import time desired_caps = {} # 支持X5内核应用自动化配置 desired_caps["recreateChromeDriverSessions"] = True # android 4.4以下的版本通过Selendroid来切换到webview desired_caps["automationName"] = "UiAutomator2" desired_caps["platformName"] = "Android" desired_caps["deviceName"] = "Android Emulator" desired_caps["appPackage"] = "com.tencent.mm" desired_caps["appActivity"] = "com.tencent.mm.ui.LauncherUI"
# 内置浏览器driver所在位置 desired_caps["chromedriverExecutableDir"] = r'D:\data\chromedriver' desired_caps["noReset"] = True desired_caps["chromeOptions"] = {"androidProcess": "com.tencent.mm:appbrand0"} driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) driver.implicitly_wait(10) # 进入微信主页的点击聊天 el = driver.find_element('id', 'com.tencent.mm:id/baj') size = driver.get_window_size() el.click() # 顶部向下滑动,进去我的小程序 driver.swipe(size["width"] * 0.5, size["height"] * 0.1, size["width"] * 0.5, size["height"] * 0.9, 100) # 下拉列表当中,点击 小程序 el = driver.find_element('xpath', '//*[contains(@text, "小程序")]') # el = WebDriverWait(driver, 30).until(EC.visibility_of_element_located(locator)) el.click() time.sleep(3) # ================== 进入了 指定小程序内部界面=============== # 获取所有的上下文 cons = driver.contexts print("当前所有的上下文为:", cons) # 切换到小程序webview #driver.switch_to.context('WEBVIEW_com.tencent.mm:appbrand0')
driver.switch_to.context[-1] #进入小程序后与H5混合应用测试一致。
time.sleep(3) driver.quit()
分类:
Appium
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示