Yah ...Here it is:
package SampleTest;
import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.io.IOException;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
import java.io.*;
import java.util.*;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class AppiumServer {
public void startServer(){
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("D:\My_DEMO\Appium\Appium\node.exe");
command.addArgument("D:\My_DEMO\Appium\Appium\node_modules\appium\lib\appium.js");
command.addArgument("--address");
command.addArgument("127.0.0.1");
command.addArgument("--port");
command.addArgument("4724");
command.addArgument("--no-reset");
command.addArgument("--log");
command.addArgument("D:/appiumLogs.txt");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(command, resultHandler);
} catch (IOException e) {
e.printStackTrace();
}
}
public void stopServer(){
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("taskkill");
command.addArgument("/F");
command.addArgument("/IM");
command.addArgument("node.exe");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(command, resultHandler);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws BiffException, IOException {
AppiumServer server=new AppiumServer();
System.out.println("---- Starting appium server ----");
server.startServer();
System.out.println("---- Appium server started Successfully ! ----");
try{Thread.sleep(10000);}catch(Exception e){}
System.out.println("---- Stoping appium server ----");
server.stopServer();
System.out.println("---- Appium server stopped Successfully ! ----");
}
}
tried....no Change..getting same Error...now Check this out plz...
package myBeepsTest;
import io.appium.java_client.AppiumDriver;
import java.io.File;
import java.io.IOException;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecuteResultHandler;
import org.apache.commons.exec.DefaultExecutor;
import java.io.*;
import java.util.*;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class AppiumServer {
public void startAppiumServer() throws IOException, InterruptedException {
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("c:/Appium/node.exe");
command.addArgument("c:/Appium/node_modules/appium/lib/appium.js");
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");
command.addArgument("--full-reset", false);
command.addArgument("C:/Appium/node.exe C:/Appium/node_modules/appium/bin/Appium.js --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
}
public void stopAppiumServer() throws IOException {
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("Taskkill /F /IM node.exe");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
}
public static void main(String as[]) throws IOException, InterruptedException
{
AppiumServer aps = new AppiumServer();
System.out.println("Starting Server...");
aps.startAppiumServer();
System.out.println("Server Started....");
try{Thread.sleep(5000);}catch(Exception e){}
System.out.println("Stopping Server");
aps.stopAppiumServer();
System.out.println("Server Stopped");
}
}
even though if we put false for no-reset/full-reset..the logs are showing as true. Has anyone faced the same issue?
command.addArgument("--full-reset", false);
or
command.addArgument("--no-reset", false);
The appium is launched as
[36minfo[39m: [debug] Non-default server args: {"address":"127.0.0.1","noReset":true,"log":"D:/appiumLogs.txt"}
For anyone who is still having problems getting the server to start programmatically, you can refer to this post about a new library called Appium Support216.
Hope it helps.
I'm getting an error like
C:/Program' is not recognized as an internal or external command,
operable program or batch file.
CODE:
public void startAppiumServer() throws IOException, InterruptedException {
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("C:/Program Files (x86)/Appium/node.exe");
command.addArgument("C:/Program Files (x86)/Appium/node_modules/appium/lib/appium.js");
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");
command.addArgument("--full-reset", false);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
}
@Hassan_Radi Could you explain the meaning of it
command.addArgument("--address", true);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4722");
command.addArgument("--full-reset", false);