其实微信小程序不过是正常的webview而已. 只是产品概念上的不同. 本质还是h5.
所以用appium是可以进行自动化的.
以我们美团外卖为例. 查看结构就可以看到小程序的dom结构.
webview的进程名是com.tencent.mm:appbrand1
webview的element需要通过devtool等工具进行分析
具体的细节可参考我之前写过 微信 webview 的自动化技术
### 示例代码
val options = new ChromeOptions()
options.setExperimentalOption("androidProcess", "com.tencent.mm:appbrand1")
capability.setCapability(ChromeOptions.CAPABILITY, options)
test("测试微信小程序") {
val capability = new DesiredCapabilities()
capability.setCapability("app", "")
capability.setCapability("appPackage", "com.tencent.mm")
capability.setCapability("appActivity", ".ui.LauncherUI")
capability.setCapability("deviceName", "emulator-5554")
capability.setCapability("fastReset", "false")
capability.setCapability("fullReset", "false")
capability.setCapability("noReset", "true")
capability.setCapability("automationName", "appium")
capability.setCapability("platformName", "android")
val options = new ChromeOptions()
options.setExperimentalOption("androidProcess", "com.tencent.mm:appbrand1")
capability.setCapability(ChromeOptions.CAPABILITY, options)
val url = "http://127.0.0.1:4723/wd/hub"
val driver = new AndroidDriver[WebElement](new URL(url), capability)
driver.findElementByXPath("//*[@text='发现']").click
driver.findElementByXPath("//*[@text='小程序']").click
driver.findElementByXPath("//*[contains(@text, '美团外卖')]").click
println(driver.getContextHandles)
driver.context("WEBVIEW_com.tencent.mm:tools")
Thread.sleep(5000)
println(driver.getPageSource)
driver.findElementByXPath("//*[contains(@url, '美食')]").click()
driver.findElementByXPath("//*[contains(., '金百万')]").click()
}