Appium sample calculator test fails with ERROR: no dump file specified - java

I'm trying to run a sample test for a native Calculator app on a real Android 4.1.2 device. I'm using Appium(run as admin) on Windows, Selendroid and Eclipse.
My sample code is
#BeforeClass
public void setUp() throws MalformedURLException{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "");
capabilities.setCapability("automationName", "Selendroid");
capabilities.setCapability("platformVersion", "4.1.2");
capabilities.setCapability("deviceName","0123456789ABCDEF");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity","com.android.calculator2.Calculator");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
From what i have found on different forums and resources, it is possible to refer to the necessary application only by its package name and the launcher activity(without providing the .apk). However, for some reason Appium fails when not provided with the dump. The log of the failure is
> Checking if an update is available
> Update not available
> Starting Node Server
> info: Welcome to Appium v1.3.7 (REV 72fbfaa116d3d9f6a862600ee99cf02f6d0e2182)
> info: Appium REST http interface listener started on 127.0.0.1:4723
> info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"16","automationName":"Selendroid"}
> info: Console LogLevel: debug
> info: --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.android.calculator2","app":"Calculator.apk","appActivity":"com.android.calculator2.Calculator","BROWSER_NAME":"Chrome","platformVersion":"4.1.2","automationName":"Selendroid","platformName":"Android","deviceName":"0123456789ABCDEF"}}
> info: Client User-Agent string: Apache-HttpClient/4.3.6 (java 1.5)
> info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : BROWSER_NAME
> info: [debug] App is an Android package, will attempt to run on device
> info: [debug] Creating new appium session 9942d26b-d1c1-43c8-9c6b-a9c4382d5ac9
> info: [debug] Starting selendroid server
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_45
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from D:\Android\android-sdk\platform-tools\adb.exe
> info: [debug] Checking whether selendroid is built yet
> info: [debug] Selendroid server exists!
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Not checking whether app is present since we are assuming it's already on the device
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: D:\Android\android-sdk\platform-tools\adb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device 0123456789ABCDEF
> info: [debug] Setting device id to 0123456789ABCDEF
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: D:\Android\android-sdk\platform-tools\adb.exe -s 0123456789ABCDEF wait-for-device
> info: [debug] executing cmd: D:\Android\android-sdk\platform-tools\adb.exe -s 0123456789ABCDEF shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Checking whether aapt is present
> info: [debug] Using aapt from D:\Android\android-sdk\build-tools\22.0.1\aapt.exe
> info: [debug] Checking if has internet permission from manifest.
> info: [debug] executing cmd: D:\Android\android-sdk\build-tools\22.0.1\aapt.exe dump badging
> warn: ERROR: no dump file specified
>
> error: Failed to start an Appium session, err was: Error: hasInternetPermissionFromManifest failed. Error: Command failed: ERROR: no dump file specified
>
> info: [debug] Cleaning up appium session
> info: [debug] Error: hasInternetPermissionFromManifest failed. Error: Command failed: ERROR: no dump file specified
>
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1661:19
> at ChildProcess.exithandler (child_process.js:641:7)
> at ChildProcess.EventEmitter.emit (events.js:98:17)
> at maybeClose (child_process.js:743:16)
> at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: hasInternetPermissionFromManifest failed. Error: Command failed: ERROR: no dump file specified\r\n)","origValue":"hasInternetPermissionFromManifest failed. Error: Command failed: ERROR: no dump file specified\r\n"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 635.247 ms - 318
Is there a way around this?

