Launching and stopping appium server programmtically


#91

Hi Radha,

Can you please let us know how do you set up the ANDROID_HOME globally in MAC.

I am getting the same issue when running the appium launch via java code in eclipse

Thank you in Advance.

Regards
Gan


#92

Hi

The same code is not working for me on Mac. Can you help me with it.

I am getting NPE at appiumProcess.getWatchdog().destroyProcess();

Please help ASAP


#93

Could you paste all code example here and the error


#94

Hi

Its working here after setting the capabilities properly.

Can you tell me how to launch an emulator programatically on Mac and Win.

Thanks,
Pradeep


#95

@Pradeep simulators and emulators are both launched automatically by appium if you don’t have one already running. You can look at the appium source code for how this is done :smile:


#96

@Hassan_Radi

public void launchAppium() {
CommandLine command = new CommandLine("/bin/sh");
command.addArgument("/Applications/Appium.app/Contents/Resources/node/bin/node");
command.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js");
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);
	} catch (ExecuteException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

Unable to start appium service by AppiumDriverLocalSerivce
#97

When you start the server through the Appium GUI, the logs show what command Appium executes to start the sever.

You can execute the same command into terminal to get the server working. An example of starting the server from terminal is to execute the following:

cd /Applications/Appium.app/Contents/Resources/node_modules/appium

‘/Applications/Appium.app/Contents/Resources/node/bin/node’ lib/server/main.js --address “127.0.0.1” --command-timeout “7200” --session-override --debug-log-spacing --platform-version “8.4” --platform-name “iOS” --app “<path-to-.app>” --show-ios-log --show-ios-log --device-name “iPad Air” --instruments “/Applications/Xcode.app/Contents/Developer/usr/bin/instruments” --native-instruments-lib --orientation “Landscape”


#98

Hi
I am able to invoke appium from source but when i run my test for hybrid app on an emulator for android it fires an error saying:
error: android.util.AndroidException: INSTRUMENTATION_FAILED: com.hp.eSupplies.s
elendroid/io.selendroid.server.ServerInstrumentation

    at com.android.commands.am.Am.runInstrument(Am.java:865)

    at com.android.commands.am.Am.onRun(Am.java:282)

    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)

    at com.android.commands.am.Am.main(Am.java:76)

    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)

    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)

    at dalvik.system.NativeStart.main(Native Method)

info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: android.util.AndroidEx
ception: INSTRUMENTATION_FAILED: com.hp.eSupplies.selendroid/io.selendroid.serve
r.ServerInstrumentation

info: [debug] Error: android.util.AndroidException: INSTRUMENTATION_FAILED: com.
hp.eSupplies.selendroid/io.selendroid.server.ServerInstrumentation

at C:\Users\birmanga\node_modules\appium\node_modules\appium-adb\lib\adb.js:

1394:17
at [object Object]. (C:\Users\birmanga\node_modules\appium\node_m
odules\appium-adb\lib\adb.js:180:9)
at ChildProcess.exithandler (child_process.js:742:7)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:"
A new session could not be created. (Original error: android.util.AndroidExcepti
on: INSTRUMENTATION_FAILED: com.hp.eSupplies.selendroid/io.selendroid.server.Ser
verInstrumentation\r\r)",“origValue”:“android.util.AndroidException: INSTRUMENTA
TION_FAILED: com.hp.eSupplies.selendroid/io.selendroid.server.ServerInstrumentat
ion\r\r”},“sessionId”:null}
info: <-- POST /wd/hub/session 500 15246.261 ms - 380

When i try the same code by launching Appium(1.3.X) from appium.exe the code works perfectly in an emulator.

Could anyone please help me out of it. Thanks in advance.


#99

@Hassan_Radi I am able to start the appium server below is my code and it’s output.

public class AppiumServer {

