Launching and stopping appium server programmtically

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

}

}

Try putting your Appium files in C directory and give it another try.

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

}