Launching and stopping appium server programmtically

Can you please mention what are you doing in your script on line 156 in your “AppiumServerLib” file?? The exception seems to be initiated from there

@Hassan_Radi: line 156 set capabilities to driver

FwConstants.AndDriver = new AndroidDriver (new URL(FwConstants.strArg_URL),FwConstants.Appiumcapabiliy);

url is coming from excel spreadsheet , accessed using Apache POI.

@Kamal_Girdher: Thanks for response and provided links , i built the framework which will access the values dynamically from the spreadsheet during execution. Firstly I am executing on Windows , same code I was referring into dynamic code. It is perfectly running in debug mode (node.exe invoke , setting capabilities and running above mentioned driver code). But during run mode , giving above mentioned error for which Hasan is requesting information. Thanks for your help.

The fact that it fails when starting the Appium session is because starting the server was somehow skipped and it is now trying to reach a server that was not started.

The server starting logic might have failed and was not started successfully without you noticing (It would throw an error message in the command prompt log) because the server might have been already running and trying to start it again with the same IP address and port number will give an error message saying that “The port number is already used by another application”

I recommend checking if the server is already running before you attempt to start it. If it was actually running, then you should stop it and then move to the start logic again. Also when working with the command prompt and executing actions in this manner, you should always print the output of the command execution in your log to be able to refer to that later and know what went wrong.

Hope I helped…

P.S. The IP address you are using “10.31.24.67” doesn’t look like a local address on your machine, unless you are doing some loopback tunneling, so please check the IP address and make sure it is not the issue.

1 Like

@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.