Hi @Hassan_Radi can you help me in this thread please
@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.
Regards,
Kiran
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????
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());
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");
}
}