Launching and stopping appium server programmtically


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


#112

@wreed
Thank you so much for the quick reply. will, try it out.


#113

@wreed

I have tried below ways but still I am getting error.

Case 1:
Still I am getting Errors “Couldn’t find ideviceinstaller, trying built-in at /Applications/Appium.app/Contents/Resources/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller” and " Could not initialize ideviceinstaller; make sure it is installed and works on your system", even I have ran below commands on Terminal.

Root directory : /Users/caaminf/appium
Commands:
git checkout v1.3.3
./reset.sh
brew install --HEAD ideviceinstaller // suggested in another post.
git checkout v1.3.4
./reset.sh
node . - UDID --full-reset ----> I am unable to run this command

Case 2:
As per my understanding appium checking ideviceinstaller is installed or not in the root directory

/Applications/Appium.app/Contents/Resources/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller.

I am unable to change the directory to
/Applications/Appium.app/Contents/Resources/node_modules/appium/build/libimobiledevice-macosx/.

Please correct me if I am wrong.

Could you please provide the root directory of the Appium repo.

Thanks in advance.

Please find the following details and let me know if any incompatability versions.

Xcode version : 6.4
iPhone 5c : 8.4
Appium Version : 1.4.0

Note :- I am getting this “ideviceinstaller” error only when starting appium server programmatically and running test script. It is working fine when manually starting appium server and running test script.


#114

Your server instance hasn’t started yet and you tried to connect to it which caused the exception to be thrown, please refer to the following article to get things started easily: https://github.com/Genium-Framework/Appium-Support/wiki


#115

@Hassan_Radi

Thanks for reply, Could you please elaborate the steps for starting server instance.

Thanks in advance.


#116

If you can just refer to my last comment, you will find a link an article that describes how to do that in details.


#117

@Hassan_Radi

I have gone through the link which you mentioned above, but I did’t find anything related mac.

Could you please share the link for starting appium server programmatically on mac machine.

Thanks in advance.


#118

It is the same code on MAC. no change is required, the library handles everything on your behalf.


#119

This class solved my problem , including waiting for the server is functional without threadSleep . In my case the Windows operating system. Consider that the node is defined in the operating system path and appium server as well.

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 org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;

public class ServerAppium {

static boolean flagStop = true;

public static void IniciarServidorAppium() throws ExecuteException, IOException, InterruptedException {
	String path = new File(".").getCanonicalPath();

	if (!new File(path + "\\log").exists() || !new File(path + "\\apk").exists() ) {
		(new File(path + "\\log")).mkdir();
		(new File(path + "\\apk")).mkdir();
	}
	CommandLine command = new CommandLine("cmd");
	command.addArgument("/c");
	command.addArgument("appium");
	command.addArgument("--address");
	command.addArgument("127.0.0.1");
	command.addArgument("--port");
	command.addArgument("4723");
	command.addArgument("--session-override");
	command.addArgument("--log");
	command.addArgument(path + "\\log\\appiumLogs_" + System.currentTimeMillis() + ".txt");

	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);

	DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
	final DefaultExecutor executor = new DefaultExecutor();
	executor.setStreamHandler(streamHandler);
	executor.execute(command, resultHandler);

	while (flagStop) {
		Thread.sleep(2000);
		String result = outputStream.toString();
		if (result.contains("Couldn't start Appium")) {
			System.out.println("Server appium já está em execução");
			PararServidorAppium();
			IniciarServidorAppium();
			flagStop = false;
		} else if (result.contains("Welcome to Appium") && result.contains("File LogLevel")) {
			System.out.println(result);
			result = outputStream.toString();
			FileUtils.cleanDirectory(new File("apk"));
			flagStop = false;
		}
	}

}

public static void PararServidorAppium() throws ExecuteException, IOException, InterruptedException {

	String command = "cmd /c taskkill /im node.exe /f";
	try {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		CommandLine commandline = CommandLine.parse(command);
		DefaultExecutor exec = new DefaultExecutor();
		PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
		exec.setStreamHandler(streamHandler);
		exec.execute(commandline);
		
		flagStop = true;
		while (flagStop) {
			Thread.sleep(2000);
			String result = outputStream.toString();
			System.out.println("Processo node.exe finalizado com sucesso!");
			if (result.contains("node") && result.contains("finalizado")) {
				break;
			} else {
				Thread.sleep(2000);
				flagStop = false;
			}
		}
	} catch (Exception e) {
		System.out.println("Node já encerrado!");
	}

}

}


#120

Hi guys! Please look at this

It probably will be the standart feature of the Appium java_client after the merging.


#121

Thanks Sergey :smile: It is about time :smile: