InvalidElementStateError [XCUITest]

My app is crashing, when launching it doesn’t pass the flash screen, both on Appium Desktop and when running it with code on my iOS but on a different laptop which I use for Android it’s working.It was working before.

The server is waiting for all connections to close
[simctl] Error running ‘uninstall’: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
Unable to lookup in current state: Shutdown
[WebDriverAgent] Error: Error running ‘uninstall’: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
[WebDriverAgent] Unable to lookup in current state: Shutdown
[WebDriverAgent] at Simctl.exec (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/node_modules/appium-ios-simulator/node_modules/node-simctl/lib/simctl.js:139:15)
[WebDriverAgent] WebDriverAgent uninstall failed. Perhaps, it is already uninstalled? Original error: Error running ‘uninstall’: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
[WebDriverAgent] Unable to lookup in current state: Shutdown
[XCUITest] {}
[DevCon Factory] Releasing connections for ECEF671A-F3F4-4838-894E-BE9CBACE9C6F device on any port number
[DevCon Factory] Found cached connections to release: [“ECEF671A-F3F4-4838-894E-BE9CBACE9C6F:8100”]
[DevCon Factory] Cached connections count: 0
[XCUITest] Not clearing log files. Use clearSystemFiles capability to turn on.
[BaseDriver] Event ‘newSessionStarted’ logged at 1611042949315 (09:55:49 GMT+0200 (South Africa Standard Time))
[MJSONWP] Encountered internal error running command: Error: Unable to start WebDriverAgent session because of xcodebuild failure: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: connect ECONNREFUSED 127.0.0.1:8100
[MJSONWP] at quitAndUninstall (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:532:15)
[MJSONWP] at /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:593:11
[MJSONWP] at wrapped (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:35:13)
[MJSONWP] at retry (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:18:13)
[MJSONWP] at retryInterval (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/asyncbox/lib/asyncbox.js:45:10)
[MJSONWP] at /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:542:7
[MJSONWP] Destroying socket connection
[HTTP] <-- POST /wd/hub/session 500 430585 ms - 388
[HTTP]
[Appium] Welcome to Appium v1.18.3
[Appium] Non-default server args:
[Appium] address: 127.0.0.1
[Appium] relaxedSecurityEnabled: true
[Appium] allowInsecure: {
[Appium] }
[Appium] denyInsecure: {
[Appium] }
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
[HTTP] --> GET /wd/hub/sessions
[HTTP] {}
[GENERIC] Calling AppiumDriver.getSessions() with args: []
[GENERIC] Responding to client with driver.getSessions() result: []
[HTTP] <-- GET /wd/hub/sessions 200 2 ms - 40
[HTTP]
[HTTP] --> POST /wd/hub/session
[HTTP] {“desiredCapabilities”:{“PLATFORM_VERSION”:14,“app”:“com.xxx.testing”,“automationName”:“XCUITest”,“deviceName”:“iPhone 12 Pro Max”,“platformName”:“iOS”,“platformVersion”:“14.1”,“showIOSLog”:false,“showXcodeLog”:false,“waitForQuiescence”:true,“wdaEventloopIdleDelay”:5,“newCommandTimeout”:0,“connectHardwareKeyboard”:true}}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{“PLATFORM_VERSION”:14,“app”:“com.xxx.app.testing”,“automationName”:“XCUITest”,“deviceName”:“iPhone 12 Pro Max”,“platformName”:“iOS”,“platformVersion”:“14.1”,“showIOSLog”:false,“showXcodeLog”:false,“waitForQuiescence”:true,“wdaEventloopIdleDelay”:5,“newCommandTimeout”:0,“connectHardwareKeyboard”:true},null,null]
[BaseDriver] Event ‘newSessionRequested’ logged at 1611043116494 (09:58:36 GMT+0200 (South Africa Standard Time))
[Appium] Appium v1.18.3 creating new XCUITestDriver (v3.29.0) session
[Appium] Applying relaxed security to ‘XCUITestDriver’ as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
[BaseDriver] Creating session with MJSONWP desired capabilities: {
[BaseDriver] “PLATFORM_VERSION”: 14,
[BaseDriver] “app”: “com.xxx.app.testing”,
[BaseDriver] “automationName”: “XCUITest”,
[BaseDriver] “deviceName”: “iPhone 12 Pro Max”,
[BaseDriver] “platformName”: “iOS”,
[BaseDriver] “platformVersion”: “14.1”,
[BaseDriver] “showIOSLog”: false,
[BaseDriver] “showXcodeLog”: false,
[BaseDriver] “waitForQuiescence”: true,
[BaseDriver] “wdaEventloopIdleDelay”: 5,
[BaseDriver] “newCommandTimeout”: 0,
[BaseDriver] “connectHardwareKeyboard”: true
[BaseDriver] }
[BaseDriver] The following capabilities were provided, but are not recognized by Appium:
[BaseDriver] PLATFORM_VERSION
[BaseDriver] Session created with session id: e9d44cfd-7aba-49c1-8149-aea9d8ae69d0
[XCUITest] Current user: ‘dany’
[XCUITest] iOS SDK Version set to ‘14.1’
[iOSSim] Constructing iOS simulator for Xcode version 12.1 with udid ‘ECEF671A-F3F4-4838-894E-BE9CBACE9C6F’
[XCUITest] Determining device to run tests on: udid: ‘ECEF671A-F3F4-4838-894E-BE9CBACE9C6F’, real device: false
[BaseDriver] Event ‘xcodeDetailsRetrieved’ logged at 1611043116875 (09:58:36 GMT+0200 (South Africa Standard Time))
[XCUITest] App is an iOS bundle, will attempt to run as pre-existing
[BaseDriver] Event ‘appConfigured’ logged at 1611043116875 (09:58:36 GMT+0200 (South Africa Standard Time))
[BaseDriver] Event ‘resetStarted’ logged at 1611043116875 (09:58:36 GMT+0200 (South Africa Standard Time))
[simctl] Error running ‘terminate’: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
Unable to lookup in current state: Shutdown
[iOSSim] Cleaning app data files for ‘’, ‘com.xxx.app.testing’
[iOSSim] Checking whether simulator has been run before: yes
[iOSSim] Building bundle path map
[Support] Plist file ‘/Users/dany/Library/Developer/CoreSimulator/Devices/ECEF671A-F3F4-4838-894E-BE9CBACE9C6F/data/Containers/Data/Application/504F9F02-A09C-4784-9406-E6F0B682CEA0/.com.apple.mobile_container_manager.metadata.plist’ does not exist. Returning an empty plist.
[iOSSim] Could not find app directories to delete. It is probably not installed
[BaseDriver] Event ‘resetComplete’ logged at 1611043117676 (09:58:37 GMT+0200 (South Africa Standard Time))
[WebDriverAgent] Using WDA path: ‘/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent’
[WebDriverAgent] Using WDA agent: ‘/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj’
[XCUITest] Continuing without capturing device logs: iOS Simulator with udid ‘ECEF671A-F3F4-4838-894E-BE9CBACE9C6F’ is not running
[XCUITest] Setting up simulator
[iOS] No reason to set locale
[iOS] No iOS / app preferences to set
[iOS] Setting did not need to be updated
[iOSSim] Setting preferences of ECEF671A-F3F4-4838-894E-BE9CBACE9C6F Simulator to {“ConnectHardwareKeyboard”:true}
[iOSSim] Setting common Simulator preferences to {“RotateWindowWhenSignaledByGuest”:true,“ConnectHardwareKeyboard”:true}
[iOSSim] Updated ECEF671A-F3F4-4838-894E-BE9CBACE9C6F Simulator preferences at ‘/Users/dany/Library/Preferences/com.apple.iphonesimulator.plist’ with {“DevicePreferences”:{“ECEF671A-F3F4-4838-894E-BE9CBACE9C6F”:{“ConnectHardwareKeyboard”:true}},“RotateWindowWhenSignaledByGuest”:true,“ConnectHardwareKeyboard”:true}
[iOSSim] Starting Simulator UI with command: open -Fn /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID ECEF671A-F3F4-4838-894E-BE9CBACE9C6F -RotateWindowWhenSignaledByGuest 1 -ConnectHardwareKeyboard 1 -PasteboardAutomaticSync 0
[iOSSim] Booting Simulator with UDID ‘ECEF671A-F3F4-4838-894E-BE9CBACE9C6F’…
[simctl] Error running ‘boot’: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
Unable to boot device in current state: Booted
[simctl] Error running ‘boot’: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
Unable to boot device in current state: Booted
[WebDriverAgent] Parsed BUILD_DIR configuration value: ‘/Users/dany/Library/Developer/Xcode/DerivedData/WebDriverAgent-alwvnomvwrdtzoaxbbkniqrpcdpp/Build/Products’
[WebDriverAgent] Got derived data root: ‘/Users/dany/Library/Developer/Xcode/DerivedData/WebDriverAgent-alwvnomvwrdtzoaxbbkniqrpcdpp’
[simctl] Error running ‘boot’: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
Unable to boot device in current state: Booted
[iOSSim] Error running ‘boot’: An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
[iOSSim] Unable to boot device in current state: Booted
[iOSSim] Simulator with UDID ECEF671A-F3F4-4838-894E-BE9CBACE9C6F booted in 10.332s
[BaseDriver] Event ‘simStarted’ logged at 1611043128235 (09:58:48 GMT+0200 (South Africa Standard Time))
[IOSSimulatorLog] Starting log capture for iOS Simulator with udid ‘ECEF671A-F3F4-4838-894E-BE9CBACE9C6F’ using simctl
[BaseDriver] Event ‘logCaptureStarted’ logged at 1611043131727 (09:58:51 GMT+0200 (South Africa Standard Time))
[WebDriverAgent] No obsolete cached processes from previous WDA sessions listening on port 8100 have been found
[DevCon Factory] Requesting connection for device ECEF671A-F3F4-4838-894E-BE9CBACE9C6F on local port 8100
[DevCon Factory] Cached connections count: 0
[DevCon Factory] Successfully requested the connection for ECEF671A-F3F4-4838-894E-BE9CBACE9C6F:8100
[XCUITest] Starting WebDriverAgent initialization with the synchronization key ‘XCUITestDriver’
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WebDriverAgent] WDA is not listening at ‘http://127.0.0.1:8100/
[WebDriverAgent] WDA is currently not running. There is nothing to cache
[XCUITest] Trying to start WebDriverAgent 2 times with 10000ms interval
[XCUITest] These values can be customized by changing wdaStartupRetries/wdaStartupRetryInterval capabilities
[BaseDriver] Event ‘wdaStartAttempted’ logged at 1611043133567 (09:58:53 GMT+0200 (South Africa Standard Time))
[WebDriverAgent] Launching WebDriverAgent on the device
[WebDriverAgent] Fetching dependencies
[WebDriverAgent] Dependencies up-to-date
[WebDriverAgent] Killing running processes ‘xcodebuild.*ECEF671A-F3F4-4838-894E-BE9CBACE9C6F, ECEF671A-F3F4-4838-894E-BE9CBACE9C6F.*XCTRunner, xctest.*ECEF671A-F3F4-4838-894E-BE9CBACE9C6F’ for the device ECEF671A-F3F4-4838-894E-BE9CBACE9C6F…
[WebDriverAgent] ‘pgrep -if xcodebuild.*ECEF671A-F3F4-4838-894E-BE9CBACE9C6F’ didn’t detect any matching processes. Return code: 1
[WebDriverAgent] ‘pgrep -if ECEF671A-F3F4-4838-894E-BE9CBACE9C6F.*XCTRunner’ didn’t detect any matching processes. Return code: 1
[WebDriverAgent] ‘pgrep -if xctest.*ECEF671A-F3F4-4838-894E-BE9CBACE9C6F’ didn’t detect any matching processes. Return code: 1
[WebDriverAgent] Beginning test with command ‘xcodebuild build-for-testing test-without-building -project /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -derivedDataPath /Users/dany/Library/Developer/Xcode/DerivedData/WebDriverAgent-alwvnomvwrdtzoaxbbkniqrpcdpp -destination id=ECEF671A-F3F4-4838-894E-BE9CBACE9C6F IPHONEOS_DEPLOYMENT_TARGET=14.1 GCC_TREAT_WARNINGS_AS_ERRORS=0 COMPILER_INDEX_STORE_ENABLE=NO’ in directory ‘/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent’
[WebDriverAgent] Output from xcodebuild will not be logged. To change this, use ‘showXcodeLog’ desired capability
[WebDriverAgent] Waiting up to 60000ms for WebDriverAgent to start
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WebDriverAgent] Log file for xcodebuild test: /Users/dany/Library/Developer/Xcode/DerivedData/WebDriverAgent-alwvnomvwrdtzoaxbbkniqrpcdpp/Logs/Test/Test-WebDriverAgentRunner-2021.01.19_09-58-56-+0200.xcresult/Staging/2_Test/Diagnostics/WebDriverAgentRunner-4432C859-90DE-4910-A886-874DB304C7EF/WebDriverAgentRunner-1BADC0EF-CB9B-4CD4-80AF-199FD6D08B4D/Session-WebDriverAgentRunner-2021-01-19_095858-SqC6w5.log
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:8100
[WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[WD Proxy] Got response with status 200: {“value”:{“message”:“WebDriverAgent is ready to accept commands”,“state”:“success”,“os”:{“testmanagerdVersion”:28,“name”:“iOS”,“sdkVersion”:“14.0”,“version”:“14.1”},“ios”:{“simulatorVersion”:“14.1”,“ip”:“192.168.8.9”},“ready”:true,“build”:{“upgradedAt”:“1610555781812”,“time”:“Jan 13 2021 18:36:36”,“productBundleIdentifier”:“com.facebook.WebDriverAgentRunner”}},“sessionId”:null}
[WebDriverAgent] WebDriverAgent information:
[WebDriverAgent] {
[WebDriverAgent] “message”: “WebDriverAgent is ready to accept commands”,
[WebDriverAgent] “state”: “success”,
[WebDriverAgent] “os”: {
[WebDriverAgent] “testmanagerdVersion”: 28,
[WebDriverAgent] “name”: “iOS”,
[WebDriverAgent] “sdkVersion”: “14.0”,
[WebDriverAgent] “version”: “14.1”
[WebDriverAgent] },
[WebDriverAgent] “ios”: {
[WebDriverAgent] “simulatorVersion”: “14.1”,
[WebDriverAgent] “ip”: “192.168.8.9”
[WebDriverAgent] },
[WebDriverAgent] “ready”: true,
[WebDriverAgent] “build”: {
[WebDriverAgent] “upgradedAt”: “1610555781812”,
[WebDriverAgent] “time”: “Jan 13 2021 18:36:36”,
[WebDriverAgent] “productBundleIdentifier”: “com.facebook.WebDriverAgentRunner”
[WebDriverAgent] }
[WebDriverAgent] }
[WebDriverAgent] WebDriverAgent successfully started after 11034ms
[BaseDriver] Event ‘wdaSessionAttempted’ logged at 1611043144690 (09:59:04 GMT+0200 (South Africa Standard Time))
[XCUITest] Sending createSession command to WDA
[WD Proxy] Matched ‘/session’ to command name ‘createSession’
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8100/session] with body: {“capabilities”:{“firstMatch”:[{“bundleId”:“com.xxx.app.testing”,“arguments”:[],“environment”:{},“eventloopIdleDelaySec”:5,“shouldWaitForQuiescence”:true,“shouldUseTestManagerForVisibilityDetection”:false,“maxTypingFrequency”:60,“shouldUseSingletonTestManager”:true}],“alwaysMatch”:{}}}
[WD Proxy] Got response with status 400: {“value”:{“error”:“invalid element state”,“message”:“The application under test with bundle id ‘com.xxx.app.testing’ is not running, possibly crashed”,“traceback”:"(\n\t0 CoreFoundation 0x0000000109e5e126 __exceptionPreprocess + 242\n\t1 libobjc.A.dylib 0x0000000109ceef78 objc_exception_throw + 48\n\t2 CoreFoundation 0x0000000109e5ddc7 -[NSException init] + 0\n\t3 WebDriverAgentLib 0x000000012f7e00b3 -[FBSession activeApplication] + 675\n\t4 WebDriverAgentLib 0x000000012f7ed4fa +[FBSessionCommands currentCapabilities] + 90\n\t5 WebDriverAgentLib 0x000000012f7ed3c9 +[FBSessionCommands sessionInformation] + 233\n\t6 WebDriverAgentLib 0x000000012f7ea2b6 +[FBSessionCommands handleCreateSession:] + 2918\n\t7 WebDriverAgentLib 0x000000012f7bb736 -[FBRoute_TargetAction mountRequest:intoResponse:] + 182\n\t8 WebDriverAgentLib …
[W3C] Matched W3C error code ‘invalid element state’ to InvalidElementStateError
[XCUITest] Failed to create WDA session (The application under test with bundle id ‘com.xxx.app.testing’ is not running, possibly crashed). Retrying…
[BaseDriver] Event ‘wdaSessionAttempted’ logged at 1611043162435 (09:59:22 GMT+0200 (South Africa Standard Time))
[XCUITest] Sending createSession command to WDA
[WD Proxy] Matched ‘/session’ to command name ‘createSession’
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8100/session] with body: {“capabilities”:{“firstMatch”:[{“bundleId”:“com.xxx.app.testing”,“arguments”:[],“environment”:{},“eventloopIdleDelaySec”:5,“shouldWaitForQuiescence”:true,“shouldUseTestManagerForVisibilityDetection”:false,“maxTypingFrequency”:60,“shouldUseSingletonTestManager”:true}],“alwaysMatch”:{}}}
Stopping…

[XCUITest] Failed to create WDA session (The application under test with bundle id ‘com.xxx.app.testing’ is not running, possibly crashed)

First, try to start that application ( specifically by running that bundle ) on device/simulator
If it crashes when you manually start it, then it’s not appium fault than the app fault.

from my experience, i would recommend to set these capabilities to false:

  • shouldWaitForQuiescence
  • ShouldUseSingletonTestManager.
1 Like

@vbutiu

The capability’s name is waitForQuiescence, not shouldWaitForQuiescence, isn’t it? (Source) - Or do both exist?

1 Like