package utilities; | |
import org.apache.commons.exec.CommandLine; | |
import org.apache.commons.exec.DefaultExecuteResultHandler; | |
import org.apache.commons.exec.DefaultExecutor; | |
import java.io.IOException; | |
/** | |
* | |
* @author RightQA | |
* | |
*/ | |
public class AppiumServer { | |
public void startServer() { | |
CommandLine command = new CommandLine( | |
"/Applications/Appium.app/Contents/Resources/node/bin/node"); | |
command.addArgument( | |
"/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js", | |
false); | |
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); | |
try { | |
executor.execute(command, resultHandler); | |
Thread.sleep(5000); | |
System.out.println("Appium server started."); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void stopServer() { | |
String[] command = { "/usr/bin/killall", "-KILL", "node" }; | |
try { | |
Runtime.getRuntime().exec(command); | |
System.out.println("Appium server stopped."); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
I'm also having same question, what we can do if we have 2 appium server instance. @benz-philip |
This comment has been minimized.
This comment has been minimized.
When tried to run the above code :
}` I got the following error : /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:1 SyntaxError: Unexpected token import After running the code : Can anyone help me with this? TIA :) |
This comment has been minimized.
This comment has been minimized.
Getting connection refused :( |
This comment has been minimized.
This comment has been minimized.
Connection get refused when your specified port is already occupied! #AllTheBest |
This comment has been minimized.
The start and stop methods are good to go with if we have only one instance of appium server. What if we have multiple appium server launched and we want to stop a particular node. using given code to stop server stops all the servers launched.
welcome your suggestions...