iDevice installer issue in an attempt to invoke appium server through code. However it works perfectly fine when started server through GUI

iDevice installer issue in an attempt to invoke appium server through code. However it works perfectly fine when started server through GUI.

I’m noticing this issue recently as my entire code was working good for past 20+ days.

My Thoughts:-

May be it can work good if I upgrade appium. I am extremely concerned with the support that upgraded appium can provided to my iOS. As my code is currently working good with better test coverage, I am not willing to go for an option which could disturb flow now.

Error displayed:
error: Could not initialize ideviceinstaller; make sure it is installed and works on your system

Logs:

error: Could not initialize ideviceinstaller; make sure it is installed and works on your system

TestNG] Running:

/Users/v4/Documents/Scopeappiumautomation/com.S2B_NextGen.Mobile.iOS/testng.xml

Appium process running … configuration in progress …

Current OS in usuage Mac OS X

Path of WorkSpace /Users/XX/Documents/XXXX/com.XX.Mobile.iOS

iOS Webkit debug proxy : Started

Appium server stopped.

iOS Webkit proxy stopped

arguements[Ljava.lang.String;@67784306

Server Flags : Completed.

Default Executor : executed commands.

Appium Server starting the PROCESS

info: [debug] Starting Appium in pre-launch mode

info: Pre-launching app

info: [debug] App is an iOS bundle, will attempt to run as pre-existing

info: [debug] Creating new appium session 3XXXXXX-cc09-4df2-ba2b-eb00f31f1834

info: [debug] Removing any remaining instruments sockets

info: [debug] Cleaned up instruments socket /tmp/instruments_sock

info: [debug] Auto-detecting iOS udid…

info: [debug] Not auto-detecting udid, running on sim

info: [debug] Could not parse plist file (as binary) at /Applications/Appium.app/Contents/Resources/node_modules/appium/com.XX.XXX.mobile/en.lproj/Localizable.strings

info: Will try to parse the plist file as XML

info: [debug] Could not parse plist file (as XML) at /Applications/Appium.app/Contents/Resources/node_modules/appium/com.XX.XXXX.mobile/en.lproj/Localizable.strings

warn: Could not parse app Localizable.strings assuming it doesn’t exist

info: [debug] Creating instruments

info: [debug] Preparing uiauto bootstrap

info: [debug] Dynamic bootstrap dir: /Users/v4/Library/Application Support/appium/bootstrap

info: [debug] Dynamic env: {“nodePath”:"/Applications/Appium.app/Contents/Resources/node/bin/node",“commandProxyClientPath”:"/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-uiauto/bin/command-proxy-client.js",“instrumentsSock”:"/tmp/instruments_sock",“interKeyDelay”:null,“justLoopInfinitely”:false,“autoAcceptAlerts”:false,“autoDismissAlerts”:false,“sendKeyStrategy”:“grouped”}

info: [debug] Dynamic bootstrap code: // This file is automatically generated. Do not manually modify!

info: [debug] Dynamic bootstrap path: /Users/XXX/Library/Application Support/appium/bootstrap/bootstrap-5923cadea0343e3f.js

info: [debug] Reusing dynamic bootstrap: /Users/XXX/Library/Application Support/appium/bootstrap/bootstrap-5923cadea0343e3f.js

info: [debug] Attempting iOS device log capture via libimobiledevice idevicesyslog

warn: Could not capture device log using libimobiledevice idevicesyslog. Libimobiledevice probably isn’t installed

info: [debug] Attempting iOS device log capture via deviceconsole

info: [debug] Creating iDevice object with udid aaXXXXX332360d4006c16d9ad7fXXb462c4e132c

info: [debug] Couldn’t find ideviceinstaller, trying built-in at /Applications/Appium.app/Contents/Resources/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller

error: Could not initialize ideviceinstaller; make sure it is installed and works on your system

info: [debug] Cleaning up appium session

error: Could not pre-launch appium: Error: Could not initialize ideviceinstaller; make sure it is installed and works on your system

Appium Server Started

killing the existing sessions

Sessions cleared

Environment:

Appium:1.4.13
Xcode: 7.3.1
iOS: 9.3.1
Home Brew: 1.1.10
Java: 8

What I’m trying to accomplish?

Invoking Appium server programmatically by using command line class.

Steps taken to correct it:-

A)