This code works on my Android device. I able to launch the calculator app w/o path to apk.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium-version", "1.1.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "my_device_name");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("device", "Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
serverAddress = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AndroidDriver(serverAddress, capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Here is what i was able to figure out:
Please note that I'm running Android 4.1.2 and have to use Selendroid
Selendroid requires the <uses-permission android:name="android.**permission.INTERNET"/> permission for the app
What i guess here is that it then uses aapt to parse the .apk file, because
Once i provide the .apk file extracted from the phone, it actually passes on to the next step where it parses the manifest and looks for the permission
So to sum up: if i'm using Selendroid, i have to provide .apk and my .apk has to have Internet permission. That is why Calculator test won't work here.

I think the problem will be solved if we rebuild the apk. I faced this issue in the past and I was able to get over it after rebuilding the apk.
Regards
Jnaneswar

Related

Getting A new session could not be created

Can anyone help me out I am new to Android testing with Appium , I am trying to open app in AVD the app getting installed but then m getting Error "A new Session could not be created.(Original error: Command failed: )","killed":false,"code":1,"signal":null,"origValue":"Command failed: "},"sessionId":null}
Thanks for the help in advance
tried with just giving capabilities.setCapability("appActivity", ".MainActivity");
'''
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/Apps/src/");
File app = new File(appDir, "ChatApp-release.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "emulator-5554");
capabilities.setCapability("platformVersion", "7.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.aaa.charla");
capabilities.setCapability("appActivity", "com.aaa.xxx.MainActivity");
driver = new AndroidDriver(new URL("https://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.quit();
Following are the Debug log:
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"D:\AndroidNew\Yrreport\YrReport\RemoteSystemsTempFiles\Appium\apk\ChatApp-master-0.9.35.1195-release.apk","appPackage":"com.odysseyinc.charla","appActivity":"com.odyssey.chatapp.MainActivity","newCommandTimeout":"10000","platformName":"Android","version":"7.1.1","deviceName":"emulator-5554"}}
info: Client User-Agent string: Apache-HttpClient/4.5.2 (Java/1.8.0_162)
info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : version
info: [debug] Using local app from desired caps: D:\AndroidNew\Yrreport\YrReport\RemoteSystemsTempFiles\Appium\apk\ChatApp-master-0.9.35.1195-release.apk
info: [debug] Creating new appium session 0d25aeac-d055-449f-af84-b6d314d9b4a5
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.8.0_162
info: [debug] Checking whether adb is present
info: [debug] Using adb from C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe
info: [debug] Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device emulator-5554
info: [debug] Setting device id to emulator-5554
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 wait-for-device
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Getting device API level
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 25
info: Device API level is: 25
info: [debug] Extracting strings for language: default
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell "getprop persist.sys.language"
info: [debug] Current device persist.sys.language:
info: [debug] java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "D:\AndroidNew\Yrreport\YrReport\RemoteSystemsTempFiles\Appium\apk\ChatApp-master-0.9.35.1195-release.apk" "C:\Users\UNMESH~1.GHA\AppData\Local\Temp\com.odysseyinc.charla"
info: [debug] Reading strings from converted strings.json
info: [debug] Setting language to default
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 push "C:\Users\UNMESH~1.GHA\AppData\Local\Temp\com.odysseyinc.charla\strings.json" /data/local/tmp
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\build-tools\28.0.3\aapt.exe
info: [debug] Retrieving process from manifest.
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\build-tools\28.0.3\aapt.exe dump xmltree D:\AndroidNew\Yrreport\YrReport\RemoteSystemsTempFiles\Appium\apk\ChatApp-master-0.9.35.1195-release.apk AndroidManifest.xml
info: [debug] Set app process to: com.odysseyinc.charla
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Checking app cert for D:\AndroidNew\Yrreport\YrReport\RemoteSystemsTempFiles\Appium\apk\ChatApp-master-0.9.35.1195-release.apk.
info: [debug] executing cmd: java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\verify.jar" D:\AndroidNew\Yrreport\YrReport\RemoteSystemsTempFiles\Appium\apk\ChatApp-master-0.9.35.1195-release.apk
info: [debug] App already signed.
info: [debug] Zip-aligning D:\AndroidNew\Yrreport\YrReport\RemoteSystemsTempFiles\Appium\apk\ChatApp-master-0.9.35.1195-release.apk
info: [debug] Checking whether zipalign is present
info: [debug] Using zipalign from C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\build-tools\28.0.3\zipalign.exe
info: [debug] Zip-aligning apk.
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\build-tools\28.0.3\zipalign.exe -f 4 D:\AndroidNew\Yrreport\YrReport\RemoteSystemsTempFiles\Appium\apk\ChatApp-master-0.9.35.1195-release.apk C:\Users\UNMESH~1.GHA\AppData\Local\Temp\119427-15556-1rmbgw9\appium.tmp
info: [debug] MD5 for app is f3d7efc8b197792c3d0529a48dc92ff2
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell "ls /data/local/tmp/f3d7efc8b197792c3d0529a48dc92ff2.apk"
info: [debug] Getting install status for com.odysseyinc.charla
info: [debug] Getting device API level
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 25
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell "pm list packages -3 com.odysseyinc.charla"
info: [debug] App is installed
info: App is already installed, resetting app
info: [debug] Running fast reset (stop and clear)
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell "am force-stop com.odysseyinc.charla"
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 shell "pm clear com.odysseyinc.charla"
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device...
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 push "C:\Program Files (x86)\Appium\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/local/tmp/
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: C:\Users\unmesh.ghatbandhe\AppData\Local\Android\Sdk\platform-tools\adb.exe -s emulator-5554 install "C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
warn: UiAutomator did not shut down fast enough, calling it gone
error: Failed to start an Appium session, err was: Error: Command failed: adb: failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Error: Command failed: adb: failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
at ChildProcess.exithandler (child_process.js:637:15)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Command failed: adb: failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n)","killed":false,"code":1,"signal":null,"origValue":"Command failed: adb: failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n"},"sessionId":null}
info: <-- POST /wd/hub/session 500 32039.992 ms - 664
`
You need to share the full appium logs in order to know the reason for that.
[After checking the logs]
That's a known issue for that specific Android image as it installs 2 versions of appium settings app and unlock app. What you can do is either change the android image you are testing against or uninstall those 2 apps before starting your script.
You can uninstall them manually by starting the emulator GUI and do that with the mouse or through the below commands:
adb -s device_serial uninstall io.appium.settings
adb -s device_serial uninstall io.appium.unlock
Also, you can add those commands in your code if you really have to execute the tests on android 7 devices as below:
String androidVersion=executeCommand("adb shell getprop ro.build.version.release");
if(androidVersion.contains("7"))
{
//uninstall appium settings app
cmd="adb uninstall io.appium.settings";
executeCommand(cmd);
//uninstall appium unlock app
cmd="adb uninstall io.appium.unlock";
executeCommand(cmd);
}
I have upgraded the Appuim 1.4 to 1.9 and started working as Expected .

Appium session, could not find a connected Android device. Shows error

Appium session, could not find a connected Android device. Shows error in eclipse
If any one know how to fix please let me know.
**The Junit code: - **
import static org.junit.Assert.*;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
public class desiredCapab {
#Test
public void test() throws MalformedURLException {
File appDir = new File("C:\\Eclipse-Neon\\Project\\AppiumT\\Apk\\");
File app = new File (appDir, "WhatsApp.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
AndroidDriver driver = new AndroidDriver(new URL ("http://127.0.0.1:4723/wd/hub"), cap);
//{"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"23","automationName":"Appium"}
}
}
Eclipse Junit Error :-
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Could not find a connected Android device.) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 28.61 seconds
Build info: version: '2.49.0', revision: '365eeb4', time: '2016-01-13 18:33:29'
System info: host: 'DESKTOP-PC1SJR4', ip: '192.168.1.104', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
AVD manager setting: - Image
Appium :- Error message
> info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"C:\\Eclipse-Neon\\Project\\AppiumT\\Apk\\WhatsApp.apk","platformName":"Android","deviceName":"Android Emulator"}}
> info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_91)
> info: [debug] No appActivity desired capability or server param. Parsing from apk.
> info: [debug] No appPackage desired capability or server param. Parsing from apk.
> info: [debug] Using local app from desired caps: C:\Eclipse-Neon\Project\AppiumT\Apk\WhatsApp.apk
> info: [debug] Creating new appium session c9232f90-f519-4058-9e80-22cd2830de57
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_101
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe
> info: [debug] Parsing package and activity from app manifest
> info: [debug] Checking whether aapt is present
> info: [debug] Using aapt from C:\Users\bizBoxChat\AppData\Local\Android\sdk\build-tools\24.0.3\aapt.exe
> info: [debug] Extracting package and launch activity from manifest.
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\build-tools\24.0.3\aapt.exe dump badging C:\Eclipse-Neon\Project\AppiumT\Apk\WhatsApp.apk
> info: [debug] badging package: com.whatsapp
> info: [debug] badging act: com.whatsapp.Main
> info: [debug] Parsed package and activity are: com.whatsapp/com.whatsapp.Main
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Checking whether app is actually present
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> warn: UiAutomator did not shut down fast enough, calling it gone
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> error: Failed to start an Appium session, err was: Error: Could not find a connected Android device.
> info: [debug] Error: Could not find a connected Android device.
> at [object Object].ADB.getDevicesWithRetry (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:606:15)
> at [object Object].androidCommon.prepareActiveDevice (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:400:12)
> at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:326:26)
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:607:21
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:246:17
> at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:146:13)
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:157:25
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:248:21
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:612:34
> at [object Object].androidCommon.ensureDeviceLocale (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:371:45)
> at [object Object].androidCommon.prepareEmulator (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:364:10)
> at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:325:26)
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:607:21
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:246:17
> at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:146:13)
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:157:25
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:248:21
> at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:612:34
> at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:344:9)
> at FSReqWrap.oncomplete (fs.js:95:15)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not find a connected Android device.)","origValue":"Could not find a connected Android device."},"sessionId":null}
> info: <-- POST /wd/hub/session 500 28492.200 ms - 206
Reason of above error is, any device or AVD could not be found to be connected. Following lines in your error message show this:
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] Error: Could not find a connected Android device.
Just creating AVD in AVD manager is not sufficient. It has to be up and running (started and ready). To do that, select any AVD in your AVD manager, and click on "Start" button. Let the AVD boot. Wait. (It is similar to a real device switching on.)
Or, some real device needs to be connected. In that device, "Developer Options" should be On. "USB debugging" should be On.
Go to command prompt and run following command:
adb devices
Expected output: Some device or AVD should be shown as connected.
Once you see any device or AVD connected, and retry, then your problem will be solved.
Note:
On running "adb devices" command in command window, if you see message like "abd.exe is an unrecognized internal or external command or batch file...", then you need to have adb.exe in path. You can add its path in environment variables, or simply run following command before running "adb devices":
set path=%PATH%;"D:\AndroidSDK\platform-tools"
Note that adb.exe file is in platform-tools folder on my PC, in Android SDK folder. You will need to modify this path as it is on your PC.
Try to use real device, since emulators are very slow and booting time will also take more time. Even real device also I was facing this kind of issue,
Expecting causes :
Android emulator startup issue
ADB issue
System config
If adb issue, you need run following command in your cmd:
adb kill-server
adb start-server
Then you try with Android emulator and make ensure you system has enough memory these emulator like VM this will CPU & memory of your system accountable amount.

Appium error : A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT) [duplicate]

This question already has answers here:
A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT)
(3 answers)
Closed 7 years ago.
Code from eclipse :
public class desiredcapabilities {
#Test
public void test() throws IOException {
File appDir = new File("src");
File app = new File(appDir,"bookMyShow-ucb.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
//cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
cap.setCapability(MobileCapabilityType.APP, app.getCanonicalPath());
AndroidDriver Driver = new AndroidDriver(new URL("http://127.0.0.1:4724/wd/hub"),cap);
}
}
Appium Log :
Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4724 --session-override --platform-name Android --platform-version 23 --automation-name Appium --log-no-color
warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
info: Welcome to Appium v1.4.13 (REV c75d8adcb66a75818a542fe1891a34260c21f76a)
info: Appium REST http interface listener started on 127.0.0.1:4724
info: [debug] Non-default server args: {"address":"127.0.0.1","port":4724,"sessionOverride":true,"logNoColors":true,"platformName":"Android","platformVersion":"23","automationName":"Appium"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"C:\Users\sahil\workspace\intro\src\bookMyShow-ucb.apk","platformName":"Android","deviceName":"Android Emulator"}}
info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] No appPackage desired capability or server param. Parsing from apk.
info: [debug] Using local app from desired caps: C:\Users\sahil\workspace\intro\src\bookMyShow-ucb.apk
info: [debug] Creating new appium session 16b1787e-64bd-4bc5-b009-a0a518730ae0
error: Failed to start an Appium session, err was: Error: 'java -version' failed. Error: spawn ENOENT
info: Starting android appium
info: [debug] Getting Java version
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] Error: 'java -version' failed. Error: spawn ENOENT
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:1057:17)
at exithandler (child_process.js:633:7)
at ChildProcess.errorhandler (child_process.js:649:5)
at ChildProcess.EventEmitter.emit (events.js:95:17)
at Process.ChildProcess._handle.onexit (child_process.js:795:12)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: 'java -version' failed. Error: spawn ENOENT)","origValue":"'java -version' failed. Error: spawn ENOENT"},"sessionId":null}
info: <-- POST /wd/hub/session 500 181.826 ms - 208
Upgrade your node click here
Should work
Looks like your node version is less than the required for Appium 1.4.13.
automation-name Appium --log-no-color warn: Appium support for versions of node < 0.12
Check your node version like this:
node --version v0.12.4

Failed to start an Appium session, err was: Error: Bad app:

I want to automated Facebook app on my android device.
I have tried to init a driver like this:
private AppiumDriver driver;
#Before
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../../../data/app/ ");
File app = new File(appDir, "Facebook.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app", app.getAbsolutePath());
// capabilities.setCapability("appPackage", "com.example.android.apis");
// capabilities.setCapability("appActivity", ".ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
and I got:
info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"/Users/eladb/WorkspaceQa/myAppiumExm/../../../data/app/ /Facebook.apk","platformVersion":"4.4","browserName":"","platformName":"Android","deviceName":"Android Emulator"}}
info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
error: Failed to start an Appium session, err was: Error: Bad app: /Users/data/app/ /Facebook.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/ /Facebook.apk'
info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] No appPackage desired capability or server param. Parsing from apk.
info: [debug] Using local app from desired caps: /Users/data/app/ /Facebook.apk
info: [debug] Got configuration error, not starting session
info: [debug] Cleaning up appium session
info: [debug] Error: Bad app: /Users/data/app/ /Facebook.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/ /Facebook.apk'
at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:56:13)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/device.js:81:16
at FSReqWrap.oncomplete (fs.js:99:15)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Bad app: /Users/data/app/ /Facebook.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/ /Facebook.apk')","origValue":"Bad app: /Users/data/app/ /Facebook.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/ /Facebook.apk'"},"sessionId":null}
info: <-- POST /wd/hub/session 500 8.318 ms - 628
I have tried:
capabilities.setCapability("app", "Facebook.apk");
and I got:
error: Failed to start an Appium session, err was: Error: Bad app: null. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: You passed in an app package as the 'app' capability, but didn't include appActivity. We need to know that too in order to start your app
info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] No appPackage desired capability or server param. Parsing from apk.
info: [debug] Got configuration error, not starting session
info: [debug] Cleaning up appium session
info: [debug] Error: Bad app: null. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: You passed in an app package as the 'app' capability, but didn't include appActivity. We need to know that too in order to start your app
at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:56:13)
at androidCommon.configureApp (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:69:14)
at androidCommon.configure (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/android/android-common.js:37:10)
at Appium.configure (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:250:15)
at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:118:10)
at Appium.start (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:129:5)
at Object.exports.createSession [as handle] (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/controller.js:182:16)
at next_layer (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/route.js:113:13)
at Route.dispatch (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/route.js:117:5)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/index.js:222:24
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Bad app: null. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: You passed in an app package as the 'app' capability, but didn't include appActivity. We need to know that too in order to start your app)","origValue":"Bad app: null. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: You passed in an app package as the 'app' capability, but didn't include appActivity. We need to know that too in order to start your app"},"sessionId":null}
info: <-- POST /wd/hub/session 500 9.616 ms - 712
error: Unexpected error: Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
at ServerResponse.res.set.res.header (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/response.js:561:10)
at ServerResponse.res.send (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/response.js:133:12)
at ServerResponse.res.json (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/response.js:210:15)
at ServerResponse.res.send (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/response.js:121:21)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/helpers.js:42:9
at safely (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/helpers.js:306:5)
at Layer.module.exports.catchAllHandler [as handle] (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/server/helpers.js:41:3)
at trim_prefix (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/index.js:261:17)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/express/lib/router/index.js:225:9 context: [POST /wd/hub/session {"desiredCapabilities":{"app":"Facebook.apk","platformVersion":"4.4","browserName":"","platformName":"Android","deviceName":"Android Emulator"}}]
TypeError: Cannot set property 'onResetTimeout' of null
at Appium.configure (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:252:30)
at null.<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:118:10)
at Appium.start (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/appium.js:129:5)
how can I make it work?
Update
I have tried:
#Before
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../../../data/app/");
File app = new File(appDir, "Facebook.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app", app.getCanonicalPath());
// capabilities.setCapability("appPackage", "com.example.android.apis");
// capabilities.setCapability("appActivity", ".ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
and got:
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Bad app: /Users/data/app/Facebook.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat '/Users/data/app/Facebook.apk') (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 900 milliseconds
Build info: version: '2.43.1', revision: '5163bceef1bc36d43f3dc0b83c88998168a363a0', time: '2014-09-10 09:43:55'
System info: host: 'eladb-macbookpro.roam.corp.google.com', ip: '10.0.0.2', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.8.0_25'
I cannot verify it at the moment but my guess is that you have a blank space generating some problems here:
1. private AppiumDriver driver;
2.
3. #Before
4. public void setUp() throws Exception {
5. File classpathRoot = new File(System.getProperty("user.dir"));
6. File appDir = new File(classpathRoot, "../../../data/app/ "); // <== HERE
7. File app = new File(appDir, "Facebook.apk");
8. ...
Appium log is telling you that the generated path is:
"app":"/Users/eladb/WorkspaceQa/myAppiumExm/../../../data/app/ /Facebook.apk"
That space in line 6 at "app/ " is causing the final path to be "/Users/eladb/WorkspaceQa/myAppiumExm/../../../data/app/ /Facebook.apk". I would rewrite line 6 like this:
File appDir = new File(classpathRoot, "../../../data/app/");
Instead of "app/ ", use "...app/"
Canonical paths
I haven't been using Java for a while so I do not remember IO APIs how they work, however you should find a better way to get the absolute path to you appfile because you have a final address which using the parent folder pattern ../ to access a resource... This is not the best. The final path should be:
"app":"/Users/data/app/Facebook.apk"
Am I right? In this answer you can see that probably you should be using getCanonicalPath rather than getAbsolutePath.
If my guess is right, the following code should work:
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../../../data/app/");
File app = new File(appDir, "Facebook.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app", app.getCanonicalPath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
If you want to automate an existing app...
So looks like you might want to automate an existing app, the set of capabilities is as follows for Android:
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "<java-package-name-of-the-app>");
capabilities.setCapability("appActivity", "<android-app-activity-name>");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
Those new capabilities: appPackage and appActivity can be found in your app's property if you inspect Settings.
I did nothing but clearing up the space in mac, and it worked.!

Appium: How do you run Java tests and devices on local machine against a remote appium server

Is it possible to have Appium running on a remote machine, while having a device connected to a local machine, and also run the tests from the local machine?
Currently, Appium continues to check adb for devices where Appium is running (which of course there is none) and fails after timing out. I have zero problems running Appium locally.
Here are my Capabilities running from the Local machine where the device is connected ( IP: 192.168.1.78 ) :
#Before
public void setUp() throws Exception
{
final DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("appium-version", "1.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("deviceName", "SCH-I545");
capabilities.setCapability("appPackage", "<appPackage_goes_here>");
capabilities.setCapability("appActivity", "<appActivity_goes_here>");
driver = new AppiumDriver(new URL("http://192.168.2.109:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
And here is the Appium Console Log from the Remote machine ( IP: 192.168.2.109 ):
QA1#QA1s-Mac-mini:3.2: ~/appium :$node .
info: Welcome to Appium v1.2.0 (REV 83e64a139b928fb1f6c06e50370f9f0140ecaa30)
info: Appium REST http interface listener started on 0.0.0.0:4723
info: LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"platformVersion":"4.4","platformName":"Android","deviceName":"SCH-I545","browserName":"","appActivity":"com.alldigital.android.cox.NewsActivity","appium-version":"1.2","appPackage":"com.cmgdigital.wsoctvhandset"}}
debug: The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : appium-version
debug: Didn't get app but did get Android package, will attempt to launch it on the device
debug: Creating new appium session b184a564-321d-4753-af63-9bd7fbf56b6e
info: Starting android appium
debug: Using fast reset? true
debug: Preparing device for session
debug: Not checking whether app is present since we are assuming it's already on the device
debug: Checking whether adb is present
debug: Using adb from /Users/QA1/android-sdk-macosx/sdk/platform-tools/adb
info: Retrieving device
debug: Trying to find a connected android device
debug: Getting connected devices...
debug: executing: "/Users/QA1/android-sdk-macosx/sdk/platform-tools/adb" devices
debug: 0 device(s) connected
debug: Could not find devices, restarting adb server...
debug: executing: "/Users/QA1/android-sdk-macosx/sdk/platform-tools/adb" kill-server
debug: Getting connected devices...
debug: executing: "/Users/QA1/android-sdk-macosx/sdk/platform-tools/adb" devices
debug: 0 device(s) connected
....... continues trying .......
debug: Sent shutdown command, waiting for UiAutomator to stop...
warn: UiAutomator did not shut down fast enough, calling it gone
debug: Cleaning up android objects
debug: Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Could not find a connected Android device.
debug: Error: Could not find a connected Android device.
at ADB.getDevicesWithRetry (/Users/QA1/appium/node_modules/appium-adb/lib/adb.js:612:15)
at androidCommon.prepareActiveDevice (/Users/QA1/appium/lib/devices/android/android-common.js:354:12)
at null.<anonymous> (/Users/QA1/appium/lib/devices/android/android-common.js:294:26)
at /Users/QA1/appium/node_modules/async/lib/async.js:610:21
at /Users/QA1/appium/node_modules/async/lib/async.js:249:17
at iterate (/Users/QA1/appium/node_modules/async/lib/async.js:149:13)
at /Users/QA1/appium/node_modules/async/lib/async.js:160:25
at /Users/QA1/appium/node_modules/async/lib/async.js:251:21
at /Users/QA1/appium/node_modules/async/lib/async.js:615:34
at androidCommon.prepareEmulator (/Users/QA1/appium/lib/devices/android/android-common.js:344:5)
debug: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not find a connected Android device.)","origValue":"Could not find a connected Android device."},"sessionId":null}
info: <-- POST /wd/hub/session 500 30473.764 ms - 206
Try to use:
driver = new RemoteWebDriver(new URL("http://192.168.2.109:4723/wd/hub"), capabilities);

Categories

Resources