Especially when working with Appium (1.4.16), Android Studio (2.2.3 and above) and with Android N (7.0) version, execution of test automation script encounters the below error:
Error: Command failed: C:\Windows\system32\cmd.exe /s /c “C:\Users\{user}\AppData\Local
Error you see in Appium server:
info: [debug] Error: Command failed: C:\Windows\system32\cmd.exe /s /c "C:\Users\132266\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "ps 'uiautomator'"" > > at ChildProcess.exithandler (child_process.js:751:12) > at ChildProcess.emit (events.js:110:17) > at maybeClose (child_process.js:1016:16) > at Process.ChildProcess._handle.onexit (child_process.js:1088:5) > info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Command failed: C:\\Windows\\system32\\cmd.exe /s /c \"C:\\Users\\132266\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -s emulator-5554 shell \"ps 'uiautomator'\"\"\n)","killed":false,"code":1,"signal":null,"cmd": "C:\\Windows\\system32\\cmd.exe /s /c \"C:\\Users\\{user}\\AppData\\Local\\Android\\sdk\\ platform-tools\\adb.exe -s emulator-5554 shell \"ps 'uiautomator'\"\"","origValue": "Command failed: C:\\Windows\\system32\\cmd.exe /s /c \"C:\\Users\\{user}\\AppData\\Local \\Android\\sdk\\platform-tools\\adb.exe -s emulator-5554 shell \"ps 'uiautomator'\"\"\n"}, "sessionId":null} > info:
Error in Android studio run console:
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c "C:\Users\{user}\AppData\ Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "ps 'uiautomator'"" ) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds
Solution for this error is to append and replace the code in adb.js file present at location
C:\Program Files (x86)\Appium\node_modules\
Code changes to be done goes as below:
- Go to adb.js in the path ‘node_modules//appium/node_modules/appium-adb/lib/adb.js’
***Find the below**ADB.prototype.shell = function (cmd, cb) { if (cmd.indexOf('"') === -1) { cmd = '"' + cmd + '"'; } var execCmd = 'shell ' + cmd; this.exec(execCmd, cb); };
Append the below
ADB.prototype.shell_grep = function (cmd, grep, cb) { if (cmd.indexOf('"') === -1) { cmd = '"' + cmd + '"'; } var execCmd = 'shell ' + cmd + '| grep ' + grep; this.exec(execCmd, cb); };
- Find the ‘ADB.prototype.getPIDsByName ‘ and replace the whole section
ADB.prototype.getPIDsByName = function (name, cb) { logger.debug("Getting all processes with '" + name + "'"); this.shell_grep("ps", name, function (err, stdout) { if (err) { logger.debug("No matching processes found"); return cb(null, []); } var pids = []; _.each(procs, function (proc) { var match = /[^\t ]+[\t ]+([0-9]+)/.exec(proc); if (match) { pids.push(parseInt(match[1], 10)); } }); if (pids.length !== procs.length) { var msg = "Could not extract PIDs from ps output. PIDS: " + JSON.stringify(pids) + ", Procs: " + JSON.stringify(procs); return cb(new Error(msg)); } cb(null, pids); }); };
Performing above changes you are good to go ahead, for more detail you can refer to the actual discussion at appium support website
Hi Team,
This is really helpful. Thanks a lot for the fix.
Regards,
ABD.
Hi AB Devilliers,
Thank you so much for reaching to us, we are glad that it helped you in solving the issue.
Awesome Your Really Really Great………. Thanks a lot friend… its works……..
Thank you and glad to know that it worked for you 🙂
Thank you so much!!!!!!! This fix is a blessing
I am glad it helped you..
how you guys are able to edit and save the adb.js.UN file. i’m able to retrieve the file in eclipse but couldn’t save it after changes. please help me
you need to have admin privileges to edit the file
Worked like a charm. Thank you so much.
Great! You are welcome dhinakaran.. keep reading 🙂
Super dude. You are the best 😉
Thank you for the compliments, may be you can share how we have been help to you 🙂