Try unlink and link
brew unlink ideviceinstaller
brew link ideviceinstaller

B)

brew install ideviceinstaller…

it should probably tell if device installer is present or not.

C)

If step 1 and 2 do not work then , uninstall home brew and iDevice Installer.

uninstall home-brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)”

uninstall iDeviceInstaller:

brew uninstall ideviceinstaller.

install home brew:

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
install device installer:

brew install ideviceinstaller.

one can test luck with these two commands as well if nothing works on top.
brew install --HEAD ideviceinstaller

node . -U --full-reset

To check the success.
ideviceinstaller -u aa794fc332360d4006c16d9ad7f82b462c4e132c
-i
-i can be changed to -l (to list apps) and — u (to display uDID) and many

D) I also tried by setting path in eclipse.

Code:
public void start(){

System.out.println(“Appium process running … configuration in progress …”);

String currentOS = System.getProperty(“os.name”);

System.out.println("Current OS in usuage " + currentOS);

File classPathRoot = new File(System.getProperty(“user.dir”));

System.out.println("Path of WorkSpace " +classPathRoot);
}

@Test(groups={“serverConfiguration”})

public void startWebkitProxy() throws IOException{

/********************Block of code is not applicable for Android **************/

/*******

Command provided in terminal to start webkit to initiate communication for mobile safari and uiwebview.

“ios_webkit_debug_proxy -c :27753 -d”

*******/

CommandLine iOSWebkitDebugProxyCommand = new CommandLine(“ios_webkit_debug_proxy”);

iOSWebkitDebugProxyCommand.addArgument("-c");

iOSWebkitDebugProxyCommand.addArgument(udidOfDevice+":27753"); //port number assigned.

iOSWebkitDebugProxyCommand.addArgument("-d"); // “-f” to disable the console output in eclipse.

DefaultExecuteResultHandler iOSWebkitResultHandler = new DefaultExecuteResultHandler();

DefaultExecutor iOSProxyexecutor = new DefaultExecutor();

iOSProxyexecutor.setExitValue(1);

try {

iOSProxyexecutor.execute(iOSWebkitDebugProxyCommand, iOSWebkitResultHandler);

iOSWebkitResultHandler.toString();

Thread.sleep(80000);

System.out.println(“iOS Webkit debug proxy : Started”);

} catch (IOException e) {

System.out.println(“Failed to start iOS Webkit debug Proxy” + iOSWebkitResultHandler.getException() + “and the exception is” + e);

e.printStackTrace();//paste the complete trace.

} catch (InterruptedException e) {

System.out.println(“Failed to start iOS Webkit debug Proxy”+ iOSWebkitResultHandler.getException() + “and the exception is” + e);

e.printStackTrace();//paste the complete trace.

}

}

@Test(groups ={“serverConfiguration”},dependsOnMethods={“startWebkitProxy”})

