1

I am using Javascript with Node.JS and WDIO and trying to start appium programatically in beforeTest hook and stop it in afterTest hook.

I've tried doing so with child_process or some appium-service builder but without any success.

Is there a possibility to start/stop appium server programatically using certain portion of code?

Thanks

vPilu
  • 11
  • 1

1 Answers1

1

You can install appium in your project directory. Import appium and call appium.main(). This will start appium in the default port.

Start appium :

const appium = require('appium');
await appium.main({port : 4723, address : "127.0.0.1"})

Stop appium : To stop appium programatically, you can kill the process. I used this package - https://www.npmjs.com/package/find-process to find the pid and kill process.

const findProcess = require('find-process')
let processList = await findProcess('port', 4723)
if(processList.length > 0) {
    processList.forEach(proc =>  {
        process.kill(proc.pid)                
    })
}