Appium 使用 appium 进行微信小程序的自动化测试
文章出处:testerhome转自:https://testerhome.com/topics/7053实微信小程序不过是正常的webview而已. 只是产品概念上的不同. 本质还是h5.
所以用appium是可以进行自动化的.以我们美团外卖为例. 查看结构就可以看到小程序的dom结构.
https://testerhome.com/uploads/photo/2017/548749d8eafc8bc30c89d635bf685f63.png!large
自动化用例的调整
[*]webview的进程名是com.tencent.mm:appbrand1
[*]webview的element需要通过devtool等工具进行分析示例代码简单写个demo给大家. 我本地是测试通过的. 代码是scala. 大家自行用自己的语言去实现吧.
关键就是那句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(new URL(url), capability)
driver.findElementByXPath("//*[@text='发现']").click
driver.findElementByXPath("//*[@text='小程序']").click
driver.findElementByXPath("//*").click
println(driver.getContextHandles)
driver.context("WEBVIEW_com.tencent.mm:tools")
Thread.sleep(5000)
println(driver.getPageSource)
driver.findElementByXPath("//*").click()
driver.findElementByXPath("//*").click()
}
getPageSource 这个在哪里?
页:
[1]