Star Appium Programatically

Hello,

I have a framework using Wdio, node.js and Appium.

I want to stop and start the appium server before each test so I want to add the logic in the beforeSession hook.

I’ve tried executing CLI commands using child_process but it does not start / stop the server.

The same commands are working ok if I am inputting them manually in the MacOS terminal.

However if I am executing ls it works.

Can someone help on how to achieve this?

Thanks!

Here is a tutorial on starting Appium server programmatically in Java using AppiumServiceBuilder. There are code examples on how to start in @Before Method and how to clean up with @After:

https://www.headspin.io/blog/starting-an-appium-server-programmatically-using-appiumservicebuilder

@wreed I am using JS not Java so I don’t know exactly how the tutorial can help me. I didn’t found anything on JS out there.

I’ve tried that small portion with Appium.main but doest not work.

Sorry, I guess that’s what I get for trying to be a mind reader :wink:

Here is a tutorial on Appium using Javascript that starts the server programmatically:

https://digital.ai/catalyst-blog/follow-this-guide-to-set-up-appium-automation-using-javascript

@wreed I’ve tried this approach with builder but without any success.
It throws: TypeError: Target browser must be a string but is ; did you forget to call forBrowser()?

I’ve given up trying to read minds. You’ll have to give more info. Could you post the log as a git gist:

https://docs.github.com/en/get-started/writing-on-github/editing-and-sharing-content-with-gists/creating-gists