# Real machine automation

Weixin Mini Program In addition to being able to control the Mini Program simulator in the developer tools, automation also supports controlling the real machine through remote debugging for automated testing on the real machine.

# Operating environment

  • Ensure that the base library version on the target machine is2.7.3and above

# How to use it

After you have written a test case and successfully tested it in a tool simulator, if you want to run automation on a real machine, you can do it in two ways.

# Launch via SDK

You can use theminiProgram.remoteinterface to launch the native debugging functionality of the tool at the beginning of the test script, and the script prints a QR code in the console when called successfully.After a successful connection using a scan of the target machine, the script continues to run on the real machine.

Example script:

const automator = require('miniprogram-automator')

const miniProgram = automator.launch({
  cliPath: 'path/to/cli', 
  projectPath: 'path/to/project',
}).then(async miniProgram => {
  await miniProgram.remote() // 扫码登录连接真机,在真机上执行后续测试脚本

  const page = await miniProgram.reLaunch('/page/component/index')
  await page.waitFor(500)
  const element = await page.$('.kind-list-item-hd')
  console.log(await element.attribute('class'))
  await element.tap()

  await miniProgram.close()
})

# Manually start up

If the tool is on a permanent location and connects using theautomator.connectinterface, you can manually enable the tool's native debugging function before running the test script so that Weixin Mini Program can be tested on the native machine.