# Automator

The Automator module provides a way to launch and connect developer tools.

# method

# automator.connect

Connect to developer tools.

automator.connect(options: Object): Promise<MiniProgram>

The options field is defined as follows:

field type Required to fill in Default values Introductions
wsEndpoint string yes - Developer Tools WebSocket Address

Developer tools that turn on automation functions can be called from the command line.

'--auto ': Opens the specified item and turns on auto-activation.

'--auto-port': Specifies a custom listening port.

cli --auto /Users/username/demo --auto-port 9420

For instructions on the use of the command line call, you can view here .

Example code:

automator.connect({
  wsEndpoint: 'ws://localhost:9420'
}).then(async miniProgram => {
  const page = await miniProgram.navigateTo('/page/component/index')
  await page.setData({})
})

# automator.launch

Launch and connect to the developer tools.

Make sure that the CLI / HTTP invocation feature is turned on in the tool's security settings.

automator.launch(options: Object): Promise<MiniProgram>

The options field is defined as follows:

field type Required to fill in Default values Introductions
cliPath string no - Developer Tools Absolute Paths to Tools on the Command Line
projectPath string yes - Project Absolute Path
timeout number no 30000 Maximum waiting time for startup
port number no - WebSocket port number
account string no - User openid
projectConfig Object no - Override the configuration in project.config.json
ticket string no - Developer Tools Login Notes

When cliPath is not set, it will try to find it in the following places:

  • Mac:/Applications/wechatwebdevtools.app/Contents/MacOS/cli
  • Win: C: / Program Files (x86) / Tencent / WeChat web developer tools / cli.bat

Account opens a project window with users added in multi-account debugging, and works with the miniProgram.testAccounts interface.

Ticket can be used with the miniProgram.getTicket interface using the developer tool identity already logged in on other machines.

Example code:

automator.launch({
  cliPath: 'path/to/cli',
  projectPath: 'path/to/project',
  projectConfig: {
    setting: {
      autoAudits: true,
    },
  },
}).then(async miniProgram => {
  const page = await miniProgram.navigateTo('/page/component/index')
  await page.setData({})
})

The following example code omits the launch parameter passing as a convenience.