appium / appium-flutter-driver

Appium Flutter Driver is a test automation tool for Flutter apps on multiple platforms/OSes. Appium Flutter Driver is part of the Appium mobile test automation tool maintained by community
MIT License
461 stars 184 forks source link

driver.deleteSession doesn't close the app #324

Closed DeanPack closed 2 years ago

DeanPack commented 2 years ago

I am using appiums flutter driver to automate my flutter apps testing. When my test conclues, I run driver.deleteSession() as the api says is the same as flutter.close(); Whenever I run my code though, I don't get any errors, but the app doesn't close, I simply get a 200 that says that everything is ok, but the app doesn't actually close. Here is my terminal for driver.deleteSession().

[debug] [FlutterDriver@376b (7998e2b5)] Calling AppiumDriver.deleteSession() with args: ["7998e2b5-7ff1-4a4e-ba32-0a564f4b84fd"]
[debug] [AppiumDriver@7ac3] Event 'quitSessionRequested' logged at 1661532829402 (10:53:49 GMT-0600 (Mountain Daylight Time))
[AppiumDriver@7ac3] Removing session 7998e2b5-7ff1-4a4e-ba32-0a564f4b84fd from our master session list
[debug] [FlutterDriver] Deleting Flutter Driver session
[debug] [XCUITestDriver@1df5 (8005f4fd)] Matched '/session/8005f4fd-80a8-4515-b62d-3d6947686576' to command name 'deleteSession'
[debug] [XCUITestDriver@1df5 (8005f4fd)] Proxying [DELETE /session/8005f4fd-80a8-4515-b62d-3d6947686576] to [DELETE http://127.0.0.1:8100/session/8C9842CB-1ADA-44A3-A73A-0811A174B76B] with no body
[debug] [XCUITestDriver@1df5 (8005f4fd)] Got response with status 200: {"value":null,"sessionId":null}
[DevCon Factory] Releasing connections for 14602CD8-810B-4D5E-89FF-B6BD48C0EBBA device on any port number
[DevCon Factory] Found cached connections to release: ["14602CD8-810B-4D5E-89FF-B6BD48C0EBBA:8100"]
[debug] [DevCon Factory] Cached connections count: 0
[debug] [XCUITestDriver@1df5 (8005f4fd)] Not clearing log files. Use `clearSystemFiles` capability to turn on.
[debug] [IOSSimulatorLog] Stopping iOS log capture
[debug] [AppiumDriver@7ac3] Event 'quitSessionFinished' logged at 1661532829410 (10:53:49 GMT-0600 (Mountain Daylight Time))
[debug] [AppiumDriver@7ac3] Received response: null
[debug] [AppiumDriver@7ac3] But deleting session, so not returning
[debug] [AppiumDriver@7ac3] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /session/7998e2b5-7ff1-4a4e-ba32-0a564f4b84fd 200 9 ms - 14

This is especially annoying, because since the session isn't properly deleted whenever I try to run a test again, it fails because the session isn't properly setup and initialization of the new test fails because it can't .match(session) because session is undefined.

KazuCocoa commented 2 years ago

Appium terminates the app under test via https://developer.apple.com/documentation/xctest/xcuiapplication/1500637-terminate in

[debug] [XCUITestDriver@1df5 (8005f4fd)] Matched '/session/8005f4fd-80a8-4515-b62d-3d6947686576' to command name 'deleteSession'
[debug] [XCUITestDriver@1df5 (8005f4fd)] Proxying [DELETE /session/8005f4fd-80a8-4515-b62d-3d6947686576] to [DELETE http://127.0.0.1:8100/session/8C9842CB-1ADA-44A3-A73A-0811A174B76B] with no body
[debug] [XCUITestDriver@1df5 (8005f4fd)] Got response with status 200: {"value":null,"sessionId":null}

So, perhaps XCTest framework (by Apple) did not terminate your app process properly.

You could try out https://github.com/appium/appium-xcuitest-driver#mobile-killapp to kill the app process outside XCTest

DKasianova commented 2 years ago

I have a similar error when running on the Android emulator, an example of an error message:

ERROR @wdio/local-runner: Failed launching test session: invalid session id: A session is either terminated or not started

But the session has started and the test runs fine until the await driver.deleteSession(); command is executed.

I'm using WebdriverIO + appium 2.0.0-beta.44 + appium-flutter-driver 1.7.2

KazuCocoa commented 2 years ago

It would be helpful to share the full appium server log to find possible issues. It seems like the deleteSession error is another issue. Please create a new issue.

KazuCocoa commented 2 years ago

btw, I saw similar reports in the appium repo about Apple's terminate app did not kill their app process occasionally... The original reported issue also potentially the same. Then, my previous comment's one may help