appium / appium-mac2-driver

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

Permission issues launching the app using app path after first launch #273

Closed MagdelineNg closed 5 months ago

MagdelineNg commented 5 months ago

When I first launch my app using the script below,

APPIUM_PORT = '4723'
APPIUM_HOST = '127.0.0.1'
BUNDLE_ID = "com.company.companyapp"
APPLICATION_NAME = "companyapp"

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": '/Users/usr/companyapp.app'})

The pop-up shown below for "Application Downloaded From The Internet" warning appears, and I click "Open" and it successfully launches the app.

first-launch-succeeds

However, I am getting permission errors launching the app on subsequent runs on the same script.

image

The appium server logs are below: [Appium] Welcome to Appium v2.4.1 [Appium] The autodetected Appium home path: /Users/ngm1/.appium [Appium] Attempting to load driver xcuitest... [Appium] Attempting to load driver mac2... [Appium] Requiring driver at /Users/ngm1/.appium/node_modules/appium-xcuitest-driver/build/index.js [Appium] Requiring driver at /Users/ngm1/.appium/node_modules/appium-mac2-driver/build/index.js [Appium] XCUITestDriver has been successfully loaded in 1.434s [Appium] Mac2Driver has been successfully loaded in 1.434s [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.50.75:4723/ [Appium] Available drivers: [Appium] - xcuitest@5.12.1 (automationName 'XCUITest') [Appium] - mac2@1.10.2 (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: 91b175e7-90ee-4c9a-8ae9-6d5d5201ef3d [HTTP] --> POST /session [HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"Mac2","platformName":"Mac","appium:showServerLogs":true,"appium:systemPort":10101}}} [AppiumDriver@a19b] Calling AppiumDriver.createSession() with args: [null,null,{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"Mac2","platformName":"Mac","appium:showServerLogs":true,"appium:systemPort":10101}}] [AppiumDriver@a19b] Event 'newSessionRequested' logged at 1705912036353 (16:27:16 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/.appium/node_modules/appium-mac2-driver [Appium] Requiring driver at /Users/ngm1/.appium/node_modules/appium-mac2-driver/build/index.js [AppiumDriver@a19b] Appium v2.4.1 creating new Mac2Driver (v1.10.2) session [AppiumDriver@a19b] Checking BaseDriver versions for Appium and Mac2Driver [AppiumDriver@a19b] Appium's BaseDriver version is 9.5.0 [AppiumDriver@a19b] Mac2Driver's BaseDriver version is 9.5.0 [Mac2Driver@4048] Creating session with W3C capabilities: { [Mac2Driver@4048] "alwaysMatch": { [Mac2Driver@4048] "platformName": "Mac", [Mac2Driver@4048] "appium:automationName": "Mac2", [Mac2Driver@4048] "appium:showServerLogs": true, [Mac2Driver@4048] "appium:systemPort": 10101 [Mac2Driver@4048] }, [Mac2Driver@4048] "firstMatch": [ [Mac2Driver@4048] {} [Mac2Driver@4048] ] [Mac2Driver@4048] } [Mac2Driver@4048 (d75f3d02)] Session created with session id: d75f3d02-e526-4dc6-832c-f37ef4814083 [WebDriverAgentMac] Using bootstrap root: /Users/ngm1/.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 10101 [WebDriverAgentMac] Starting Mac2Driver host process: xcodebuild build-for-testing test-without-building -project /Users/ngm1/.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:10101/status] with no body [WD Proxy] connect ECONNREFUSED 127.0.0.1:10101 [WebDriverAgentMac] [xcodebuild] 2024-01-22 16:27:17.151 xcodebuild[60663:4325894] 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/.appium/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 [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 } [WD Proxy] connect ECONNREFUSED 127.0.0.1:10101 [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/.appium/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-01-22 16:27:18.030524+0800 WebDriverAgentRunner-Runner[60672:4326029] Running tests... [WebDriverAgentMac] [xcodebuild] Test Suite 'All tests' started at 2024-01-22 16:27:18.074 [WebDriverAgentMac] [xcodebuild] Test Suite 'WebDriverAgentRunner.xctest' started at 2024-01-22 16:27:18.074 [WebDriverAgentMac] Test Suite 'UITestingUITests' started at 2024-01-22 16:27:18.074 [WebDriverAgentMac] t = nans Suite Set Up [WebDriverAgentMac] [xcodebuild] Test Case '-[UITestingUITests testRunner]' started. [WebDriverAgentMac] t = 0.00s Start Test at 2024-01-22 16:27:18.075 [WebDriverAgentMac] [xcodebuild] t = 0.03s Set Up [WebDriverAgentMac] [xcodebuild] 2024-01-22 16:27:18.104330+0800 WebDriverAgentRunner-Runner[60672:4326029] Built at Jan 18 2024 13:07:31 [WebDriverAgentMac] [xcodebuild] 2024-01-22 16:27:18.109055+0800 WebDriverAgentRunner-Runner[60672:4326029] 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 (Build 22G320)"},"ready":true,"build":{"time":"Jan 18 2024 13:07:31"}},"sessionId":null} [WebDriverAgentMac] The host process is ready within 2138ms [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":"16575D11-E7FB-40E2-8BEA-75C0AD20D476","capabilities":{"CFBundleIdentifier":"com.apple.finder"}},"sessionId":"16575D11-E7FB-40E2-8BEA-75C0AD20D476"} [WD Proxy] Determined the downstream protocol as 'W3C' [AppiumDriver@a19b] New Mac2Driver session created successfully, session d75f3d02-e526-4dc6-832c-f37ef4814083 added to master session list [AppiumDriver@a19b] Event 'newSessionStarted' logged at 1705912038533 (16:27:18 GMT+0800 (Singapore Standard Time)) [Mac2Driver@4048 (d75f3d02)] Cached the protocol value 'W3C' for the new session d75f3d02-e526-4dc6-832c-f37ef4814083 [Mac2Driver@4048 (d75f3d02)] Responding to client with driver.createSession() result: {"capabilities":{"platformName":"Mac","automationName":"Mac2","showServerLogs":true,"systemPort":10101}} [HTTP] <-- POST /session 200 2185 ms - 165 [HTTP] [HTTP] --> POST /session/d75f3d02-e526-4dc6-832c-f37ef4814083/execute/sync [HTTP] {"script":"macos: activateApp","args":[{"path":"/Users/ngm1/Desktop/companyapp.app"}]} [Mac2Driver@4048 (d75f3d02)] Calling AppiumDriver.execute() with args: ["macos: activateApp",[{"path":"/Users/ngm1/Desktopcompanyapp.app"}],"d75f3d02-e526-4dc6-832c-f37ef4814083"] [Mac2Driver] Executing extension command 'macos: activateApp' [WD Proxy] Proxying [POST /wda/apps/activate] to [POST http://127.0.0.1:10101/session/16575D11-E7FB-40E2-8BEA-75C0AD20D476/wda/apps/activate] with body: {"path":"/Users/ngm1/Desktop/companyapp.app"} [WebDriverAgentMac] [xcodebuild] t = 0.51s Open com.company.companyapp [WebDriverAgentMac] [xcodebuild] t = 0.51s Launch com.company.companyapp [WebDriverAgentMac] [xcodebuild] XCTExpectFailure: matcher accepted Assertion Failure: Failed to launch com.company.companyapp: You do not have permission to run the application “companyapp”. You don’t have permission. To view or change permissions, select the item in the Finder and choose File > Get Info. (Underlying Error: The operation couldn’t be completed. Operation not permitted) [WebDriverAgentMac] [xcodebuild] 2024-01-22 16:27:18.631452+0800 WebDriverAgentRunner-Runner[60672:4326029] Issue type: 0 [WebDriverAgentMac] 2024-01-22 16:27:18.631520+0800 WebDriverAgentRunner-Runner[60672:4326029] Enqueue Failure: Failed to launch com.company.companyapp: You do not have permission to run the application “companyapp”. You don’t have permission. To view or change permissions, select the item in the Finder and choose File > Get Info. (Underlying Error: The operation couldn’t be completed. Operation not permitted) ((null)) (null) 0 0

mykola-mokhnach commented 5 months ago

This is the expected macOS behaviour. A workaround exists for it though: https://apple.stackexchange.com/questions/337320/how-to-get-rid-of-application-downloaded-from-the-internet-message-when-instal

MagdelineNg commented 5 months ago

Even if I get rid of the "application downloaded from the internet" message, the subsequent launches of the app do not have this pop-up but is unable to be activated, as seen in the logs above where " Enqueue Failure: Failed to launch com.company.companyapp: You do not have permission to run the application “companyapp”. You don’t have permission. To view or change permissions, select the item in the Finder and choose File > Get Info. (Underlying Error: The operation couldn’t be completed. Operation not permitted) ((null)) (null) 0 0".

I already allowed all R+W permissions using both chmod and MacOS "Get info > Sharings and Permissions". Only the first run of the script successfully launches the app.

mykola-mokhnach commented 5 months ago

Have you tried the trick with the xattr tool described there?

Also disabling spctl might be a cool feature for a test machine

MagdelineNg commented 5 months ago

Thanks, downloading a fresh version of the binary and running the xattr disabled the permissions errors. Will check out disabling spctl!