Appium scripts do not work after switch to WebView - webview

I tried to run test cases in hybrid app.
I can switch to WebView with using driver.context("WEBVIEW").
But after I switch to webview, driver.findElement() method to do not perform under webview, and it returns the error in the Appium server as below. Could you help me how to solve this?
Below are my test scripts:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","066e28s70b115a3b");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("app", "/Users/lin/codes/tester.apk");
capabilities.setCapability("app-package", "com.test.tester");
capabilities.setCapability("app-activity", "com.test.tester.myActivity");
AppiumDriver driver = new AppiumDriver(new URL("http://my.local.address:4723/wd/hub"), capabilities);
Set<String> contextNames = driver.getContextHandles();
System.out.println(contextNames.size());
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
}
}
Thread.sleep(5000);
driver.findElement(By.xpath("//div[#class='item item-entrance']/h2[#class='grey-title mb20']")).click();
The following code doesn't not work:
driver.findElement(By.xpath("//div[#class='item item-entrance']/h2[#class='grey-title mb20']")).click();
And here is the error message from Appium server log:
info: Available contexts: NATIVE_APP,WEBVIEW_1
info: Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_1"],"sessionId":"7dd9ea41-f47c-4466-a108-21ce90284ad1"}
GET /wd/hub/session/7dd9ea41-f47c-4466-a108-21ce90284ad1/contexts 200 50ms - 124b
debug: Appium request initiated at /wd/hub/session/7dd9ea41-f47c-4466-a108-21ce90284ad1/context
debug: Request received with params: {"name":"WEBVIEW_1"}
info: Getting a list of available webviews
debug: executing: "/Users/lin/tools/android-sdk-macosx/platform-tools/adb" -s 066e28s70b115a3b shell "cat /proc/net/unix"
info: ["webview_devtools_remote_20051"]
info: Available contexts: NATIVE_APP,WEBVIEW_1
info: Connecting to chrome-backed webview
info: Creating Chrome session
info: Ensuring Chromedriver exists
info: Killing any old chromedrivers, running: ps -e | grep /Users/lin/codes/appiumGit/appium/build/chromedriver/mac/chromedriver | grep -v grep |grep -e '--port=9515$' | awk '{ print $1 }' | xargs kill -15
info: Successfully cleaned up old chromedrivers
info: Spawning chromedriver with: /Users/lin/codes/appiumGit/appium/build/chromedriver/mac/chromedriver
info: [CHROMEDRIVER] Starting ChromeDriver (v2.10.267517) on port 9515
Only local connections are allowed.
info: Making http request with opts: {"url":"http://my.local.address:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.test.tester","androidUseRunningApp":true,"androidDeviceSerial":"066e28s70b115a3b"}}}}
info: Could not connect yet; retrying
info: Making http request with opts: {"url":"http://my.local.address:9515/wd/hub/session","method":"POST","json":{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage": "com.test.tester","androidUseRunningApp":true,"androidDeviceSerial":"066e28s70b115a3b"}}}}
info: Didn't get a new command in 60 secs, shutting down...
info: Shutting down appium session...
info: [ADB] Pressing the HOME button
debug: executing: "/Users/lingzhixiang/tools/android-sdk-macosx/platform-tools/adb" -s 066e28s70b115a3b shell "input keyevent 3"
info: Stopping logcat capture
debug: Logcat terminated with code null, signal SIGTERM
info: Cleaning up Chromedriver
info: Killing chromedriver
info: Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command. (Original error: socket hang up)","code":"ECONNRESET","origValue":"socket hang up"},"sessionId":"7dd9ea41-f47c-4466-a108-21ce90284ad1"}
POST /wd/hub/session/7dd9ea41-f47c-4466-a108-21ce90284ad1/context 500 60649ms - 270b
info: Chromedriver exited with code null
info: (killed by signal SIGTERM)
info: [BOOTSTRAP] [info] Got data from client: {"cmd":"shutdown"}
info: [BOOTSTRAP] [info] Got command of type SHUTDOWN
info: [BOOTSTRAP] [info] Returning result: {"value":"OK, shutting down","status":0}
info: [BOOTSTRAP] [info] Closed client connection
BTW, I started the Appium 1.0.0 server from source (>node appium.js --no-reset).

# xlzdew Please change driver.context("WEBVIEW") to driver.context("WEBVIEW_1")

Your log said it couldn't start chrome driver on your device. So pls check the chromedriver in
/Users/lin/codes/appiumGit/appium/build/chromedriver/mac/chromedriver
is working or not, or it requires execution permission. You can test it by using some chrome driver commands.

I believe that when you're in a WebView, finding elements by xpath does not work. The only method of finding an element that I have had success with is By.CSS_SELECTOR and the elements class (.menu-item).
http://appium.io/slate/en/v1.2.0/?java#automating-hybrid-android-apps

Related

NullPointerException when using AndroidDriver and calling WebDriverWait

My code below tries to wait until our native app loads. But it receives NPE:
RemoteWebDriver driver =
new AndroidDriver<MobileElement>//this gets NPE below
//new RemoteWebDriver //this works!!
(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
new WebDriverWait(driver, 30).until(
ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[contains(#text, 'Tan')]")));
When I replace AndroidDriver with RemoteDriver, everything works as expected! Our app launches and our test code waits until the app loads. The problem is, we cannot use mobile device specific API using RemoteDriver.
Appium GUI v1.4.16.1 (Ophiuchus). Please tell if any other version info is needed, as I'm not good at npm etc. But I downloaded all of the stuff last week.
Here is the stack trace:
java.lang.NullPointerException
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:152)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:636)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
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.findElement(RemoteWebDriver.java:369)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:56)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:474)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:134)
at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:361)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:52)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:41)
at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:181)
at org.openqa.selenium.support.ui.ExpectedConditions$6.apply(ExpectedConditions.java:178)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:238)
Here is what I see on Appium GUI:
> info: [debug] Appium session started with sessionId 4153c447-cfba-45db-a23a-1e603a3e0e7c
> info: <-- POST /wd/hub/session 303 17598.310 ms - 74
> info: --> GET /wd/hub/session/4153c447-cfba-45db-a23a-1e603a3e0e7c {}
> info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"C:\\Temp\\appium\\akbank-release.apk","appActivity":"com.akbank.akbankdirekt.ui.prelogin.SplashActivity","platformName":"Android","deviceName":"OJOBUCIBGEKNTKYS"},"app":"C:\\Temp\\appium\\akbank-release.apk","appActivity":"com.akbank.akbankdirekt.ui.prelogin.SplashActivity","platformName":"Android","deviceName":"OJOBUCIBGEKNTKYS"},"sessionId":"4153c447-cfba-45db-a23a-1e603a3e0e7c"}
> info: <-- GET /wd/hub/session/4153c447-cfba-45db-a23a-1e603a3e0e7c 200 4.362 ms - 667 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"4.4.2","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"app":"C:\\Temp\\appium\\akbank-release.apk","appActivity":"com.akbank.akbankdirekt.ui.prelogin.SplashActivity","platformName":"Android","deviceName":"OJOBUCIBGEKNTKYS"},"app":"C:\\Temp\\appium\\akbank-release.apk","appActivity":"com.akbank.akbankdirekt.ui.prelogin.SplashActivity","platformName":"Android","deviceName":"OJOBUCIBGEKNTKYS"},"sessionId":"4153c447-cfba-45db-a23a-1e603a3e0e7c"}
> info: --> POST /wd/hub/session/4153c447-cfba-45db-a23a-1e603a3e0e7c/element {"using":"xpath","value":"//*[contains(#text, 'Tan')]"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"xpath","selector":"//*[contains(#text, 'Tan')]","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//*[contains(#text, 'Tan')]","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding //*[contains(#text, 'Tan')] using XPATH with the contextId: multiple: false
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Could not find an element using supplied strategy. ","status":7}
> info: [debug] Condition unmet after 8397ms. Timing out.
> info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":"Could not find an element using supplied strategy. "},"sessionId":"4153c447-cfba-45db-a23a-1e603a3e0e7c"}
> info: <-- POST /wd/hub/session/4153c447-cfba-45db-a23a-1e603a3e0e7c/element 500 8402.114 ms - 230
I've put a sleep before wait and now I don't get NPE:
RemoteWebDriver driver =
new AndroidDriver<MobileElement>//this gets NPE below
//new RemoteWebDriver //this works!!
(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(15000);
new WebDriverWait(driver, 30).until(
ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[contains(#text, 'Tan')]")));
NPE was thrown as soon as the app was first loaded. I think this is an internal Appium problem.

Appium : UiAutomator quit before it successfully launched

Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color
info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
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":"23","automationName":"Appium"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.Honkampkrueger.hk","appActivity":".MainActivity","app":"C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk","browserName":"","platformName":"Android","deviceName":"Android Emulator","version":"4.4.2"}}
info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_71)
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: C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk
info: [debug] Creating new appium session f2eb01fe-7b8c-4e7c-89c6-5d776471a569
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.8.0_71
info: [debug] Checking whether adb is present
info: [debug] Using adb from C:\Program Files\SDK\platform-tools\adb.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:\Program Files\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:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 wait-for-device
info: [debug] executing cmd: "C:\Program Files\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:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 19
info: Device API level is: 19
info: [debug] Extracting strings for language: default
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "getprop persist.sys.language"
info: [debug] Current device persist.sys.language: en
info: [debug] java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk" "C:\Users\KULDEE~1.SAH\AppData\Local\Temp\com.Honkampkrueger.hk" en
info: [debug] No strings.xml for language 'en', getting default strings.xml
info: [debug] java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk" "C:\Users\KULDEE~1.SAH\AppData\Local\Temp\com.Honkampkrueger.hk"
info: [debug] Reading strings from converted strings.json
info: [debug] Setting language to default
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 push "C:\Users\KULDEE~1.SAH\AppData\Local\Temp\com.Honkampkrueger.hk\strings.json" /data/local/tmp
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Program Files\SDK\build-tools\23.0.2\aapt.exe
info: [debug] Retrieving process from manifest.
info: [debug] executing cmd: "C:\Program Files\SDK\build-tools\23.0.2\aapt.exe" dump xmltree C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk AndroidManifest.xml
info: [debug] Set app process to: com.Honkampkrueger.hk
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Checking app cert for C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk.
info: [debug] executing cmd: java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\verify.jar" C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk
info: [debug] App already signed.
info: [debug] Zip-aligning C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk
info: [debug] Checking whether zipalign is present
info: [debug] Using zipalign from C:\Program Files\SDK\build-tools\23.0.2\zipalign.exe
info: [debug] Zip-aligning apk.
info: [debug] executing cmd: "C:\Program Files\SDK\build-tools\23.0.2\zipalign.exe" -f 4 C:\Users\kuldeep.sahu\workspace\AppiumIntro\Src\honkamp.apk C:\Users\KULDEE~1.SAH\AppData\Local\Temp\11615-3480-14zot2k\appium.tmp
info: [debug] MD5 for app is 91f72bc7e64a758cdb9d0b8414bd853c
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "ls /data/local/tmp/91f72bc7e64a758cdb9d0b8414bd853c.apk"
info: [debug] Getting install status for com.Honkampkrueger.hk
info: [debug] Getting device API level
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 19
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "pm list packages -3 com.Honkampkrueger.hk"
info: [debug] App is not installed
info: Installing App
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "mkdir -p /data/local/tmp/"
info: [debug] Removing any old apks
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "ls /data/local/tmp/*.apk"
info: [debug] Found an apk we want to keep at /data/local/tmp/91f72bc7e64a758cdb9d0b8414bd853c.apk
info: [debug] Couldn't find any apks to remove
info: [debug] Uninstalling com.Honkampkrueger.hk
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "am force-stop com.Honkampkrueger.hk"
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 uninstall com.Honkampkrueger.hk
info: [debug] App was not uninstalled, maybe it wasn't on device?
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "pm install -r /data/local/tmp/91f72bc7e64a758cdb9d0b8414bd853c.apk"
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: "C:\Program Files\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:\Program Files\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:\Program Files\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] Pushing unlock helper app to device...
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: C:\Program Files\SDK\platform-tools\adb.exe -s emulator-5554 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.Honkampkrueger.hk -e disableAndroidWatchers false
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_RESULT: shortMsg=java.lang.NullPointerException
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_RESULT: longMsg=null
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_CODE: 0
info: [debug] UiAutomator exited
info: [debug] executing cmd: "C:\Program Files\SDK\platform-tools\adb.exe" -s emulator-5554 shell "echo 'ping'"
info: [debug] Attempting to uninstall app
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: UiAutomator quit before it successfully launched
error: Failed to start an Appium session, err was: Error: UiAutomator quit before it successfully launched
info: [debug] Error: UiAutomator quit before it successfully launched
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js:205:23)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-hybrid.js:249:5)
at Object.async.eachSeries (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:142:20)
at [object Object].androidHybrid.stopChromedriverProxies (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-hybrid.js:233:9)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js:200:10)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js:222:9)
at [object Object].androidCommon.uninstallApp (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:478:5)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js:220:12)
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js:229:11)
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:901:7
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:180:9)
at ChildProcess.exithandler (child_process.js:742:7)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js: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: UiAutomator quit before it successfully launched)","origValue":"UiAutomator quit before it successfully launched"},"sessionId":null}
info: <-- POST /wd/hub/session 500 46111.400 ms - 218
Error : Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: UiAutomator quit before it successfully launched) (WARNING: The server did not provide any stacktrace information).
Anyone have solution of this as My running emulator is very slow to launch.
UiAutomator quit before it successfully launched error: Failed to
start an Appium session, err was: Error: UiAutomator quit before it
successfully launched info: [debug] Error: UiAutomator quit before it
successfully launched at [object Object]. (C:\Program Files
(x86)\Appium\node_modules\appium\lib\devices\android\android.js:205:23)
at [object Object].
These suggests that UIAutomator did not launch due to which Appium session was not created. [SessionNotCreatedException on your IDE]
Restarting adb server and appium serve shall help you.
Prior to that you can also try running the UIAutomator using shell to verify if its working alright on your machine.
In case you using Appium 1.4 + version to automate android (7.0 / N / Nougat ) version, this issue persists. you have to make couple of changes to get this working properly.
We had a similar issue, when we started to automate a simple mobile application using appium, android studio and selenium webdriver, after so many searches and also looking at various appium support tickets, we found that it was a bug and they have given an alternative to fix and go ahead.
You have to change code in couple of places in following file:
C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js
Those details have been listed in below article:
http://www.testingtools.co/appium/error-command-failed-adb-exe-s-emulator-5554-shell-ps-uiautomator
Hope it helps you, in case you have any queries, you can post them over the blog article in form of comments as well.
You cannot run UIAutomator and Appium server in parallel, this is known issue. Make sure your Appium server is stopped before you run your UIAutomator then try again. This should work.

