The "driver_quit" functionality doesn't work properly in [email protected] as well as in [email protected]

The “driver_quit” functionality doesn’t work properly in [email protected] as well as in [email protected]
Instead of killing the driver and start it from the beginning, it starts from the place it was before. This means the app under the test is not killed but just stopped and after new “start_driver” opens from the last place it was opened in the previous test. This is not reproducible in version 1.21.0

Environment

  • Appium version (or git revision) that exhibits the issue: [email protected] as well as [email protected]
  • Last Appium version that did not exhibit the issue (if applicable): 1.21.0
  • Desktop OS/version used to run Appium: Mac OS BIG SUR 11.5.2 (20G95)
  • Node.js version (unless using Appium.app|exe): v14.16.1
  • Npm or Yarn package manager: [email protected]
  • Mobile platform/version under test: iOS 14.7.1, iOS
    15 Beta
    *Real device or emulator/simulator: Real device

for example:

def setWiFiState(targetState)

  $driver = $testEnvironment.newDriverWithBundleID("com.apple.Preferences")
  $driver.start_driver
  sleep(1)
  pressElement(wiFiCell, WAIT_TIMEOUT)
  sleep(5)
  setSwitchToTargetState(targetState) {wiFiSwitch}

  $driver.driver_quit
  puts "OK - the Wi-FI switch is set to \"#{targetState}\""

end

so the next
$driver = $testEnvironment.newDriverWithBundleID(“com.apple.Preferences”)
$driver.start_driver
will be started from the WIFI Settings screen instead of the iOS Settings screen which is wrong. The driver is not killed and after performing $driver.driver_quit just stays on the WIFISettings screen
and there is no any error message for that.

you have xCode 12.5 or earlier :slight_smile:. just update to 12.5.1 and ‘quit’ will start work again.

just met this oddness few days ago.

I have a Version 12.5.1 (12E507):confused:
Hmm … but it could be because I have also Xcode beta and looks like I use it’s command line by default

Apple clang version 13.0.0 (clang-1300.0.18.6)

Target: x86_64-apple-darwin20.6.0

Thread model: posix

InstalledDir: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

xcodebuild -version

Xcode 13.0

mine data with working ‘quit’:

xcodebuild -version
Xcode 12.5.1
appium -v
1.22.0-beta.0

Same thing. I have even uninstalled everything and installed again - the same result. On appium 1.21.0 it kills the driver on 1.22.0-beta.0 it doesn’t. I also removed my Xcode Beta

Unfortunately it is impossible to suggest anything without a detailed sever log

The thing is I cannot add any logs after
“$driver.driver_quit”
because appium tells me that
" A session is either terminated or not started (Selenium::WebDriver::Error::InvalidSessionIdError)
NoSuchDriverError: A session is either terminated or not started"
So I can provide only logs before this place
“$driver.driver_quit”

It looks like that driver was stopped but not killed, and the next start just awake it and it continue from the same place it was stopped.

LOG BEFORE QUIT DRIVER APPIUM 1.21.0

LOG BEFORE QUIT DRIVER APPIUM [email protected]

this is strange. I can see QUIT command.

And I see it in your logs also BUT in middle instead of end (see ’ --> DELETE’).

Appium 1.22.0-beta.0

[15:57:37.160420] [emptyContact]   quitDriver()
2021-09-09 12:57:37:163 - [HTTP] --> DELETE /wd/hub/session/91ee0f77-d684-4f17-9739-d3cf299952de
2021-09-09 12:57:37:163 - [HTTP] {}
2021-09-09 12:57:37:163 - [debug] [W3C (91ee0f77)] Calling AppiumDriver.deleteSession() with args: ["91ee0f77-d684-4f17-9739-d3cf299952de"]
2021-09-09 12:57:37:164 - [debug] [BaseDriver] Event 'quitSessionRequested' logged at 1631192257164 (15:57:37 GMT+0300 (Eastern European Summer Time))
2021-09-09 12:57:37:164 - [Appium] Removing session 91ee0f77-d684-4f17-9739-d3cf299952de from our master session list
2021-09-09 12:57:37:165 - [debug] [WD Proxy] Matched '/session/91ee0f77-d684-4f17-9739-d3cf299952de' to command name 'deleteSession'
2021-09-09 12:57:37:165 - [debug] [WD Proxy] Proxying [DELETE /session/91ee0f77-d684-4f17-9739-d3cf299952de] to [DELETE http://127.0.0.1:6112/session/43D7B94A-EC0A-49DF-A2ED-E5FA52B99E05] with no body
2021-09-09 12:57:38:181 - [debug] [WD Proxy] Got response with status 200: {"value":null,"sessionId":null}
2021-09-09 12:57:38:181 - [DevCon Factory] Releasing connections for 00008030-001645403431402E device on any port number
2021-09-09 12:57:38:182 - [DevCon Factory] Found cached connections to release: ["00008030-001645403431402E:6112"]
2021-09-09 12:57:38:182 - [DevCon Factory] Releasing the listener for '00008030-001645403431402E:6112'
2021-09-09 12:57:38:182 - [debug] [[email protected]:6112] Closing the connection
2021-09-09 12:57:38:182 - [debug] [DevCon Factory] Cached connections count: 0
2021-09-09 12:57:38:187 - [debug] [XCUITest] Did not find the temporary XCTest logs root at '/var/folders/_r/nbsgp9v95gq0ht_43kqc1lqc0000gq/T/com.apple.dt.XCTest*/'
2021-09-09 12:57:38:188 - [XCUITest] There is no /Users/xxxxx/Library/Developer/Xcode/DerivedData/WebDriverAgent-ciegwgvxzxdrqthilmrmczmqvrgu/Logs folder, so not cleaning files
2021-09-09 12:57:38:188 - [debug] [BaseDriver] Event 'quitSessionFinished' logged at 1631192258188 (15:57:38 GMT+0300 (Eastern European Summer Time))
2021-09-09 12:57:38:188 - [debug] [W3C (91ee0f77)] Received response: null
2021-09-09 12:57:38:188 - [debug] [W3C (91ee0f77)] But deleting session, so not returning
2021-09-09 12:57:38:189 - [debug] [W3C (91ee0f77)] Responding to client with driver.deleteSession() result: null
2021-09-09 12:57:38:189 - [HTTP] <-- DELETE /wd/hub/session/91ee0f77-d684-4f17-9739-d3cf299952de 200 1026 ms - 14

It could be because I have few precondition steps where the driver starts and then quits before code from my example. But in that preconditions it is also not killing the driver, interesting that it is visible in the logs because in my example right after “$driver.driver_quit” I cannot get any logs, only error about the session.

you could try to terminate the app by calling the mobile: terminateApp API as a possible workaround

Maybe better

driver.closeApp();

?

Or it uses similar session quit?

It does. Also this API is going to be deprecated and removed from v2: https://github.com/appium/appium/issues/15807

Sorry for the late reply, I was on vacation.
So the terminate_app command works fine for me.

Thank you guys for the help.

Hi all. I have the same issue like sashok644 mentioned, it is not possible to close driver when I run automation tests from IntelliJ and also not possible to close application from Appium when close Appium inspector. It was working normally with Appium 1.21, with Appium 1.22 (XCode 13.0) does not work.
I saw that the terminate_app command helped to sashok644, but I am interested how to use it in Appium inspector to make it work. Thanks.

I had this issue as well. resolved it by adding “appium:shouldTerminateApp”: true capability

1 Like