Switching from NATIV_APP to WEBVIEW App gets automatically stop

I am trying to automate a payment gateway page of a app. Here I have to switch from NATIVE perspective to WEBVIEW. Following is the code sample :
Set contextNames=driver.getContextHandles();
for(String contextName: contextNames)
{
try{
System.out.println(contextName);
if(contextName.contains(“WEBVIEW”))
{
System.out.println(“Changing context now”);
driver.context(contextName);
Thread.sleep(20000);
}
}
catch(Exception e)
{
System.out.println(“WebView error”);
e.printStackTrace();
}
}
System.out.println(“for ends here”);
System.out.println(driver.findElements(By.tagName(“input”)).size());

driver is initialize as follows:
driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),capabilities);

The problem is that when I am trying to switch context, log shows that, it didnt get a new command in 60 sec and it just stop the app.

Please let me know if anyone has solution
Thanks in advance!!

Following is the log

info: → POST /wd/hub/session/92b9f8a8-a177-4909-89e0-f1fad119640e/element/50/click {“id”:“50”}
info: [debug] Pushing command to appium work queue: [“element:click”,{“elementId”:“50”}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“element:click”,“params”:{“elementId”:“50”}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Returning result: {“value”:true,“status”:0}
info: [debug] Responding to client with success: {“status”:0,“value”:true,“sessionId”:“92b9f8a8-a177-4909-89e0-f1fad119640e”}
info: ← POST /wd/hub/session/92b9f8a8-a177-4909-89e0-f1fad119640e/element/50/click 200 3027.610 ms - 76 {“status”:0,“value”:true,“sessionId”:“92b9f8a8-a177-4909-89e0-f1fad119640e”}
info: → POST /wd/hub/session/92b9f8a8-a177-4909-89e0-f1fad119640e/elements {“using”:“id”,“value”:“web_view”}
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: [“find”,{“strategy”:“id”,“selector”:“web_view”,“context”:“”,“multiple”:true}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“id”,“selector”:“web_view”,“context”:“”,“multiple”:true}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: find
info: [debug] [BOOTSTRAP] [debug] Finding web_view using ID with the contextId: multiple: true
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=com.bt.bms:id/web_view]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=com.bt.bms:id/web_view]
info: [debug] [BOOTSTRAP] [debug] Element is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.bt.bms:id/web_view]
info: [debug] [BOOTSTRAP] [debug] Element is null: (1)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=1, RESOURCE_ID=com.bt.bms:id/web_view]
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[RESOURCE_ID=android:id/web_view]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[RESOURCE_ID=android:id/web_view]
info: [debug] [BOOTSTRAP] [debug] Element is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=android:id/web_view]
info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[DESCRIPTION=web_view]
info: [debug] [BOOTSTRAP] [debug] getElements selector:UiSelector[DESCRIPTION=web_view]
info: [debug] [BOOTSTRAP] [debug] Element is null: (0)
info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[DESCRIPTION=web_view, INSTANCE=0]
info: [debug] [BOOTSTRAP] [debug] Returning result: {“value”:[{“ELEMENT”:“55”}],“status”:0}
info: [debug] Responding to client with success: {“status”:0,“value”:[{“ELEMENT”:“55”}],“sessionId”:“92b9f8a8-a177-4909-89e0-f1fad119640e”}
info: ← POST /wd/hub/session/92b9f8a8-a177-4909-89e0-f1fad119640e/elements 200 597.217 ms - 90 {“status”:0,“value”:[{“ELEMENT”:“55”}],“sessionId”:“92b9f8a8-a177-4909-89e0-f1fad119640e”}
info: → GET /wd/hub/session/92b9f8a8-a177-4909-89e0-f1fad119640e/contexts {}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: E:\Android\Sdk\platform-tools\adb.exe -s E8AZCY09K150 shell “cat /proc/net/unix”
info: [debug] WEBVIEW_25235 mapped to pid 25235
info: [debug] Getting process name for webview
info: [debug] executing cmd: E:\Android\Sdk\platform-tools\adb.exe -s E8AZCY09K150 shell “ps”
info: [debug] WEBVIEW_12748 mapped to pid 12748
info: [debug] Getting process name for webview
info: [debug] executing cmd: E:\Android\Sdk\platform-tools\adb.exe -s E8AZCY09K150 shell “ps”
info: [debug] Parsed pid: 12748 pkg: com.google.android.apps.magazines
info: [debug] from: u0_a81,12748,152,595848,33900,ffffffff,00000000,S,com.google.android.apps.magazines
info: [debug] returning process name: com.google.android.apps.magazines
info: [debug] Parsed pid: 25235 pkg: com.google.android.apps.magazines
info: [debug] from: u0_a81,25235,152,594896,37016,ffffffff,00000000,S,com.google.android.apps.magazines
info: [debug] returning process name: com.google.android.apps.magazines
info: [debug] Available contexts:
info: [debug] [“WEBVIEW_com.google.android.apps.magazines”,“WEBVIEW_com.google.android.apps.magazines”]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.google.android.apps.magazines
info: [debug] Responding to client with success: {“status”:0,“value”:[“NATIVE_APP”,“WEBVIEW_com.google.android.apps.magazines”],“sessionId”:“92b9f8a8-a177-4909-89e0-f1fad119640e”}
info: ← GET /wd/hub/session/92b9f8a8-a177-4909-89e0-f1fad119640e/contexts 200 248.729 ms - 130 {“status”:0,“value”:[“NATIVE_APP”,“WEBVIEW_com.google.android.apps.magazines”],“sessionId”:“92b9f8a8-a177-4909-89e0-f1fad119640e”}
info: → POST /wd/hub/session/92b9f8a8-a177-4909-89e0-f1fad119640e/context {“name”:“WEBVIEW_com.google.android.apps.magazines”}
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: E:\Android\Sdk\platform-tools\adb.exe -s E8AZCY09K150 shell “cat /proc/net/unix”
info: [debug] WEBVIEW_25235 mapped to pid 25235
info: [debug] Getting process name for webview
info: [debug] executing cmd: E:\Android\Sdk\platform-tools\adb.exe -s E8AZCY09K150 shell “ps”
info: [debug] WEBVIEW_12748 mapped to pid 12748
info: [debug] Getting process name for webview
info: [debug] executing cmd: E:\Android\Sdk\platform-tools\adb.exe -s E8AZCY09K150 shell “ps”
info: [debug] Parsed pid: 25235 pkg: com.google.android.apps.magazines
info: [debug] from: u0_a81,25235,152,594896,37016,ffffffff,00000000,S,com.google.android.apps.magazines
info: [debug] returning process name: com.google.android.apps.magazines
info: [debug] Parsed pid: 12748 pkg: com.google.android.apps.magazines
info: [debug] from: u0_a81,12748,152,595848,33900,ffffffff,00000000,S,com.google.android.apps.magazines
info: [debug] returning process name: com.google.android.apps.magazines
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.google.android.apps.magazines
info: [debug] [“WEBVIEW_com.google.android.apps.magazines”,“WEBVIEW_com.google.android.apps.magazines”]
info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.google.android.apps.magazines
info: [debug] Connecting to chrome-backed webview
info: Set chromedriver binary as: E:\Appium\AppiumInstallation\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: Killing any old chromedrivers, running: FOR /F “usebackq tokens=5” %a in (netstat -nao ^| findstr /R /C:"9515 ") do (FOR /F “usebackq” %b in (TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe) do (IF NOT %b==“” TASKKILL /F /PID %a))
info: No old chromedrivers seemed to exist
info: Spawning chromedriver with: E:\Appium\AppiumInstallation\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe --url-base=wd/hub --port=9515
info: [CHROMEDRIVER STDOUT] Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515
Only local connections are allowed.
info: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
info: Got response with status 200: {“sessionId”:“”,“status”:0,“value”:{“build”:{“version”:“alpha”},“os”:{“arch”:“x86_64”,“name”:“Windows NT”,“version”:“6.1 SP1”}}}
info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {“desiredCapabilities”:{“chromeOptions”:{“androidPackage”:“com.bt.bms”,“androidUseRunningApp”:true,“androidDeviceSerial”:“E8AZCY09K150”}}}
info: [debug] Didn’t get a new command in 60 secs, shutting down…
info: Shutting down appium session
info: [debug] Pressing the HOME button
info: [debug] executing cmd: E:\Android\Sdk\platform-tools\adb.exe -s E8AZCY09K150 shell “input keyevent 3”
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] [BOOTSTRAP] [debug] Got data from client: {“cmd”:“shutdown”}
info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
info: [debug] [BOOTSTRAP] [debug] Returning result: {“value”:“OK, shutting down”,“status”:0}
info: [debug] Sent shutdown command, waiting for UiAutomator to stop…
info: [debug] [BOOTSTRAP] [debug] Closed client connection
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
info: [debug] [UIAUTOMATOR STDOUT] Time: 172.397
info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
info: [debug] UiAutomator shut down normally
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] We shut down because no new commands came in
info: Got response with status 200: {“sessionId”:“6f5dd3365b11000ac9c611eb5abcff05”,“status”:100,“value”:{“message”:"chrome not reachable\n (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Wind…
info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {“desiredCapabilities”:{“chromeOptions”:{“androidPackage”:“com.bt.bms”,“androidUseRunningApp”:true,“androidDeviceSerial”:“E8AZCY09K150”}}}

Hi @susmitb

Did you find solution to the problem. I am facing the same issue. Could you please post the solution.

Thanks,
Sravya

MobileCapabilityType.NEW_COMMAND_TIMEOUT capability has to be set to increase the time.
eg DeviceCaps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,120);