appium-flutter-driver: Unable to test app `after terminate_app` and `activate_app`
I’m trying to test launching app with deep link after it’s being terminated. But after executing driver.terminate_app
and driver.get
flutter driver is unable to find or interact with any widgets on the screen.
driver.terminate_app(‘app_id’) results in closing dart vm connection
[debug] [FlutterDriver] Executing proxied driver command 'execute'
[AndroidUiautomator2Driver@0e7e (d5ac6982)] Executing native command 'mobile: terminateApp'
[AndroidUiautomator2Driver@0e7e (d5ac6982)] Terminating 'com.app.devo'
[debug] [ADB] Getting IDs of all 'com.app.devo' processes
[debug] [ADB] Running '/Users/admin/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pgrep -f \(\[\[:blank:\]\]\|\^\)com\.apphq\.devo\(\[\[:blank:\]\]\|\$\)'
[debug] [ADB] Running '/Users/admin/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.apphq.devo'
[FlutterDriver] Connection to ws://127.0.0.1:38399/DWHjjOnA_jk=/ws closed
calling driver.get("https://deep.link.com")
opens the app, but doesn’t establish a new connection.
So I tried calling driver.activate_app('com.apphq.devo')
, as stated in documentation,
Activate the app via driver.activate_app or mobile:activateApp command Then, appium-flutter-driver establish a connection with the Dart VM
But the connection is never established.
I also tried calling driver.execute_script("flutter:connectObservatoryWsUrl")
. That returned NotImplementedError: Method is not implemented
error
Calling AppiumDriver.execute() with args: ["flutter:connectObservatoryWsUrl",[],"277be7e6-c837-432e-8cce-1e36d2d889de"]
[debug] [FlutterDriver] Executing proxied driver command 'execute'
[debug] [FlutterDriver@4ef4 (277be7e6)] Encountered internal error running command: NotImplementedError: Method is not implemented
If driver.execute_script("flutter:connectObservatoryWsUrl")
is called from a flutter context, the error would be Command not support
:
{'status': 500, 'value': '{"value":{"error":"unknown error","message":"An unknown server-side error occurred while processing the command. Original error: Command not support: \\"flutter:connectObservatoryWsUrl\\"","stacktrace":"UnknownError: An unknown server-side error occurred while processing the command. Original error: Command not support: \\"flutter:connectObservatoryWsUrl\\"\\n at getResponseForW3CError (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/errors.js:1073:9)\\n at asyncHandler (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:491:57)"}}'}
So I need a reliable way to re-establish dart vm connection after the app was terminated during a test session.
Here’s the code example
driver.switch_to.context('NATIVE_APP')
driver.terminate_app('com.apphq.devo')
driver.activate_app('com.apphq.devo')
driver.execute_script("flutter:connectObservatoryWsUrl")
driver.get("https://devo.app.com")
driver.switch_to.context('FLUTTER')
sign_in_btn_finder = finder.by_text('Sign in')
sign_in_btn = FlutterElement(driver, sign_in_btn_finder)
print("Clicking 'Sign in' button")
sign_in_btn.click()
And this is the log output:
[debug] [FlutterDriver] Executing proxied driver command 'execute'
[AndroidUiautomator2Driver@0e7e (d5ac6982)] Executing native command 'mobile: terminateApp'
[AndroidUiautomator2Driver@0e7e (d5ac6982)] Terminating 'com.apphq.devo'
[debug] [ADB] Getting IDs of all 'com.apphq.devo' processes
[debug] [ADB] Running '/Users/admin/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pgrep -f \(\[\[:blank:\]\]\|\^\)com\.apphq\.devo\(\[\[:blank:\]\]\|\$\)'
[debug] [ADB] Running '/Users/admin/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.apphq.devo'
[FlutterDriver] Connection to ws://127.0.0.1:38399/DWHjjOnA_jk=/ws closed
[AndroidUiautomator2Driver@0e7e (d5ac6982)] Querying the state of 'com.apphq.devo'
[debug] [ADB] Getting install status for com.apphq.devo
[debug] [ADB] Running '/Users/admin/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pm path com.apphq.devo'
[debug] [ADB] 'com.apphq.devo' is installed
[debug] [ADB] Getting IDs of all 'com.apphq.devo' processes
[debug] [ADB] Running '/Users/admin/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell pgrep -f \(\[\[:blank:\]\]\|\^\)com\.apphq\.devo\(\[\[:blank:\]\]\|\$\)'
[AndroidUiautomator2Driver@0e7e (d5ac6982)] 'com.apphq.devo' has been successfully terminated
[debug] [FlutterDriver@4ef4 (277be7e6)] Responding to client with driver.execute() result: true
[HTTP] <-- POST /session/277be7e6-c837-432e-8cce-1e36d2d889de/execute/sync 200 760 ms - 14
[HTTP]
[HTTP] --> POST /session/277be7e6-c837-432e-8cce-1e36d2d889de/execute/sync
[HTTP] {"script":"mobile: activateApp","args":[{"appId":"com.apphq.devo","bundleId":"com.apphq.devo"}]}
[debug] [FlutterDriver@4ef4 (277be7e6)] Calling AppiumDriver.execute() with args: ["mobile: activateApp",[{"appId":"com.apphq.devo","bundleId":"com.apphq.devo"}],"277be7e6-c837-432e-8cce-1e36d2d889de"]
[debug] [FlutterDriver] Executing proxied driver command 'execute'
[AndroidUiautomator2Driver@0e7e (d5ac6982)] Executing native command 'mobile: activateApp'
[debug] [AndroidUiautomator2Driver@0e7e (d5ac6982)] Activating 'com.apphq.devo'
[debug] [ADB] Running '/Users/admin/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell cmd package resolve-activity --brief com.apphq.devo'
[debug] [ADB] Running '/Users/admin/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start-activity -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.apphq.devo/com.apphq.MainActivity'
[debug] [AndroidUiautomator2Driver@0e7e (d5ac6982)] Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.appohq.devo/com.apphq.MainActivity }
[debug] [FlutterDriver@4ef4 (277be7e6)] Responding to client with driver.execute() result: null
[HTTP] <-- POST /session/277be7e6-c837-432e-8cce-1e36d2d889de/execute/sync 200 315 ms - 14
[HTTP]
[HTTP] --> POST /session/277be7e6-c837-432e-8cce-1e36d2d889de/execute/sync
[HTTP] {"script":"flutter:connectObservatoryWsUrl","args":[]}
[debug] [FlutterDriver@4ef4 (277be7e6)] Calling AppiumDriver.execute() with args: ["flutter:connectObservatoryWsUrl",[],"277be7e6-c837-432e-8cce-1e36d2d889de"]
[debug] [FlutterDriver] Executing proxied driver command 'execute'
[debug] [FlutterDriver@4ef4 (277be7e6)] Encountered internal error running command: NotImplementedError: Method is not implemented
[debug] [FlutterDriver@4ef4 (277be7e6)] at AndroidUiautomator2Driver.execute (/Users/admin/.appium/node_modules/appium-flutter-driver/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/commands/execute.js:13:11)
[debug] [FlutterDriver@4ef4 (277be7e6)] at commandExecutor (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/driver.ts:107:18)
[debug] [FlutterDriver@4ef4 (277be7e6)] at /opt/homebrew/lib/node_modules/appium/node_modules/async-lock/lib/index.js:171:12
[debug] [FlutterDriver@4ef4 (277be7e6)] at AsyncLock._promiseTry (/opt/homebrew/lib/node_modules/appium/node_modules/async-lock/lib/index.js:304:31)
[debug] [FlutterDriver@4ef4 (277be7e6)] at exec (/opt/homebrew/lib/node_modules/appium/node_modules/async-lock/lib/index.js:170:9)
[debug] [FlutterDriver@4ef4 (277be7e6)] at AsyncLock.acquire (/opt/homebrew/lib/node_modules/appium/node_modules/async-lock/lib/index.js:187:3)
[debug] [FlutterDriver@4ef4 (277be7e6)] at AndroidUiautomator2Driver.executeCommand (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/basedriver/driver.ts:123:39)
[debug] [FlutterDriver@4ef4 (277be7e6)] at processTicksAndRejections (node:internal/process/task_queues:95:5)
[debug] [FlutterDriver@4ef4 (277be7e6)] at FlutterDriver.executeCommand (/Users/admin/.appium/node_modules/appium-flutter-driver/lib/driver.ts:170:24)
[debug] [FlutterDriver@4ef4 (277be7e6)] at defaultBehavior (/opt/homebrew/lib/node_modules/appium/lib/appium.js:684:14)
[debug] [FlutterDriver@4ef4 (277be7e6)] at AppiumDriver.executeWrappedCommand (/opt/homebrew/lib/node_modules/appium/lib/appium.js:774:16)
[debug] [FlutterDriver@4ef4 (277be7e6)] at AppiumDriver.executeCommand (/opt/homebrew/lib/node_modules/appium/lib/appium.js:696:17)
[debug] [FlutterDriver@4ef4 (277be7e6)] at asyncHandler (/opt/homebrew/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:393:19)
[HTTP] <-- POST /session/277be7e6-c837-432e-8cce-1e36d2d889de/execute/sync 405 73 ms - 1660
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 15 (8 by maintainers)
It will be a new option, so not in current options. I’ll create a PR later