I am trying to start and stop Appium server programmatically.
I have nodeJS installed in my system.
For starting the server I am using "appium" command in a batch file and running that batch file using Java.
For stopping the server:
Runtime runtime = Runtime.getRuntime();
runtime.exec("taskkill /F /IM node.exe");
But by using taskKill server is not killing.
Please suggest any methods by which I can stop the running Appium server.
There are two ways through which you can start & stop the appium server as,
private AppiumDriver<?> driver;
private AppiumDriverLocalService appiumDriverLocalService;
private static final String NODE_FILE_PATH = "/usr/local/bin/node";
private static final String APPIUM_FILE_PATH = "/usr/local/bin/appium";
public void startAppiumServer() {
Map<String, String> environment = new HashMap();
environment.put("PATH", "/usr/local/bin:" + System.getenv("PATH"));
AppiumServiceBuilder appiumServiceBuilder = new AppiumServiceBuilder();
appiumServiceBuilder.usingAnyFreePort();
appiumServiceBuilder.usingDriverExecutable(new File(NODE_FILE_PATH));
appiumServiceBuilder.withAppiumJS(new File(APPIUM_FILE_PATH));
appiumServiceBuilder.withEnvironment(environment);
appiumDriverLocalService = AppiumDriverLocalService.buildService(appiumServiceBuilder);
appiumDriverLocalService.start();
}
public void stopAppiumServer() {
appiumDriverLocalService.stop();
}
sudo kill $(ps aux | grep -i appium | awk '{print $2}')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.