public void startAppiumServer() throws InterruptedException, ExecuteException, IOException{

/*

*  Passing arguments/commands to configure Appium server.

*  

*  Incase of android add commands "--app-pkg","--app-activity", "--app-wait-package","--app-wait-activity"

*/

commandAppiumServer = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");

commandAppiumServer.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js", false);

commandAppiumServer.addArgument("–address", true); // ip address to listen on

commandAppiumServer.addArgument(“127.0.0.1”);

commandAppiumServer.addArgument("–port", true); // Port to listen on

commandAppiumServer.addArgument(driverPort);

commandAppiumServer.addArgument("–no-reset", false); // To avoid resetting the app between sessions.

// commandAppiumServer.addArgument("–full-reset", false); // Enable if you want to uninstall the app.

// commandAppiumServer.addArgument("–log-level", false); // Will block the console logs in eclipse

commandAppiumServer.addArgument("–session-override", true); // Permits to create multiple sessions

commandAppiumServer.addArgument("–pre-launch", true);

/*

Aruguments to Run your script in browser. Pass “Chrome” incase of android
commandAppiumServer.addArgument("–browser-name");

commandAppiumServer.addArgument(“Safari”);

commandAppiumServer.addArgument("–safari", false);
*/

commandAppiumServer.addArgument("–log",false); // To save Logs.

commandAppiumServer.addArgument("/tmp/file.log");

commandAppiumServer.addArgument("–log-no-colors", true);

commandAppiumServer.addArgument("–platform-name"); //

commandAppiumServer.addArgument(“iOS”);

commandAppiumServer.addArgument("–platform-version");

commandAppiumServer.addArgument(“9.3.4”);

commandAppiumServer.addArgument("–device-name");

commandAppiumServer.addArgument(“S2bv4010 Ipad”);

commandAppiumServer.addArgument("–udid");

commandAppiumServer.addArgument(udidOfDevice);

commandAppiumServer.addArgument("–app");

commandAppiumServer.addArgument(“com.sc.s2bng.mobile”);

commandAppiumServer.addArgument("–command-timeout");

commandAppiumServer.addArgument(“7200”); //by default timeout will be 60 seconds.

// commandAppiumServer.addArgument("–webkit-debug-proxy-port");

// commandAppiumServer.addArgument(“27753”);

System.out.println(“arguements”+ commandAppiumServer.getArguments());
System.out.println(“Server Flags : Completed.”);

/*

Customizing logs with time stamp information.

Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime());

commandAppiumServer.addArgument("/Users/XXX/appium"+currentTimestamp+".log");

*/

DefaultExecuteResultHandler serverResultHandler = new DefaultExecuteResultHandler();

DefaultExecutor executor = new DefaultExecutor();

executor.setExitValue(1);

System.out.println(“Default Executor : executed commands.”);
try {

executor.execute(commandAppiumServer, serverResultHandler);

System.out.println(“Appium Server starting the PROCESS”);

Thread.sleep(80000); //Waiting to complete the server start

System.out.println(“Appium Server Started”);

} catch (ExecuteException e) {

System.out.println(“Failed to start Appium server” + serverResultHandler.getException() + “and the exception is”+ e);

e.printStackTrace();

} catch (IOException e) {

System.out.println(“Failed to start Appium server” + serverResultHandler.getException() + “and the exception is” + e);

e.printStackTrace();

}

/*

Another way to start Appium Service

appiumService = AppiumDriverLocalService.buildDefaultService();

appiumServerURL= appiumService.getUrl().toString();

System.out.println("Appium service URL " + appiumServerURL);

AppiumDriverLocalService appiumservice = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()

.usingDriverExecutable(new File("/Applications/Appium.app/Contents/Resources/node/bin/node"))

.withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js"))

.withLogFile(new File("/Users/XXXX/Documents/log.txt")));

appiumservice.start();
*/

}

@Test(groups={“serverConfiguration”},dependsOnMethods={“startAppiumServer”})

public void killExistingSessions() throws ExecuteException, IOException {

/**

Kill the existing sessions corresponding to the port number.

*/

System.out.println(“killing the existing sessions”);

// { “/usr/bin/killall”, “-9”, “node” };

CommandLine command = new CommandLine("/usr");

command.addArgument("/bin");

command.addArgument(“killall”);

command.addArgument("-9");

command.addArgument(“node”);

DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

DefaultExecutor executor = new DefaultExecutor();
// System.out.println(“Execution status of killing session” + executor.execute(command));

executor.setExitValue(1);

try {

executor.execute(command, resultHandler);

System.out.println(“Sessions cleared”);

} catch (IOException e) {

System.out.println(“Failed to pre kill the appium session” + e);
e.printStackTrace();//paste the complete trace.

}
}

@Test(groups={“serverConfiguration”})

public void stop(){

//Stopping the appium server

String[] commandStopServer = { “/usr/bin/killall”, “-9”, “node” };

try {

Runtime.getRuntime().exec(commandStopServer);

System.out.println(“Appium server stopped.”);

} catch (IOException e) {

e.printStackTrace();

}

//Stop the webkit proxy

String[] commandStopProxy = { “/usr/bin/killall”, “-9”, “ios_webkit_debug_proxy” };

try {

Runtime.getRuntime().exec(commandStopProxy);

System.out.println(“iOS Webkit proxy stopped”);

} catch (IOException e) {

e.printStackTrace();

}