Launching and stopping appium server programmtically

@Hassan_Radi:

Thanks for your time and comments.

I am examining and working on your comments.

I have two queries here:
a) How to know whether Appium server is running or not , do you have any reference code or link?
b) Regarding output of the command execution log record , do you have any link or reference code?, so that I will implement and see

The IP address shown in the log file is , Host IP Address. But in the actual code for server start on IP Address is 127.0.0.1 , port 4789

Does this impact when we trying to initiate Appium server through code?

Regards,
Kiran

You will find a node.exe process in your task manager when the server is running.

You can use this function. The whole class is supposed to start and stop Appium server. Give it a try and let me know how it works.

Hi @Hassan_Radi can you help me in this thread please

How can i start the server and stop it from ruby programmatically?

hi bro can you tell me how i can do this in c# please in mac platform…how can i start the server and also give my app path for the simulator to open the app.?

@Hassan_Radi: Thanks for your great support , while this is still under my work , I have another priority issue than this one. If you have time , could you please respond to below mentioned issue which I have to clear ASAP.

IOS App not signing in with correct credentials using Automation Code

Regards,
Kiran

hey hi,
I am new to the appium i want to launch appium in ubuntu, want to know how to write test scripts…
any help would be very helpful.
thanks in advance.

There is no Appium Gui and Inspector for Ubuntu???

Hi,

I’m not sure about iOS devices as I’m able to run them on Mac’s only, however you could install Android sdk’s where you can use tools/uiautomatorviewer for getting more info about your Android app

HI,
i have already installed android sdk also i have develop my app to test , but want to know how to start appium with my app also want to how to write tests cases and to run tests on my app???

Hey, seems you are not in correct topic:-)
Please look around other topics on the discuss as this topic about exact problem - launch appium programatically

Hi,
i did all the mentioned setup. But when i try to launch appium from cmd by triggering the appium.js file i get a windows error. I even get the same error when i manually double click on the appium.js file.
But i am able to launch appium from the .exe file and run my tests on both physical device and emulators.
Am i doing anything wrong???

Please attach a screenshot of the error message or share your piece of code. Tell us more about what you are experiencing in order for us to be able to help you :smile:

P.S. Manually clicking the Appium.js file won’t help at all :smile:

1 Like

Hi Hasan,

It’s unbelievable, I’ve faced the same issue with ProcessBuilder like you just only now:-) I don;t know why it works previously and I why it doesn’t work now.
However, I started using apache commons exec for parallel running and it works like a charm:-)

So start is:
private Executor appiumProcess;
CommandLine cmdLine = new CommandLine(command);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
PumpStreamHandler streamHandler = new PumpStreamHandler(new FileOutputStream(“Device” + deviceIndex + “Logs.txt”));
appiumProcess = new DefaultExecutor();
appiumProcess.setExitValue(0);
appiumProcess.setWatchdog(watchdog);
appiumProcess.setStreamHandler(streamHandler);
appiumProcess.execute(command, resultHandler);

Stop is simple:
appiumProcess.getWatchdog().destroyProcess();

Cmd creation smth like that:
CommandLine cmd = new CommandLine(“node”);
cmd.addArgument(PropertyLoader.get(“appium.path”));
cmd.addArgument("-a");
cmd.addArgument(PropertyLoader.get(“appium.host”));
cmd.addArgument("-p");
cmd.addArgument(String.valueOf(Integer.parseInt(PropertyLoader.get(“appium.port”)) + deviceIndex));
cmd.addArgument("-bp");
cmd.addArgument(String.valueOf(Integer.parseInt(PropertyLoader.get(“appium.bootstrapPort”)) + deviceIndex));
cmd.addArgument("-U");
cmd.addArgument(device.getUDID());

1 Like

Please let me know Steps for MAC.
Thanks,
AJ.

In my case I am Using iOS Application…so Please Help me out …
As MY Application File Name Extension is DemoApp.app

Please send me code snippet if poossible.
Thanks,
Aiit.

Hello Husain,

In My case I am Getting Error as:

ERROR: The process “node.exe” not found

__I am trying to launch Appium Server for Android Application Testing on Android Simulator.

Please provide your code snippet that led to this error?? :smile:

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 ! ----");

}

}