How to test an already running android activity

i want to test an already running android activity, but if i set autoLaunch to ‘false’, the test code is no response

code:

#coding=utf-8
from appium import webdriver

desired_caps = {}
desired_caps[‘platformName’] = ‘Android’
desired_caps[‘platformVersion’] = ‘6.0’
desired_caps[‘deviceName’] = ‘33008b74614b520f’
desired_caps[‘appPackage’] = ‘com.example.a305029270.helloworld’
desired_caps[‘appActivity’] = ‘com.example.a305029270.helloworld.HelloWorldActivity’
desired_caps[‘autoLaunch’] = ‘true’

driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)

driver.find_element_by_name(“test button 1”).click()

driver.find_element_by_name(“test button 1”).click()

driver.quit()

log:

Checking if an update is available
Update not available
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”:{“deviceName”:“33008b74614b520f”,“autoLaunch”:“false”,“platformVersion”:“6.0”,“appPackage”:“com.example.a305029270.helloworld”,“platformName”:“Android”,“appActivity”:“com.example.a305029270.helloworld.HelloWorldActivity”}}
info: Client User-Agent string: Python-urllib/2.7
warn: Converting cap autoLaunch from string to boolean. This might cause unexpected behavior.
info: [debug] Didn’t get app but did get Android package, will attempt to launch it on the device
info: [debug] Creating new appium session 03160b98-6777-435f-bc8e-a1897e1c7193
info: [debug] Setting up Android for ‘autoLaunch: false’
info: [debug] Getting Java version
info: Java version is: 1.8.0_91
info: [debug] Checking whether adb is present
info: [debug] Using adb from C:\Users\305029270\AppData\Local\Android\sdk\platform-tools\adb.exe
info: [debug] Appium session started with sessionId 03160b98-6777-435f-bc8e-a1897e1c7193
info: ← POST /wd/hub/session 303 192.004 ms - 74
info: → GET /wd/hub/session/03160b98-6777-435f-bc8e-a1897e1c7193 {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“platform”:“LINUX”,“browserName”:“Android”,“platformVersion”:“6.0”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“deviceName”:“33008b74614b520f”,“autoLaunch”:false,“platformVersion”:“6.0”,“appPackage”:“com.example.a305029270.helloworld”,“platformName”:“Android”,“appActivity”:“com.example.a305029270.helloworld.HelloWorldActivity”},“deviceName”:“33008b74614b520f”,“autoLaunch”:false,“appPackage”:“com.example.a305029270.helloworld”,“platformName”:“Android”,“appActivity”:“com.example.a305029270.helloworld.HelloWorldActivity”},“sessionId”:“03160b98-6777-435f-bc8e-a1897e1c7193”}
info: ← GET /wd/hub/session/03160b98-6777-435f-bc8e-a1897e1c7193 200 6.455 ms - 739 {“status”:0,“value”:{“platform”:“LINUX”,“browserName”:“Android”,“platformVersion”:“6.0”,“webStorageEnabled”:false,“takesScreenshot”:true,“javascriptEnabled”:true,“databaseEnabled”:false,“networkConnectionEnabled”:true,“locationContextEnabled”:false,“warnings”:{},“desired”:{“deviceName”:“33008b74614b520f”,“autoLaunch”:false,“platformVersion”:“6.0”,“appPackage”:“com.example.a305029270.helloworld”,“platformName”:“Android”,“appActivity”:“com.example.a305029270.helloworld.HelloWorldActivity”},“deviceName”:“33008b74614b520f”,“autoLaunch”:false,“appPackage”:“com.example.a305029270.helloworld”,“platformName”:“Android”,“appActivity”:“com.example.a305029270.helloworld.HelloWorldActivity”},“sessionId”:“03160b98-6777-435f-bc8e-a1897e1c7193”}
info: → POST /wd/hub/session/03160b98-6777-435f-bc8e-a1897e1c7193/element {“using”:“name”,“sessionId”:“03160b98-6777-435f-bc8e-a1897e1c7193”,“value”:“test button 1”}
warn: [DEPRECATED] The name locator strategy has been deprecated and will be removed. Please use the accessibility id locator strategy instead.
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: [“find”,{“strategy”:“name”,“selector”:“test button 1”,“context”:“”,“multiple”:false}]
error: Unhandled error: TypeError: Cannot read property ‘sendAction’ of null
at [object Object]. (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android.js:504:23)
at Immediate.q.process [as _onImmediate] (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:806:21)
at processImmediate [as _immediateCallback] (timers.js:367:17) context: [POST /wd/hub/session/03160b98-6777-435f-bc8e-a1897e1c7193/element {“using”:“name”,“sessionId”:“03160b98-6777-435f-bc8e-a1897e1c7193”,“value”:“test button 1”}]
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: C:\Users\305029270\AppData\Local\Android\sdk\platform-tools\adb.exe shell “input keyevent 3”
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
info: [debug] We shut down because no new commands came in

When you set autoLaunch is false, make sure you launch the app by calling:

driver.launchApp()

thank you for your help, driver.launch_app() is also closing the App first, i want to attach the already running App.

I try to achieve the same thing. Is this supported?