 public void startServer(){
  CommandLine command = new CommandLine("cmd");
  command.addArgument("/c");
  command.addArgument("D:/Appium/node.exe");
  command.addArgument("D:/Appium/node_modules/appium/bin/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) {
  AppiumServer server=new AppiumServer();
  System.out.println("---- Starting appium server ----");
  server.startServer();
  System.out.println("---- Appium server started Successfully ! ----");
  
  try {
    Thread.sleep(2000L);
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
  
  System.out.println("---- Stoping appium server ----");
  server.stopServer();
  System.out.println("---- Appium server stopped Successfully ! ----");
  
 }
 
}

Output:
---- Starting appium server ----
---- Appium server started Successfully ! ----
---- Stoping appium server ----
---- Appium server stopped Successfully ! ----
SUCCESS: The process “node.exe” with PID 6752 has been terminated.

But when i am trying to set capabilities, i am getting error as session can’t be created. Below is the code for capablities

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
capabilities.setCapability(CapabilityType.VERSION, “5.1.1”);
capabilities.setCapability(“platformName”, “ANDROID”);
capabilities.setCapability(“deviceName”, “QO4301C12715”);
capabilities.setCapability(“autoWebview”, “true”);
capabilities.setCapability(“appPackage”, “com.android.settings”);
capabilities.setCapability(“appActivity”, “com.android.calendar.LaunchActivity”);
capabilities.setCapability(“newCommandTimeout”, “180”);
capabilities.setCapability(“autoWebviewTimeout”, “6000”);
driver = new AndroidDriver(new URL(“http://127.0.0.1:4725/wd/hub”),
capabilities);

	System.out.println("App Launched sucessfully:::");

Please help me out to resolve this issue.


#100

Please include details regarding the error message and stack trace.


#101

@Hassan_Radi Below is the complete code and it’s error log.
Source Code:
public class AppiumServer {
static AppiumDriver driver = null;
static AndroidDriver androidDriver = null;

 public void startServer(){
  CommandLine command = new CommandLine("cmd");
  command.addArgument("/c");
  command.addArgument("D:/Appium/node.exe");
  command.addArgument("D:/Appium/node_modules/appium/bin/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) {
  AppiumServer server=new AppiumServer();
  System.out.println("---- Starting appium server ----");
  server.startServer();
  System.out.println("---- Appium server started Successfully ! ----");
  
  try {
    Thread.sleep(2000L);
    
    DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
	capabilities.setCapability(CapabilityType.VERSION, "4.2.2");
	capabilities.setCapability("platformName", "ANDROID");
	capabilities.setCapability("deviceName", "QO4301C12715");
	capabilities.setCapability("autoWebview", "true");
	capabilities.setCapability("appPackage", "com.android.settings");
	capabilities.setCapability("appActivity", "com.android.calendar.LaunchActivity");// com.android.calendar.LaunchActivity
	capabilities.setCapability("newCommandTimeout", "180");
	capabilities.setCapability("autoWebviewTimeout", "6000");
	driver = new AndroidDriver(new URL("http://127.0.0.1:4724/wd/hub"),capabilities);
	androidDriver = (AndroidDriver) driver;
	System.out.println("App Launched sucessfully:::");
    
  } catch (InterruptedException e) {
    e.printStackTrace();
  } catch (MalformedURLException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
  
  /*System.out.println("---- Stoping appium server ----");
  server.stopServer();
  System.out.println("---- Appium server stopped Successfully ! ----");*/
  
 }
 
}

Error Log:
---- Starting appium server ----
---- Appium server started Successfully ! ----
Exception in thread “main” org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: ‘2.46.0’, revision: ‘87c69e2’, time: ‘2015-06-04 16:17:10’
System info: host: ‘NAG1-LHP-41508’, ip: ‘172.18.36.99’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_67’
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:22)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:202)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:50)
at com.AppiumServer.main(AppiumServer.java:88)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4724 [/127.0.0.1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:134)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
… 10 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
… 23 more
e[33mwarne[39m: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
e[36minfoe[39m: Welcome to Appium v1.4.0 (REV 8f63e2f91ef7907aed8bda763f4e5ca08e86970a)
e[36minfoe[39m: Appium REST http interface listener started on 127.0.0.1:4724
e[36minfoe[39m: [debug] Non-default server args: {“address”:“127.0.0.1”,“port”:4724,“noReset”:true,“log”:“D:/appiumLogs.txt”}
e[36minfoe[39m: Console LogLevel: debug
e[36minfoe[39m: File LogLevel: debug

Need your help.


#102

@Nitinvermaa1
Look through your running processes for a process called node.ex, terminate that proces and give it another try.

basically you tried to connect while the server hasn’t started yet.

please refer to this article to get things starting easily. You will find a method called isServerRunning, use it to make sure that the server is up and running before you try to connect to it.


#103

@Hassan_Radi I refereed the article which you have provide and i am able to start the server and also cross verified in the task manager. But when i am setting up the capabilities i am getting the same error. Please find below code.

public class LaunchAppium {

static AppiumDriver driver;
@SuppressWarnings("rawtypes")
public static void main(String[] args) throws ExecuteException, IOException, InterruptedException {
	

	ServerArguments serverArguments = new ServerArguments();

	serverArguments.setArgument("--address", "127.0.0.1");

	serverArguments.setArgument("--chromedriver-port", 9516);

	serverArguments.setArgument("--bootstrap-port", 4725);

	serverArguments.setArgument("--no-reset", true);

	serverArguments.setArgument("--local-timezone", true);
	
	serverArguments.setArgument("--platform-name", "ANDROID");
	
	serverArguments.setArgument("--platform-version", "4.2.2");
	
	serverArguments.setArgument("--device-name", "QO4301C12715");
	
	serverArguments.setArgument("--app-pkg", "com.android.settings");
	
	serverArguments.setArgument("--app-activity", "com.android.calendar.LaunchActivity");
	
	AppiumServer _appiumServer = new AppiumServer(new File("D:/Appium"), serverArguments);
	_appiumServer.startServer();
	System.out.println(_appiumServer.isServerRunning());
	
	DesiredCapabilities capabilities = new DesiredCapabilities();
	/*capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
	capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
	capabilities.setCapability("platformName", "ANDROID");
	capabilities.setCapability("deviceName", "QO4301C12715");
	capabilities.setCapability("autoWebview", "true");
	capabilities.setCapability("appPackage", "com.android.settings");
	capabilities.setCapability("appActivity", "com.android.calendar.LaunchActivity");// com.android.calendar.LaunchActivity
	capabilities.setCapability("newCommandTimeout", "180");
	capabilities.setCapability("autoWebviewTimeout", "6000");*/
	driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"),null);
	AndroidDriver androidDriver = (AndroidDriver) driver;
	androidDriver.startActivity("com.android.settings",
			"com.android.settings.accounts.AddAccountSettings");
	System.out.println("App Launched sucessfully:::");
	
	
	
}

}

Error Log:
Aug 19, 2015 3:13:52 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server is starting…
Aug 19, 2015 3:13:53 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 19, 2015 3:13:55 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 19, 2015 3:13:57 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has not started yet. Trying again in one second…
Aug 19, 2015 3:13:58 PM com.github.genium_framework.appium.support.server.AppiumServer startServer
INFO: Server has been started successfully.
true
Aug 19, 2015 3:13:58 PM com.github.genium_framework.appium.support.server.AppiumServer isServerRunning
INFO: Checking to see if a server instance is running or not …
Exception in thread “main” org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: ‘2.46.0’, revision: ‘87c69e2’, time: ‘2015-06-04 16:17:10’
System info: host: ‘NAG1-LHP-41508’, ip: ‘172.18.36.99’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_67’
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:22)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:202)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:50)
at account.LaunchAppium.main(LaunchAppium.java:65)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4725 [/127.0.0.1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:134)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
… 10 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
… 23 more

Please help me to know how to initialize the appiumdriver or androiddriver with address and capabilities
driver = new AndroidDriver(new URL(“http://127.0.0.1:4725/wd/hub”),capabilities);

i also tried with UN-commenting the capabilities code. But still the same error.


#104

This line refers to the port number on the mobile device side and not the port number of the server as you think. The server argument for the server port number is –port. Refer to this for a list of all server arguments.

The issue you are experiencing is because you are starting Appium using the default port number 4723 and trying to connect to another connection that doesn’t exist:

Change it to be the following and it should work correctrly:

driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),null);


#106

@Hassan_Radi Thanks for helping me out. It worked at my end. Thank you!!


#107

Hi,

I did all the above mentioned steps but still not able to run appium server throug my Java code. Please the code below:

    public void startAppiumServer(){
        String nodeJspath="\"C:\\Progra~1\\nodejs\\node.exe\"";
        CommandLine command = new CommandLine("cmd");
        command.addArgument("/c");
        command.addArgument(nodeJspath);
        command.addArgument("\"C:\\Progra~2\\Appium\\node_modules\\appium\\bin\\appium.js\"");
        command.addArgument("--address");
        command.addArgument("127.0.0.1");
        command.addArgument("--port");
        command.addArgument("4723");
        command.addArgument("--full-reset", false); 
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
        DefaultExecutor executor = new DefaultExecutor();
        executor.setExitValue(1);
        try{
        executor.execute(command, resultHandler);
        }
        catch(Exception e){
            e.printStackTrace();
        }}
    @BeforeClass
public void setUp() throws MalformedURLException {
        startAppiumServer();
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.VERSION, "4.0.1");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"41000818edc99f00");
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE,"com.sec.android.app.popupcalculator");
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.sec.android.app.popupcalculator.Calculator");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

#108

I am seeing following error:

FAILED CONFIGURATION: @BeforeClass setUp
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: ‘2.45.0’, revision: ‘5017cb8e7ca8e37638dc3091b2440b90a1d8686f’, time: ‘2015-02-27 09:10:26’
System info: host: ‘Ramandeep-PC’, ip: ‘192.168.1.5’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_11’
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:22)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:202)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:50)
at first.appiumTest.Calculator_Automation.setUp(Calculator_Automation.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Please help


#109

Hi Guys,

I am unable to starting iOS webkit debug proxy server and get iPhone information( UDID, Device Name and Device Version) from Terminal Using Java Code in mac machine. Is it possible to get the iOS device information from terminal using java code in mac machine. This is priority work for me. Please help me any one.

Thanks in advance.


#110

Hi Guys,

I was able to launch appium server. It even got connected to the device. But, failed while launching the appium driver. I am getting the below error .
Error : “Could not initialize ideviceinstaller; make sure it is installed and works on your system”.
Please help me any one, thanks in advance.

Please find the below code and Console log.

Code:
Runtime.getRuntime().exec("/bin/bash export ANDROID_HOME=/Users/caaminf/Library/Android/sdk/");
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(“0.0.0.0”);
command.addArgument("–port", false);
command.addArgument(port);
command.addArgument("–no-reset", false);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try
{
executor.execute(command, resultHandler);
}
catch (ExecuteException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
Thread.sleep(9000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println(“Appium server started”);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
capabilities.setCapability(CapabilityType.VERSION, “8.4”);
capabilities.setCapability(CapabilityType.PLATFORM, “Mac”);
capabilities.setCapability(“deviceName”, “iPhone 5c”);
capabilities.setCapability(“device”, “iPhone”);
capabilities.setCapability(“platformName”, “iOS”);
capabilities.setCapability(“app”, " App.app");
capabilities.setCapability(“newCommandTimeout”, “180000”);
driver = new IOSDriver(new URL(“http://0.0.0.0:”+port+"/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);

Console Log:

e[36minfoe[39m: Welcome to Appium v1.4.8 (REV c81fa58b324491230df9342a)
e[36minfoe[39m: Appium REST http interface listener started on 0.0.0.0:50879
e[36minfoe[39m: [debug] Non-default server args: {“port”:50879,“noReset”:true}
e[36minfoe[39m: Console LogLevel: debug
Appium server started
e[36minfoe[39m: e[37m–>e[39m e[37mPOSTe[39m e[37m/wd/hub/sessione[39m e[90m{“desiredCapabilities”:{“newCommandTimeout”:“90”,“app”:”/App.app”,“deviceName”:“iPhone 5c”,“platformName”:“iOS”,“udid”:“1a6c5a1a”}}e[39m
e[36minfoe[39m: Client User-Agent string: Apache-HttpClient/4.3.1 (java 1.5)
e[36minfoe[39m: [debug] Using local app from desired caps: /App.app
e[36minfoe[39m: [debug] Creating new appium session 0faa9e2c2
e[36minfoe[39m: [debug] Removing any remaining instruments sockets
e[36minfoe[39m: [debug] Cleaned up instruments socket /tmp/instruments_sock
e[36minfoe[39m: [debug] Auto-detecting iOS udid…
e[36minfoe[39m: [debug] Not auto-detecting udid, running on sim
e[36minfoe[39m: [debug] Could not parse plist file (as binary) at /App.app/en.lproj/Localizable.strings
e[36minfoe[39m: Will try to parse the plist file as XML
e[36minfoe[39m: [debug] Could not parse plist file (as XML) at /App.app/en.lproj/Localizable.strings
e[33mwarne[39m: Could not parse app Localizable.strings assuming it doesn’t exist
e[36minfoe[39m: [debug] Getting bundle ID from app
e[36minfoe[39m: [debug] Parsed app Info.plist (as binary)
e[36minfoe[39m: [debug] Creating instruments
e[36minfoe[39m: [debug] Preparing uiauto bootstrap
e[36minfoe[39m: [debug] Dynamic bootstrap dir: /Users/caaminf/Library/Application Support/appium/bootstrap
e[36minfoe[39m: [debug] Dynamic env: {“nodePath”:"/Applications/Appium.app/Contents/Resources/node/bin/node",“commandProxyClientPath”:"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js",“instrumentsSock”:"/tmp/instruments_sock",“interKeyDelay”:null,“justLoopInfinitely”:false,“autoAcceptAlerts”:false,“autoDismissAlerts”:false,“sendKeyStrategy”:“grouped”}
…6minfoe[39m: [debug] Dynamic bootstrap code: // This file is automatically generated. Do not manually modify!
e[36minfoe[39m: [debug] Dynamic bootstrap path: /Users/caaminf/Library/Application Support/appium/bootstrap/bootstrap-674424bb0c0.js
e[36minfoe[39m: [debug] Reusing dynamic bootstrap: /Users/caaminf/Library/Application Support/appium/bootstrap/bootstrap-6744bb0c0.js
e[36minfoe[39m: [debug] Attempting iOS device log capture via libimobiledevice idevicesyslog
e[33mwarne[39m: Could not capture device log using libimobiledevice idevicesyslog. Libimobiledevice probably isn’t installed
e[36minfoe[39m: [debug] Attempting iOS device log capture via deviceconsole
e[36minfoe[39m: [debug] Creating iDevice object with udid dsfdasfasdfasfasa1a
e[36minfoe[39m: [debug] Couldn’t find ideviceinstaller, trying built-in at /Applications/Appium.app/Contents/Resources/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller
e[36minfoe[39m: [debug] Cleaning up appium session
e[31merrore[39m: Could not initialize ideviceinstaller; make sure it is installed and works on your system
e[31merrore[39m: Failed to start an Appium session, err was: Error: Could not initialize ideviceinstaller; make sure it is installed and works on your system
e[36minfoe[39m: [debug] Error: Could not initialize ideviceinstaller; make sure it is installed and works on your system
at [object Object].IOS.getIDeviceObj (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios.js:909:13)
at [object Object].IOS.installToRealDevice (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios.js:856:32)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:607:21
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:246:17
at iterate (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:146:13)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:157:25
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:248:21
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:612:34
at [object Object]. (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-crash-log.js:52:5)
at [object Object]. (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-crash-log.js:27:5)
at f (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/once/once.js:17:25)
at Glob. (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:131:7)
at Glob.emit (events.js:107:17)
at Glob._finish (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:168:8)
at done (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:157:12)
at Glob._processReaddir2 (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:351:12)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:288:17
at RES (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/inflight/inflight.js:23:14)
at f (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/once/once.js:17:25)
at Glob._readdirEntries (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:480:10)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:457:12
at FSReqWrap.oncomplete (fs.js:95:15)
e[36minfoe[39m: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: Could not initialize ideviceinstaller; make sure it is installed and works on your system)”,“origValue”:“Could not initialize ideviceinstaller; make sure it is installed and works on your system”},“sessionId”:null}
e[36minfoe[39m: e[37m<-- POST /wd/hub/session e[39me[31m500e[39me[90m 1386.268 ms - 300e[39m e[90me[39m
Report :Error ID 46: Could not open Browserorg.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Could not initialize ideviceinstaller; make sure it is installed and works on your system) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.59 seconds
Build info: version: ‘2.45.0’, revision: ‘5017cb8’, time: ‘2015-02-27 00:00:10’
System info: host: ‘sunils-MBP-2’, ip: ‘195.106.980’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.2’, java.version: ‘1.7.0_79’
Driver info: io.appium.java_client.ios.IOSDriver


#111

Sounds like you need to run ‘reset.sh’ in the root directory of the Appium repo. If you read the script you’ll see that it checks out the git submodules and then builds those products (like ideviceinstaller). Alternatively, you could run those commands by hand.