error: cannot bind to socket: Address already in use

I run appium script parallel on 39 emulators, some times appium throw exception while creating the appium session for few emulator(3 or 4 out of 39 emulator). please find the following error for more details.
I'm using Appium 1.4.14 and Ubuntu 14.04 LTS.
**Error details:**
2015-11-27 17:29:21:492 - info: [debug] Using fast reset? true
2015-11-27 17:29:21:492 - info: [debug] Preparing device for session
2015-11-27 17:29:21:493 - info: [debug] Not checking whether app is present since we are assuming it's already on the device
2015-11-27 17:29:21:494 - info: Retrieving device
2015-11-27 17:29:21:495 - info: [debug] Trying to find a connected android device
2015-11-27 17:29:21:496 - info: [debug] Getting connected devices...
2015-11-27 17:29:21:501 - info: [debug] executing cmd: /home/user/Android/Sdk/platform-tools/adb devices
2015-11-27 17:29:21:530 - info: [debug] 39 device(s) connected
2015-11-27 17:29:21:531 - info: Found device emulator-5590
2015-11-27 17:29:21:531 - info: [debug] Setting device id to emulator-5590
2015-11-27 17:29:21:532 - info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
2015-11-27 17:29:21:533 - info: [debug] executing cmd: /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 wait-for-device
2015-11-27 17:29:21:555 - info: [debug] executing cmd: /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 shell "echo 'ready'"
2015-11-27 17:29:21:620 - info: [debug] Starting logcat capture
2015-11-27 17:29:21:712 - info: [debug] Getting device API level
2015-11-27 17:29:21:713 - info: [debug] executing cmd: /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 shell "getprop ro.build.version.sdk"
2015-11-27 17:29:21:833 - info: [debug] Device is at API Level 19
2015-11-27 17:29:21:834 - info: Device API level is: 19
2015-11-27 17:29:21:835 - info: [debug] Extracting strings for language: default
2015-11-27 17:29:21:836 - info: [debug] Apk doesn't exist locally
2015-11-27 17:29:21:836 - info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
2015-11-27 17:29:21:837 - info: [debug] executing cmd: /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 shell "rm -rf /data/local/tmp/strings.json"
2015-11-27 17:29:22:135 - info: [debug] Not uninstalling app since server not started with --full-reset
2015-11-27 17:29:22:137 - info: [debug] Skipping install since we launched with a package instead of an app path
2015-11-27 17:29:22:138 - info: [debug] Forwarding system:37036 to device:4724
2015-11-27 17:29:22:140 - info: [debug] executing cmd: /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 forward tcp:37036 tcp:4724
2015-11-27 17:29:22:164 - info: [debug] Stopping logcat capture
2015-11-27 17:29:22:167 - info: [debug] Logcat terminated with code null, signal SIGTERM
2015-11-27 17:29:22:168 - info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
2015-11-27 17:29:29:173 - warn: UiAutomator did not shut down fast enough, calling it gone
2015-11-27 17:29:29:174 - info: [debug] Cleaning up android objects
2015-11-27 17:29:29:177 - info: [debug] Cleaning up appium session
2015-11-27 17:29:29:180 - error: Failed to start an Appium session, err was: Error: Command failed: /bin/sh -c /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 forward tcp:37036 tcp:4724
error: cannot bind to socket: Address already in use
error: cannot bind to socket: Address already in use
2015-11-27 17:29:29:193 - info: [debug] Error: Command failed: /bin/sh -c /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 forward tcp:37036 tcp:4724
error: cannot bind to socket: Address already in use
error: cannot bind to socket: Address already in use
at ChildProcess.exithandler (child_process.js:203:12)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:818:16)
at Socket.<anonymous> (internal/child_process.js:319:11)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Pipe._onclose (net.js:469:12)
2015-11-27 17:29:29:195 - info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Command failed: /bin/sh -c /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 forward tcp:37036 tcp:4724\nerror: cannot bind to socket: Address already in use\nerror: cannot bind to socket: Address already in use\n)","killed":false,"code":1,"signal":null,"cmd":"/bin/sh -c /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 forward tcp:37036 tcp:4724","origValue":"Command failed: /bin/sh -c /home/user/Android/Sdk/platform-tools/adb -s emulator-5590 forward tcp:37036 tcp:4724\nerror: cannot bind to socket: Address already in use\nerror: cannot bind to socket: Address already in use\n"},"sessionId":null}
2015-11-27 17:29:29:203 - info: <-- POST /wd/hub/session 500 7944.285 ms - 709
please help me fix this issue..
Thank you in advance for your support,
Tirupathi Rao

