appium / appium-mac2-driver

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

Error using macos: activateApp with path capability #281

Closed MagdelineNg closed 4 months ago

MagdelineNg commented 4 months ago

Not sure why the activateApp function is suddenly not accepting the path capability.

from appium import webdriver as appium_webdriver
from appium.options.mac import Mac2Options

APPIUM_PORT = '4723'
APPIUM_HOST = '127.0.0.1'

options = Mac2Options()
options.show_server_logs = True
options.system_port = 10101

driver = appium_webdriver.Remote(f"http://{APPIUM_HOST}:{APPIUM_PORT}", options=options)
driver.execute_script("macos: activateApp", {"path": "/Applications/Xcode.app"})

Here are the logs from appium server:

[Appium] Welcome to Appium v2.4.1
[Appium] The autodetected Appium home path: /Users/ngm1
[Appium] Attempting to load driver mac2...
[Appium] Requiring driver at /Users/ngm1/node_modules/appium-mac2-driver/build/index.js
[Appium] Mac2Driver has been successfully loaded in 0.427s
[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://172.20.10.10:4723/
[Appium] Available drivers:
[Appium]   - mac2@1.10.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: 47c41c9a-d4ea-47d3-8254-076f63a77530
[HTTP] --> POST /session
[HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"Mac2","platformName":"Mac","appium:showServerLogs":true,"appium:systemPort":10101}}}
[AppiumDriver@7951] Calling AppiumDriver.createSession() with args: [null,null,{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"Mac2","platformName":"Mac","appium:showServerLogs":true,"appium:systemPort":10101}}]
[AppiumDriver@7951] Event 'newSessionRequested' logged at 1708413749664 (15:22:29 GMT+0800 (Singapore Standard 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/ngm1/node_modules/appium-mac2-driver
[Appium] Requiring driver at /Users/ngm1/node_modules/appium-mac2-driver/build/index.js
[AppiumDriver@7951] Appium v2.4.1 creating new Mac2Driver (v1.10.0) session
[AppiumDriver@7951] Checking BaseDriver versions for Appium and Mac2Driver
[AppiumDriver@7951] Appium's BaseDriver version is 9.5.0
[AppiumDriver@7951] Mac2Driver's BaseDriver version is 9.5.2
[Mac2Driver@d7ac] Creating session with W3C capabilities: {
[Mac2Driver@d7ac]   "alwaysMatch": {
[Mac2Driver@d7ac]     "platformName": "Mac",
[Mac2Driver@d7ac]     "appium:automationName": "Mac2",
[Mac2Driver@d7ac]     "appium:showServerLogs": true,
[Mac2Driver@d7ac]     "appium:systemPort": 10101
[Mac2Driver@d7ac]   },
[Mac2Driver@d7ac]   "firstMatch": [
[Mac2Driver@d7ac]     {}
[Mac2Driver@d7ac]   ]
[Mac2Driver@d7ac] }
[Mac2Driver@d7ac (2c6d020c)] Session created with session id: 2c6d020c-4938-4126-8ae9-8c38b84213e6
[WebDriverAgentMac] Using bootstrap root: /Users/ngm1/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 10101
[WebDriverAgentMac] Starting Mac2Driver host process: xcodebuild build-for-testing test-without-building -project /Users/ngm1/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:10101/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:10101
[WebDriverAgentMac] [xcodebuild] 2024-02-20 15:22:30.507 xcodebuild[79689:7398850] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
[WebDriverAgentMac] [xcodebuild] Command line invocation:
[WebDriverAgentMac] [xcodebuild] /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild build-for-testing test-without-building -project /Users/ngm1/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj -scheme WebDriverAgentRunner COMPILER_INDEX_STORE_ENABLE=NO
[WebDriverAgentMac] 
[WebDriverAgentMac] User defaults from command line:
[WebDriverAgentMac]     IDEPackageSupportUseBuiltinSCM = YES
[WebDriverAgentMac] 
[WebDriverAgentMac] Build settings from command line:
[WebDriverAgentMac]     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:10101/status] with no body
[WD Proxy] connect ECONNREFUSED 127.0.0.1:10101
[WebDriverAgentMac] [xcodebuild] --- xcodebuild: WARNING: Using the first of multiple matching destinations:
[WebDriverAgentMac] { platform:macOS, arch:arm64, id:00006020-000A711E2E33C01E }
[WebDriverAgentMac] { platform:macOS, arch:x86_64, id:00006020-000A711E2E33C01E }
[WebDriverAgentMac] { platform:macOS, name:Any Mac }
[WebDriverAgentMac] [xcodebuild] Computing target dependency graph and provisioning inputs
[WebDriverAgentMac] [xcodebuild] Create build description
[WebDriverAgentMac] [xcodebuild] note: Building targets in dependency order
[WebDriverAgentMac] [xcodebuild] ClangStatCache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk /Users/ngm1/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx13.3-22E245-.sdkstatcache
[WebDriverAgentMac]     cd /Users/ngm1/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj
[WebDriverAgentMac]     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -o /Users/ngm1/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx13.3-22E245-.sdkstatcache
[WebDriverAgentMac] [xcodebuild] ** TEST BUILD SUCCEEDED **
[WebDriverAgentMac] [xcodebuild] --- xcodebuild: WARNING: Using the first of multiple matching destinations:
[WebDriverAgentMac] { platform:macOS, arch:arm64, id:00006020-000A711E2E33C01E }
[WebDriverAgentMac] { platform:macOS, arch:x86_64, id:00006020-000A711E2E33C01E }
[WebDriverAgentMac] { platform:macOS, name:Any Mac }
[WebDriverAgentMac] [xcodebuild] 2024-02-20 15:22:31.215238+0800 WebDriverAgentRunner-Runner[79698:7398991] Running tests...
[WebDriverAgentMac] [xcodebuild] Test Suite 'All tests' started at 2024-02-20 15:22:31.244
[WebDriverAgentMac] [xcodebuild] Test Suite 'WebDriverAgentRunner.xctest' started at 2024-02-20 15:22:31.244
[WebDriverAgentMac] [xcodebuild] Test Suite 'UITestingUITests' started at 2024-02-20 15:22:31.244
[WebDriverAgentMac]     t =      nans Suite Set Up
[WebDriverAgentMac] [xcodebuild] Test Case '-[UITestingUITests testRunner]' started.
[WebDriverAgentMac] [xcodebuild] t =     0.00s Start Test at 2024-02-20 15:22:31.245
[WebDriverAgentMac] [xcodebuild] t =     0.02s Set Up
[WebDriverAgentMac] [xcodebuild] 2024-02-20 15:22:31.262916+0800 WebDriverAgentRunner-Runner[79698:7398991] Built at Feb 20 2024 14:08:07
[WebDriverAgentMac] [xcodebuild] 2024-02-20 15:22:31.267542+0800 WebDriverAgentRunner-Runner[79698:7398991] ServerURLHere->http://localhost:10101<-ServerURLHere
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10101/status] with no body
[WD Proxy] Got response with status 200: {"value":{"message":"WebDriverAgent is ready to accept commands","state":"success","os":{"version":"Version 13.6.2 (assemblage 22G320)"},"ready":true,"build":{"time":"Feb 20 2024 14:08:08"}},"sessionId":null}
[WebDriverAgentMac] The host process is ready within 2170ms
[WD Proxy] Matched '/session' to command name 'createSession'
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:10101/session] with body: {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"platformName":"Mac","automationName":"Mac2","showServerLogs":true,"systemPort":10101}}}
[WD Proxy] Got response with status 200: {"value":{"sessionId":"1815F0A5-6DCB-4CFB-9D8D-A540AA95A2CF","capabilities":{"CFBundleIdentifier":"com.apple.finder"}},"sessionId":"1815F0A5-6DCB-4CFB-9D8D-A540AA95A2CF"}
[WD Proxy] Determined the downstream protocol as 'W3C'
[AppiumDriver@7951] New Mac2Driver session created successfully, session 2c6d020c-4938-4126-8ae9-8c38b84213e6 added to master session list
[AppiumDriver@7951] Event 'newSessionStarted' logged at 1708413751875 (15:22:31 GMT+0800 (Singapore Standard Time))
[Mac2Driver@d7ac (2c6d020c)] Cached the protocol value 'W3C' for the new session 2c6d020c-4938-4126-8ae9-8c38b84213e6
[Mac2Driver@d7ac (2c6d020c)] Responding to client with driver.createSession() result: {"capabilities":{"platformName":"Mac","automationName":"Mac2","showServerLogs":true,"systemPort":10101}}
[HTTP] <-- POST /session 200 2214 ms - 165
[HTTP] 
[HTTP] --> POST /session/2c6d020c-4938-4126-8ae9-8c38b84213e6/execute/sync
[HTTP] {"script":"macos: activateApp","args":[{"path":"/Applications/Xcode.app"}]}
[Mac2Driver@d7ac (2c6d020c)] Calling AppiumDriver.execute() with args: ["macos: activateApp",[{"path":"/Applications/Xcode.app"}],"2c6d020c-4938-4126-8ae9-8c38b84213e6"]
[Mac2Driver] Executing extension command 'macos: activateApp'
[WD Proxy] Proxying [POST /wda/apps/activate] to [POST http://127.0.0.1:10101/session/1815F0A5-6DCB-4CFB-9D8D-A540AA95A2CF/wda/apps/activate] with body: {}
[WD Proxy] Got response with status 400: {"value":{"error":"invalid argument","message":"Either app bundle identifier or app path must be provided","traceback":"(\n\t0   CoreFoundation                      0x000000018e6970e4 __exceptionPreprocess + 176\n\t1   libobjc.A.dylib                     0x000000018e1b5fd0 objc_exception_throw + 60\n\t2   WebDriverAgentLib                   0x00000001118521b0 -[FBSession applicationWithBundleId:orPath:] + 180\n\t3   WebDriverAgentLib                   0x000000011185199c -[FBSession activateApplicationWithBundleId:path:] + 204\n\t4   WebDriverAgentLib                   0x00000001118618f4 +[FBSessionCommands handleSessionAppActivate:] + 200\n\t5   WebDriverAgentLib                   0x0000000111865cf8 -[FBRoute_TargetAction mountRequest:intoResponse:] + 168\n\t6   WebDriverAgentLib                   0x000000011185fcd4 __37-[FBWebServer registerRouteHandlers:]_block_invoke + 652\n\t7   WebDriverAgentLib                   0x0000000111859f48 -[RoutingHTTPServer handleRoute:withRequest:response:] + 168\n\t8   We...
[W3C] Matched W3C error code 'invalid argument' to InvalidArgumentError
[Mac2Driver@d7ac (2c6d020c)] Encountered internal error running command: InvalidArgumentError: Either app bundle identifier or app path must be provided
[Mac2Driver@d7ac (2c6d020c)]     at errorFromW3CJsonCode (/Users/ngm1/node_modules/@appium/base-driver/lib/protocol/errors.js:1085:25)
[Mac2Driver@d7ac (2c6d020c)]     at ProxyRequestError.getActualError (/Users/ngm1/node_modules/@appium/base-driver/lib/protocol/errors.js:954:14)
[Mac2Driver@d7ac (2c6d020c)]     at WDAMacProxy.command (/Users/ngm1/node_modules/@appium/base-driver/lib/jsonwp-proxy/proxy.js:353:19)
[Mac2Driver@d7ac (2c6d020c)]     at processTicksAndRejections (node:internal/process/task_queues:95:5)
[Mac2Driver@d7ac (2c6d020c)]     at Mac2Driver.macosActivateApp (/Users/ngm1/node_modules/appium-mac2-driver/lib/commands/app-management.js:48:10)
[Mac2Driver@d7ac (2c6d020c)]     at Mac2Driver.executeMacosCommand (/Users/ngm1/node_modules/appium-mac2-driver/lib/commands/execute.js:54:10)
[Mac2Driver@d7ac (2c6d020c)]     at Mac2Driver.execute (/Users/ngm1/node_modules/appium-mac2-driver/lib/commands/execute.js:44:12)
KazuCocoa commented 4 months ago

How about path instead? https://github.com/appium/appium-mac2-driver?tab=readme-ov-file#macos-activateapp

MagdelineNg commented 4 months ago

Sorry, can you clarify your suggestion? To clarify on my end, I am using driver.execute_script("macos: activateApp", {"path": "/Applications/Xcode.app"}) based on appium/appium-mac2-driver#macos-activateapp

MagdelineNg commented 4 months ago

Closing as I realised the error was using an older version of Appium (that only supported bundleId) due to the machine using an internal npm registry.