appium / appium-mac2-driver

Next-gen Appium macOS driver, backed by Apple XCTest
Apache License 2.0
115 stars 24 forks source link

Cannot create new sessions: "Failed to determine bundle identifier" #293

Closed smadsenjc closed 2 months ago

smadsenjc commented 2 months ago

I cannot create a simple automation script and launch any application. The error is always Failed to determine bundle identifier for <app>. The application may be damaged or incomplete.

Appium 2.5.2 Mac2 driver 1.12.0 Xcode 15.3 Sonoma 14.4.1

Here is the error from the Appium server console:

[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:10100/session] with body: {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"platformName":"mac","automationName":"mac2","bundleId":"com.apple.calculator","appPath":"/Applications/Calculator.app"}}}
[WD Proxy] Got response with status 500: {"value":{"error":"unknown error","message":"Failed to determine bundle identifier for '/Applications/Calculator.app'. The application may be damaged or incomplete.","traceback":"(\n\t0   CoreFoundation                      0x000000019181eccc __exceptionPreprocess + 176\n\t1   libobjc.A.dylib                     0x0000000191306788 objc_exception_throw + 60\n\t2   Foundation                          0x000000019298fc6c -[NSCalendarDate initWithCoder:] + 0\n\t3   XCUIAutomation                      0x0000000103188e24 -[XCUIApplication commonInitWithApplicationSpecifier:device:] + 472\n\t4   XCUIAutomation                      0x0000000103188c24 -[XCUIApplication initPrivateWithPath:bundleID:] + 180\n\t5   WebDriverAgentLib                   0x0000000102d5ca9c +[FBSessionCommands handleCreateSession:] + 920\n\t6   WebDriverAgentLib                   0x0000000102d61bf8 -[FBRoute_TargetAction mountRequest:intoResponse:] + 168\n\t7   WebDriverAgentLib                   0x0000000102d5b520 __37-[FBWebServer registe...

Here is a readable form of the backtrace:

0   CoreFoundation                      0x000000019181eccc __exceptionPreprocess + 176
1   libobjc.A.dylib                     0x0000000191306788 objc_exception_throw + 60
2   Foundation                          0x000000019298fc6c -[NSCalendarDate initWithCoder:] + 0
3   XCUIAutomation                      0x0000000103188e24 -[XCUIApplication commonInitWithApplicationSpecifier:device:] + 472
4   XCUIAutomation                      0x0000000103188c24 -[XCUIApplication initPrivateWithPath:bundleID:] + 180
5   WebDriverAgentLib                   0x0000000102d5ca9c +[FBSessionCommands handleCreateSession:] + 920
6   WebDriverAgentLib                   0x0000000102d61bf8 -[FBRoute_TargetAction mountRequest:intoResponse:] + 168
7   WebDriverAgentLib                   0x0000000102d5b520 __37-[FBWebServer registe...

This is my simple testing script:

import unittest
from appium import webdriver
from appium.options.mac import Mac2Options
from appium.webdriver.common.appiumby import AppiumBy

capabilities = dict(
  platformName = "mac",
  automationName = "mac2",
  bundleId = "com.apple.calculator",
  appPath = "/Applications/Calculator.app"
)

appium_server_url = 'http://localhost:4723'

class TestAppium(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Remote(appium_server_url, options=Mac2Options().load_capabilities(capabilities))

    def tearDown(self) -> None:
        if self.driver:
            self.driver.quit()

    def test_find_menu(self) -> None:
        el = self.driver.find_element(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeMenuBarItem')
        el.click()

if __name__ == '__main__':
    unittest.main()
mykola-mokhnach commented 2 months ago
smadsenjc commented 2 months ago

If I remove appPath, it works, although earlier I had problems with it.

Server log:

[Appium] Welcome to Appium v2.5.2 (REV 9edabf02ce29e54d0b717baa757cff38ad0c0e25)
[Appium] The autodetected Appium home path: /Users/smadsen/.appium
[Appium] Attempting to load driver mac2...
[Appium] Requiring driver at /Users/smadsen/.appium/node_modules/appium-mac2-driver/build/index.js
[Appium] Mac2Driver has been successfully loaded in 0.040s
[Appium] Appium REST http interface listener started on http://0.0.0.0:4723
[Appium] You can provide the following URLs in your client code to connect to this server:
[Appium]    http://127.0.0.1:4723/ (only accessible from the same host)
[Appium]    http://192.168.1.230:4723/
[Appium]    http://100.64.0.5:4723/
[Appium]    http://192.168.2.1:4723/
[Appium]    http://100.65.0.1:4723/
[Appium] Available drivers:
[Appium]   - mac2@1.12.0 (automationName 'Mac2')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
[HTTP] Request idempotency key: 6c40dfc5-eea6-4028-9528-c31f80934658
[HTTP] --> POST /session
[HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"mac2","platformName":"mac","appium:bundleId":"com.apple.calculator","appium:appPath":"/Applications/Calculator.app"}}}
[AppiumDriver@e748] Calling AppiumDriver.createSession() with args: [null,null,{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"mac2","platformName":"mac","appium:bundleId":"com.apple.calculator","appium:appPath":"/Applications/Calculator.app"}}]
[AppiumDriver@e748] Event 'newSessionRequested' logged at 1713384811605 (16:13:31 GMT-0400 (Eastern Daylight Time))
[Appium] Attempting to find matching driver for automationName 'mac2' and platformName 'mac'
[Appium] The 'mac2' driver was installed and matched caps.
[Appium] Will require it at /Users/smadsen/.appium/node_modules/appium-mac2-driver
[Appium] Requiring driver at /Users/smadsen/.appium/node_modules/appium-mac2-driver/build/index.js
[AppiumDriver@e748] Appium v2.5.2 creating new Mac2Driver (v1.12.0) session
[AppiumDriver@e748] Checking BaseDriver versions for Appium and Mac2Driver
[AppiumDriver@e748] Appium's BaseDriver version is 9.5.3
[AppiumDriver@e748] Mac2Driver's BaseDriver version is 9.5.3
[Mac2Driver@35fd] Creating session with W3C capabilities: {
[Mac2Driver@35fd]   "alwaysMatch": {
[Mac2Driver@35fd]     "platformName": "mac",
[Mac2Driver@35fd]     "appium:automationName": "mac2",
[Mac2Driver@35fd]     "appium:bundleId": "com.apple.calculator",
[Mac2Driver@35fd]     "appium:appPath": "/Applications/Calculator.app"
[Mac2Driver@35fd]   },
[Mac2Driver@35fd]   "firstMatch": [
[Mac2Driver@35fd]     {}
[Mac2Driver@35fd]   ]
[Mac2Driver@35fd] }
[Mac2Driver@35fd (b4032be6)] Session created with session id: b4032be6-b5a9-464d-b789-e8320736e370
[WebDriverAgentMac] Using bootstrap root: /Users/smadsen/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac
[WebDriverAgentMac] Using xcodebuild binary at '/usr/bin/xcodebuild'
[WebDriverAgentMac] There is no need to perform the project cleanup. A fresh install has been detected
[WebDriverAgentMac] Using 127.0.0.1 as server host
[WebDriverAgentMac] Using port 10100
[WebDriverAgentMac] Mac2Driver host process logging is disabled. All the xcodebuild output is going to be suppressed. Set the 'showServerLogs' capability to 'true' if this is an undesired behavior
[WebDriverAgentMac] Starting Mac2Driver host process: xcodebuild build-for-testing test-without-building -project /Users/smadsen/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj -scheme WebDriverAgentRunner COMPILER_INDEX_STORE_ENABLE\=NO
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:10100
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:10100
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:10100
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:10100
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:10100
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10100/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:10100
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10100/status] with no body
[WD Proxy] Got response with status 200: {"value":{"message":"WebDriverAgent is ready to accept commands","state":"success","os":{"version":"Version 14.4.1 (Build 23E224)"},"ready":true,"build":{"time":"Apr 17 2024 16:13:32"}},"sessionId":null}
[WebDriverAgentMac] The host process is ready within 6230ms
[WD Proxy] Matched '/session' to command name 'createSession'
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:10100/session] with body: {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"platformName":"mac","automationName":"mac2","bundleId":"com.apple.calculator","appPath":"/Applications/Calculator.app"}}}
[WD Proxy] Got response with status 500: {"value":{"error":"unknown error","message":"Failed to determine bundle identifier for '/Applications/Calculator.app'. The application may be damaged or incomplete.","traceback":"(\n\t0   CoreFoundation                      0x000000019181eccc __exceptionPreprocess + 176\n\t1   libobjc.A.dylib                     0x0000000191306788 objc_exception_throw + 60\n\t2   Foundation                          0x000000019298fc6c -[NSCalendarDate initWithCoder:] + 0\n\t3   XCUIAutomation                      0x0000000103188e24 -[XCUIApplication commonInitWithApplicationSpecifier:device:] + 472\n\t4   XCUIAutomation                      0x0000000103188c24 -[XCUIApplication initPrivateWithPath:bundleID:] + 180\n\t5   WebDriverAgentLib                   0x0000000102d5ca9c +[FBSessionCommands handleCreateSession:] + 920\n\t6   WebDriverAgentLib                   0x0000000102d61bf8 -[FBRoute_TargetAction mountRequest:intoResponse:] + 168\n\t7   WebDriverAgentLib                   0x0000000102d5b520 __37-[FBWebServer registe...
[W3C] Matched W3C error code 'unknown error' to UnknownError
[AppiumDriver@e748] Event 'newSessionStarted' logged at 1713384817882 (16:13:37 GMT-0400 (Eastern Daylight Time))
[AppiumDriver@e748] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Failed to determine bundle identifier for '/Applications/Calculator.app'. The application may be damaged or incomplete.
[AppiumDriver@e748]     at errorFromW3CJsonCode (/opt/homebrew/Cellar/appium/2.5.2/libexec/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/errors.js:1112:25)
[AppiumDriver@e748]     at ProxyRequestError.getActualError (/opt/homebrew/Cellar/appium/2.5.2/libexec/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/errors.js:981:14)
[AppiumDriver@e748]     at WDAMacProxy.command (/opt/homebrew/Cellar/appium/2.5.2/libexec/lib/node_modules/appium/node_modules/@appium/base-driver/lib/jsonwp-proxy/proxy.js:353:19)
[AppiumDriver@e748]     at processTicksAndRejections (node:internal/process/task_queues:95:5)
[AppiumDriver@e748]     at WDAMacServer.startSession (/Users/smadsen/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:444:5)
[AppiumDriver@e748]     at Mac2Driver.createSession (/Users/smadsen/.appium/node_modules/appium-mac2-driver/lib/driver.js:115:7)
[AppiumDriver@e748]     at AppiumDriver.createSession (/opt/homebrew/Cellar/appium/2.5.2/libexec/lib/node_modules/appium/lib/appium.js:717:35)
[HTTP] <-- POST /session 500 6282 ms - 1400
[HTTP] 
^C[Appium] Received SIGINT - shutting down
[AppiumDriver@e748] There are no active sessions for cleanup
[HTTP] Waiting until the server is closed
[HTTP] Received server close event
KazuCocoa commented 2 months ago

Did the Calculator path exist on your host? For example, on my host has /System/Applications/Calculator.app but it is not in /Applications.

smadsenjc commented 2 months ago

🤦‍♂️ Yes, you've got it. I'd forgotten about the sealed system volume because Finder shows a unified view of /Applications. Fixing the path in the test script resolves the problem.