Instruments crashed at start up

I am running appium server 1.2 at MAC OS 10.8.X and appis installed on real iOs device Iphone 5.
When I try to run the test script, it gives me the following error.
info: [debug] App is installed.
info: [debug] fullReset not requested. No need to install.
info: [debug] Starting command proxy.
info: [debug] Instruments socket server started at /tmp/instruments_sock
info: [debug] Starting instruments
info: [debug] Instruments is at: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments
info: Launching instruments
info: [debug] Attempting to run app on real device with UDID 1d30758b4d21c267fb261c47d52b1e393357367e
info: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w 1d30758b4d21c267fb261c47d52b1e393357367e com.equinix.ecpnewappdistribution -e UIASCRIPT "/Users/anujtomar/Library/Application Support/appium/bootstrap/bootstrap-0943baae6b1d6f5b.js" -e UIARESULTSPATH /tmp/appium-instruments
info: [debug] And extra without-delay env: {}
info: [debug] And launch timeouts (in ms): {"global":90000}
info: [debug] [INST STDERR] 2014-12-10 15:18:14.827 instruments[6611:707] Failed to start Instruments daemon for 'iOS' on 'Equinix's iPhone (v8.0.2)' (The service is invalid.)
info: [debug] [INST STDERR] 2014-12-10 15:18:14.954 instruments[6611:2203] Failed to start Instruments daemon for 'iOS' on 'Equinix's iPhone (v8.0.2)' (The service is invalid.)
info: [debug] [INSTSERVER] Instruments exited with code 253
info: [debug] Killall instruments
How can I fix this?
The problem seems to be with device. Try below steps:
Open Xcode
Goto Window
Organizer
Under you device name goto Console.
Clear the the console.
And then run test cases again.
Hope that helps !!!
I also faced a similar problem and none of the above techniques worked.
However I was able to run appium by doing the following changes in the setting
choose xcode instruments
choose automation
Look for options and select allow device for automation
A window comes up asking for permission. Select 'okay' and you should be able to run appium now

