Start Appium Server programmatically with JavaScript

Hi,

I would like to start the Appium server using JS, run my tests, and then shut it down, preferably in a Gulp task. I can start using the command line manually, but haven’t been able to get it to work programmatically. Looks like the Java Client has an excellent implementation for the service, AppiumDriverLocalService, but I cannot find something equivalent for JavaScript.

Does anyone have any tips?

I looked at the main.js file in the appium node bindings, but it looked pretty complicated, so I was wondering if anyone has already figured this out. I was thinking somethig like:

class Appium {
    public server() {
        // server configs
        // start the server
    }
}

export = (done: any) => {
  new Appium()
    .server()
    .then((server: any) => {
      gulp
        // gulp tasks here
        .on('error', (error: string) => { throw error; })
        .on('end', () => { server.close(done); });
    });
};

Any help would be appreciated. Thanks!

Got this working (not the Gulp stuff, but starting Appium)

import { main as appiumServer } from 'appium';

class Appium {
    public async server() {
        let args = {};
        return await appiumServer(args);
    }
}

... blah blah gulp stuff

Found this in the appium e2e specs :blush:

Hi, can you link me the appium e2e specs?

Totally. In this spec, they import main.js as appiumServer and call that to start and shutdown the server. Hope that helps!

1 Like