Appium Chrome driver port 9515

I am able to execute the script for the first with appium, selenium and C# on android device. But whenever I try to run the script next time I am getting below error.
info: [CHROMEDRIVER STDERR] [0.028][SEVERE]: Could not bind socket to 0.0.0.0:9515
info: [CHROMEDRIVER] Port not available. Exiting...
info: Chromedriver exited with code 1
ERROR: debug: executing: "c:\android-sdk\platform-tools\adb.exe" -s 4d00b33d4ae241bf devices
info: [ADB] Getting connected devices...
info: [ADB] 1 device(s) connected
ERROR: debug: executing: "c:\android-sdk\platform-tools\adb.exe" -s 4d00b33d4ae241bf shell "am force-stop com.android.chrome"
ERROR: error: Chromedriver create session did not work. Status was 200 and body was {"sessionId":"79cdf9fec37fb4700e10ce34566a7e11","status":13,"value":{"message":"unknown error: Device 4d00b33d4ae241bf is already in use\n (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)"}}
ERROR: error: Failed to start an Appium session, err was: Error: Did not get session redirect from Chromedriver
But if I change the Chrome driver port from 9515 to something else the script is getting executed. Then againw henever I want to execute the script, I have to change the Chrome driver port to something new from the existing one. My OS is windows 7. Need help in this matter.
I think you are not closing the driver instance after the script run so the acquired port is not free for next run.
Possible Solutions:
Findout the process of Chromedriver and stop it
Restart Appium server
Try with driver.quit() or equivalent at the end point of your script

Resources