Error running Appium server in Jenkins

I want to run Appium programmatically in my Pytest script to run Pytests on my Jenkins node:
I have added these commands to my Jenkinsfile:

def runTest(operatingSystem, configType, Version) {
  echo "## Running UI Automation Test ##"
  nodejs(nodeJSInstallationName: 'node') {
  if (operatingSystem.contains('Mac')) {
      runTestVenv(operatingSystem, '/Volumes/jenkins/jenkins_agent_config/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/node --version')   #returns v21.6.2
      runTestVenv(operatingSystem, '/Volumes/jenkins/jenkins_agent_config/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/bin/npm --version')   #returns v10.2.4
      runTestVenv(operatingSystem, 'npm install -g appium')   #returns success
      runTestVenv(operatingSystem, 'appium -v')   #returns 2.5.1
      runTestVenv(operatingSystem, 'appium driver install mac2')   #returns [32mDriver [email protected] successfully installed
      runTestVenv(operatingSystem, "pytest --reruns 3 -vv ${get.UiAutomationTestDir(operatingSystem)}/builds/scripts/ui_automation_test/test_ui-automation.py", "build")
    }
  }

}

From above, I can see from the logs Mac2 driver is successfully installed. In my test_ui-automation.py script:

options = Mac2Options()
options.show_server_logs = True
options.system_port = MAC2_DRIVER_PORT
appium_service = AppiumService()
appium_service.start(args=["--relaxed-security", "--log", "appium.log"])
appium_driver = appium_webdriver.Remote(
    f"http://{APPIUM_HOST}:{APPIUM_PORT}", options=options
)

The Jenkins console output is throwing an error for the above, here is the Jenkins log:

_ ERROR at setup of TestUIAutomation.test1_should_verify_french_im_screen[Google Chrome] _

request = <SubRequest 'setup' for <Function test1_should_verify_french_im_screen[Google Chrome]>>

    @pytest.fixture(scope="class", autouse=True)
    def setup(request):
        global appium_driver, appium_service, start_time, username, password
        load_dotenv()
        username = os.getenv("USERNAME_ENV_VARIABLE")
        password = os.getenv("PASSWORD_ENV_VARIABLE")
        start_time = time.time()
    
        for app in APPS_TO_TERMINATE:
            terminate_process(app)
        terminate_browser_processes()
    
        for app in [TESTAPP_PATH_1, TESTAPP_PATH_2]:
            os.system(f"xattr -r -d com.apple.quarantine '{app}'")
    
        options = Mac2Options()
        options.show_server_logs = True
        options.system_port = MAC2_DRIVER_PORT
        appium_service = AppiumService()
        appium_service.start(args=["--relaxed-security", "--log", "appium.log"])
>       appium_driver = appium_webdriver.Remote(
            f"http://{APPIUM_HOST}:{APPIUM_PORT}", options=options
        )

builds/scripts/ui_automation_test/test_ui-automation.py:105: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
scripts_dependencies_venv/lib/python3.9/site-packages/appium/webdriver/webdriver.py:229: in __init__
    super().__init__(
scripts_dependencies_venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:208: in __init__
    self.start_session(capabilities)
scripts_dependencies_venv/lib/python3.9/site-packages/appium/webdriver/webdriver.py:321: in start_session
    response = self.execute(RemoteCommand.NEW_SESSION, w3c_caps)
scripts_dependencies_venv/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py:347: in execute
    self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f9c58b64a00>
response = {'status': 500, 'value': '{"value":{"error":"unknown error","message":"An unknown server-side error occurred while pro....NodeJSInstallation/node/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:491:57)"}}'}

    def check_response(self, response: Dict[str, Any]) -> None:
        """Checks that a JSON response from the WebDriver does not have an
        error.
    
        :Args:
         - response - The JSON response from the WebDriver server as a dictionary
           object.
    
        :Raises: If the response contains an error message.
        """
        status = response.get("status", None)
        if not status or status == ErrorCode.SUCCESS:
            return
        value = None
        message = response.get("message", "")
        screen: str = response.get("screen", "")
        stacktrace = None
        if isinstance(status, int):
            value_json = response.get("value", None)
            if value_json and isinstance(value_json, str):
                import json
    
                try:
                    value = json.loads(value_json)
                    if len(value) == 1:
                        value = value["value"]
                    status = value.get("error", None)
                    if not status:
                        status = value.get("status", ErrorCode.UNKNOWN_ERROR)
                        message = value.get("value") or value.get("message")
                        if not isinstance(message, str):
                            value = message
                            message = message.get("message")
                    else:
                        message = value.get("message", None)
                except ValueError:
                    pass
    
        exception_class: Type[WebDriverException]
        e = ErrorCode()
        error_codes = [item for item in dir(e) if not item.startswith("__")]
        for error_code in error_codes:
            error_info = getattr(ErrorCode, error_code)
            if isinstance(error_info, list) and status in error_info:
                exception_class = getattr(ExceptionMapping, error_code, WebDriverException)
                break
        else:
            exception_class = WebDriverException
    
        if not value:
            value = response["value"]
        if isinstance(value, str):
            raise exception_class(value)
        if message == "" and "message" in value:
            message = value["message"]
    
        screen = None  # type: ignore[assignment]
        if "screen" in value:
            screen = value["screen"]
    
        stacktrace = None
        st_value = value.get("stackTrace") or value.get("stacktrace")
        if st_value:
            if isinstance(st_value, str):
                stacktrace = st_value.split("\n")
            else:
                stacktrace = []
                try:
                    for frame in st_value:
                        line = frame.get("lineNumber", "")
                        file = frame.get("fileName", "<anonymous>")
                        if line:
                            file = f"{file}:{line}"
                        meth = frame.get("methodName", "<anonymous>")
                        if "className" in frame:
                            meth = f"{frame['className']}.{meth}"
                        msg = "    at %s (%s)"
                        msg = msg % (meth, file)
                        stacktrace.append(msg)
                except TypeError:
                    pass
        if exception_class == UnexpectedAlertPresentException:
            alert_text = None
            if "data" in value:
                alert_text = value["data"].get("text")
            elif "alert" in value:
                alert_text = value["alert"].get("text")
            raise exception_class(message, screen, stacktrace, alert_text)  # type: ignore[call-arg]  # mypy is not smart enough here
>       raise exception_class(message, screen, stacktrace)
E       selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Mac2Driver server is not listening within 120000ms timeout. Try to increase the value of 'serverStartupTimeout' capability, check the server logs and make sure the xcodebuild host process could be started manually from a terminal
E       Stacktrace:
E       UnknownError: An unknown server-side error occurred while processing the command. Original error: Mac2Driver server is not listening within 120000ms timeout. Try to increase the value of 'serverStartupTimeout' capability, check the server logs and make sure the xcodebuild host process could be started manually from a terminal
E           at getResponseForW3CError (/Volumes/jenkins/jenkins_agent_config/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/errors.js:1118:9)
E           at asyncHandler (/Volumes/jenkins/jenkins_agent_config/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:491:57)

scripts_dependencies_venv/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py:229: WebDriverException
------------------------------ Captured log setup ------------------------------
WARNING  urllib3.connectionpool:connectionpool.py:874 Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9c58ae05b0>: Failed to establish a new connection: [Errno 61] Connection refused')': /status
WARNING  urllib3.connectionpool:connectionpool.py:874 Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9c58ae0a90>: Failed to establish a new connection: [Errno 61] Connection refused')': /status
WARNING  urllib3.connectionpool:connectionpool.py:874 Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9c58afe280>: Failed to establish a new connection: [Errno 61] Connection refused')': /status

Furthermore, even though I passed the flag --log appium.log to get the Appium server logs, the file is not getting created in the Jenkins Workspace. How do I view the Appium logs to troubleshoot?

Lot to unpack in this question. My best suggestion to you would be to simplify things as much as possible. Rather than adding your entire test suite to the Jenkins server and then wondering whatā€™s gone wrong in this complex situation with many points of failure, could I suggest to you that you try a very simple test, like say start Appium and verify logs are created & such. Once you have that running it will be much easier to get the rest of it going.

You will probably face the same errors you are seeing now. At that point you should read that log and do some of the things it suggests, like:

  • Try to increase the value of ā€˜serverStartupTimeoutā€™ capability,
  • check the server logs (make sure to get server running before you look for logs!)
  • make sure the xcodebuild host process could be started manually from a terminal

One of the most crucial elements of your story that youā€™ve left out entirely is why you have to install everything from scratch, programmatically. If I had to guess, you are installing on some static virtual machine that canā€™t store the environment that you need for the tests to run. If you can, I would suggest creating an image file that already has your core components (Appium, Mac driver, Xcode, etc.) installed and tested. If you canā€™t do that, then you will need to do some extra work to make sure these things are properly installed, and working, testing of the testing environment. This is a huge job that will not be fun. You can utilize tools like Appium Doctor, but to run that programmatically you would need to parse the output & such. Think about how much easier it would be for you to create an image that you could verify once manually. I donā€™t know your situation, so I can only suggest.

Note that if the server fails to run it wonā€™t create any logs. With a simpler POC you should get to the point of starting the server, then you will get logs and be able to run a more complicated setup.

A lot of people think that a Jenkins setup is easy. I would suggest that even a cursory look will reveal previously unknown complexities. Appium canā€™t solve all of Jenkinsā€™ problems (of course) so my final suggestion to you is a bit of more research. Hereā€™s a good place to start:

@wreed
Thank you for the suggestions. I ran a simple test to start the Appium server first, and the Appium logs was generated in appium.logs with the flag passed. Not sure why but running the Appium server programmatically gave the previous errorā€¦

I then ran Appium as a sh command in my Jenkinsfile instead:

  nodejs(nodeJSInstallationName: 'node') {
  if (operatingSystem.contains('Mac')) {
      sh '''
      if lsof -t -i :4723 > /dev/null
      then
          kill -9 $(lsof -t -i :4723)
      else
          echo "No process listening on port 4723"
      fi
      '''
      runTestVenv(operatingSystem, "npm install -g -d appium")
      runTestVenv(operatingSystem, "appium -v")
      runTestVenv(operatingSystem, "appium driver install mac2")
      runTestVenv(operatingSystem, "xcodebuild -version")
      sh "appium --relaxed-security --log appiumLogs.log --port 4723 &"  //starting appium server here works instead of running programmatically, added & so that Appium server runs in background and does not block the next sh command to ran
      runTestVenv(operatingSystem, "pytest -vv ${getUiAutomationTestDir(operatingSystem)}/builds/scripts/ui_automation_test/test_ui-automation.py", "build")
  }
  }

I can see that the Appium server is running in the logs, but there are errors connecting the Mac2 driver to it. Below are the Appium server logs:

<p>2024-02-19 13:55:08:916 [Appium] Welcome to Appium v2.5.1
2024-02-19 13:55:08:919 [Appium] Non-default server args:
2024-02-19 13:55:08:920 [Appium] { relaxedSecurityEnabled: true }
2024-02-19 13:55:08:921 [Appium] The autodetected Appium home path: /Users/airbuild/.appium
2024-02-19 13:55:08:921 [Appium] Attempting to load driver mac2...
2024-02-19 13:55:08:923 [Appium] Requiring driver at /Users/airbuild/.appium/node_modules/appium-mac2-driver/build/index.js
2024-02-19 13:55:08:998 [Appium] Mac2Driver has been successfully loaded in 0.076s
2024-02-19 13:55:09:018 [Appium] Appium REST http interface listener started on http://0.0.0.0:4723
2024-02-19 13:55:09:019 [Appium] You can provide the following URLs in your client code to connect to this server:
2024-02-19 13:55:09:019 [Appium] 	http://127.0.0.1:4723/ (only accessible from the same host)
2024-02-19 13:55:09:019 [Appium] 	http://10.50.80.207:4723/
2024-02-19 13:55:09:019 [Appium] Available drivers:
2024-02-19 13:55:09:019 [Appium]   - [email protected] (automationName 'Mac2')
2024-02-19 13:55:09:020 [Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
2024-02-19 13:55:17:404 [HTTP] Request idempotency key: e9f19089-5fe9-4b95-8f15-6e3128e9d945
2024-02-19 13:55:17:415 [HTTP] --> POST /session
2024-02-19 13:55:17:415 [HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"Mac2","platformName":"Mac","appium:showServerLogs":true,"appium:systemPort":10101,"appium:serverStartupTimeout":24000}}}
2024-02-19 13:55:17:416 [AppiumDriver@1b0f] Calling AppiumDriver.createSession() with args: [null,null,{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"Mac2","platformName":"Mac","appium:showServerLogs":true,"appium:systemPort":10101,"appium:serverStartupTimeout":24000}}]
2024-02-19 13:55:17:417 [AppiumDriver@1b0f] Event 'newSessionRequested' logged at 1708350917417 (19:25:17 GMT+0530 (India Standard Time))
2024-02-19 13:55:17:420 [Appium] Attempting to find matching driver for automationName 'Mac2' and platformName 'Mac'
2024-02-19 13:55:17:420 [Appium] The 'mac2' driver was installed and matched caps.
2024-02-19 13:55:17:420 [Appium] Will require it at /Users/airbuild/.appium/node_modules/appium-mac2-driver
2024-02-19 13:55:17:424 [Appium] Requiring driver at /Users/airbuild/.appium/node_modules/appium-mac2-driver/build/index.js
2024-02-19 13:55:17:424 [AppiumDriver@1b0f] Appium v2.5.1 creating new Mac2Driver (v1.10.2) session
2024-02-19 13:55:17:424 [AppiumDriver@1b0f] Checking BaseDriver versions for Appium and Mac2Driver
2024-02-19 13:55:17:425 [AppiumDriver@1b0f] Appium's BaseDriver version is 9.5.2
2024-02-19 13:55:17:425 [AppiumDriver@1b0f] Mac2Driver's BaseDriver version is 9.5.2
2024-02-19 13:55:17:426 [AppiumDriver@1b0f] Applying relaxed security to 'Mac2Driver' as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
2024-02-19 13:55:17:427 [Mac2Driver@79d5] Creating session with W3C capabilities: {
2024-02-19 13:55:17:427 [Mac2Driver@79d5]   "alwaysMatch": {
2024-02-19 13:55:17:427 [Mac2Driver@79d5]     "platformName": "Mac",
2024-02-19 13:55:17:427 [Mac2Driver@79d5]     "appium:automationName": "Mac2",
2024-02-19 13:55:17:427 [Mac2Driver@79d5]     "appium:showServerLogs": true,
2024-02-19 13:55:17:427 [Mac2Driver@79d5]     "appium:systemPort": 10101,
2024-02-19 13:55:17:427 [Mac2Driver@79d5]     "appium:serverStartupTimeout": 24000
2024-02-19 13:55:17:427 [Mac2Driver@79d5]   },
2024-02-19 13:55:17:428 [Mac2Driver@79d5]   "firstMatch": [
2024-02-19 13:55:17:428 [Mac2Driver@79d5]     {}
2024-02-19 13:55:17:428 [Mac2Driver@79d5]   ]
2024-02-19 13:55:17:428 [Mac2Driver@79d5] }
2024-02-19 13:55:17:430 [Mac2Driver@79d5 (9821fc90)] Session created with session id: 9821fc90-5bf4-431b-88af-162a40f93ef1
2024-02-19 13:55:17:431 [WebDriverAgentMac] Using bootstrap root: /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac
2024-02-19 13:55:17:432 [WebDriverAgentMac] Using xcodebuild binary at '/usr/bin/xcodebuild'
2024-02-19 13:55:17:433 [WebDriverAgentMac] There is no need to perform the project cleanup. A fresh install has been detected
2024-02-19 13:55:17:434 [WebDriverAgentMac] Using 127.0.0.1 as server host
2024-02-19 13:55:17:434 [WebDriverAgentMac] Using port 10101
2024-02-19 13:55:17:437 [WebDriverAgentMac] Starting Mac2Driver host process: xcodebuild build-for-testing test-without-building -project /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj -scheme WebDriverAgentRunner COMPILER_INDEX_STORE_ENABLE\=NO
2024-02-19 13:55:17:441 [WD Proxy] Matched '/status' to command name 'getStatus'
2024-02-19 13:55:17:441 [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10101/status] with no body
2024-02-19 13:55:17:501 [WD Proxy] connect ECONNREFUSED 127.0.0.1:10101
2024-02-19 13:55:18:301 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:18.300 xcodebuild[9329:69469] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
2024-02-19 13:55:18:301 [WebDriverAgentMac] [xcodebuild] Command line invocation:
2024-02-19 13:55:18:302 [WebDriverAgentMac]     /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild build-for-testing test-without-building -project /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj -scheme WebDriverAgentRunner COMPILER_INDEX_STORE_ENABLE=NO
2024-02-19 13:55:18:302 [WebDriverAgentMac] 
2024-02-19 13:55:18:302 [WebDriverAgentMac] User defaults from command line:
2024-02-19 13:55:18:302 [WebDriverAgentMac]     IDEPackageSupportUseBuiltinSCM = YES
2024-02-19 13:55:18:302 [WebDriverAgentMac] 
2024-02-19 13:55:18:302 [WebDriverAgentMac] Build settings from command line:
2024-02-19 13:55:18:302 [WebDriverAgentMac]     COMPILER_INDEX_STORE_ENABLE = NO
2024-02-19 13:55:18:473 [WebDriverAgentMac] [xcodebuild] --- xcodebuild: WARNING: Using the first of multiple matching destinations:
2024-02-19 13:55:18:473 [WebDriverAgentMac] { platform:macOS, arch:x86_64, id:422D5C6F-EF69-CA29-7098-1D8F98860FE8 }
2024-02-19 13:55:18:474 [WebDriverAgentMac] { platform:macOS, name:Any Mac }
2024-02-19 13:55:18:504 [WD Proxy] Matched '/status' to command name 'getStatus'
2024-02-19 13:55:18:505 [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10101/status] with no body
2024-02-19 13:55:18:507 [WD Proxy] connect ECONNREFUSED 127.0.0.1:10101
2024-02-19 13:55:18:732 [WebDriverAgentMac] [xcodebuild] Computing target dependency graph and provisioning inputs
2024-02-19 13:55:18:778 [WebDriverAgentMac] [xcodebuild] Create build description
2024-02-19 13:55:18:803 [WebDriverAgentMac] [xcodebuild] note: Building targets in dependency order
2024-02-19 13:55:18:818 [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/airbuild/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx13.3-22E245-.sdkstatcache
2024-02-19 13:55:18:818 [WebDriverAgentMac]     cd /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj
2024-02-19 13:55:18:819 [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/airbuild/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx13.3-22E245-.sdkstatcache
2024-02-19 13:55:18:964 [WebDriverAgentMac] [xcodebuild] ** TEST BUILD SUCCEEDED **
2024-02-19 13:55:18:966 [WebDriverAgentMac] [xcodebuild] --- xcodebuild: WARNING: Using the first of multiple matching destinations:
2024-02-19 13:55:18:966 [WebDriverAgentMac] { platform:macOS, arch:x86_64, id:422D5C6F-EF69-CA29-7098-1D8F98860FE8 }
2024-02-19 13:55:18:966 [WebDriverAgentMac] { platform:macOS, name:Any Mac }
2024-02-19 13:55:18:975 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:18.975 xcodebuild[9329:69469] [MT] IDETestingSystemActivityDebug: Failed to suppress screen saver (SACSetScreenSaverCanRun returned 22)
2024-02-19 13:55:19:049 [WebDriverAgentMac] [xcodebuild] *** If you believe this error represents a bug, please attach the result bundle at /Users/airbuild/Library/Developer/Xcode/DerivedData/WebDriverAgentMac-fdrjklffbzkvilhgtqdkpzgwtddm/Logs/Test/Test-WebDriverAgentRunner-2024.02.19_19-25-18-+0530.xcresult
2024-02-19 13:55:19:054 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:19.054 xcodebuild[9329:69492]  IDETestOperationsObserverDebug: Failure collecting logarchive: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.testmanagerd.control was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.testmanagerd.control was invalidated: failed at lookup with error 3 - No such process.}
2024-02-19 13:55:19:058 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:19.057 xcodebuild[9329:69469] [MT] IDETestOperationsObserverDebug: 0.022 elapsed -- Testing started completed.
2024-02-19 13:55:19:058 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:19.057 xcodebuild[9329:69469] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
2024-02-19 13:55:19:058 [WebDriverAgentMac] 2024-02-19 19:25:19.057 xcodebuild[9329:69469] [MT] IDETestOperationsObserverDebug: 0.022 sec, +0.022 sec -- end
2024-02-19 13:55:19:157 [WebDriverAgentMac] [xcodebuild] Test session results, code coverage, and logs:
2024-02-19 13:55:19:157 [WebDriverAgentMac] 	/Users/airbuild/Library/Developer/Xcode/DerivedData/WebDriverAgentMac-fdrjklffbzkvilhgtqdkpzgwtddm/Logs/Test/Test-WebDriverAgentRunner-2024.02.19_19-25-18-+0530.xcresult
2024-02-19 13:55:19:157 [WebDriverAgentMac] [xcodebuild] Testing failed:
2024-02-19 13:55:19:157 [WebDriverAgentMac] 	The test runner encountered an error (Failed to establish communication with the test runner. If you believe this error represents a bug, please attach the result bundle at /Users/airbuild/Library/Developer/Xcode/DerivedData/WebDriverAgentMac-fdrjklffbzkvilhgtqdkpzgwtddm/Logs/Test/Test-WebDriverAgentRunner-2024.02.19_19-25-18-+0530.xcresult. (Underlying Error: CouldnĆ¢ā‚¬ā„¢t communicate with a helper application. Try your operation again. If that fails, quit and relaunch the application and try again. The connection to service named com.apple.testmanagerd.control was invalidated: failed at lookup with error 3 - No such process.))
2024-02-19 13:55:19:158 [WebDriverAgentMac] 
2024-02-19 13:55:19:158 [WebDriverAgentMac] ** TEST EXECUTE FAILED **
2024-02-19 13:55:19:158 [WebDriverAgentMac] [xcodebuild] Testing started
2024-02-19 13:55:19:166 [WebDriverAgentMac] Mac2Driver host process has exited with code 65, signal null
2024-02-19 13:55:19:508 [WebDriverAgentMac] Mac2Driver session cannot be stopped, because the server is not running
2024-02-19 13:55:19:510 [AppiumDriver@1b0f] Event 'newSessionStarted' logged at 1708350919509 (19:25:19 GMT+0530 (India Standard Time))
2024-02-19 13:55:19:510 [AppiumDriver@1b0f] Encountered internal error running command: Error: An unknown server-side error occurred while processing the command. Original error: 'GET /status' cannot be proxied to Mac2 Driver server because its process is not running (probably crashed). Check the Appium log for more details
2024-02-19 13:55:19:510 [AppiumDriver@1b0f]     at WDAMacServer.isProxyReady (/Users/airbuild/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:316:15)
2024-02-19 13:55:19:510 [AppiumDriver@1b0f]     at waitMs (/Users/airbuild/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:412:44)
2024-02-19 13:55:19:510 [AppiumDriver@1b0f]     at spin (/Users/airbuild/.appium/node_modules/appium-mac2-driver/node_modules/asyncbox/lib/asyncbox.js:219:20)
2024-02-19 13:55:19:510 [AppiumDriver@1b0f]     at spin (/Users/airbuild/.appium/node_modules/appium-mac2-driver/node_modules/asyncbox/lib/asyncbox.js:229:14)
2024-02-19 13:55:19:510 [AppiumDriver@1b0f]     at spin (/Users/airbuild/.appium/node_modules/appium-mac2-driver/node_modules/asyncbox/lib/asyncbox.js:229:14)
2024-02-19 13:55:19:510 [AppiumDriver@1b0f]     at waitForCondition (/Users/airbuild/.appium/node_modules/appium-mac2-driver/node_modules/asyncbox/lib/asyncbox.js:236:10)
2024-02-19 13:55:19:510 [AppiumDriver@1b0f]     at WDAMacServer.startSession (/Users/airbuild/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:412:9)
2024-02-19 13:55:19:511 [AppiumDriver@1b0f]     at Mac2Driver.createSession (/Users/airbuild/.appium/node_modules/appium-mac2-driver/lib/driver.js:110:7)
2024-02-19 13:55:19:511 [AppiumDriver@1b0f]     at AppiumDriver.createSession (/Volumes/Extended/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/appium/lib/appium.js:717:35)
2024-02-19 13:55:19:523 [HTTP] <-- POST /session 500 2107 ms - 1092
2024-02-19 13:55:19:523 [HTTP] 
2024-02-19 13:55:19:687 [HTTP] Request idempotency key: e84a7fb4-2a2e-4c29-b3b8-0e766b090256
2024-02-19 13:55:19:688 [HTTP] --> POST /session
2024-02-19 13:55:19:688 [HTTP] {"capabilities":{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"Mac2","platformName":"Mac","appium:showServerLogs":true,"appium:systemPort":10101,"appium:serverStartupTimeout":24000}}}
2024-02-19 13:55:19:688 [AppiumDriver@1b0f] Calling AppiumDriver.createSession() with args: [null,null,{"firstMatch":[{}],"alwaysMatch":{"appium:automationName":"Mac2","platformName":"Mac","appium:showServerLogs":true,"appium:systemPort":10101,"appium:serverStartupTimeout":24000}}]
2024-02-19 13:55:19:688 [AppiumDriver@1b0f] Event 'newSessionRequested' logged at 1708350919688 (19:25:19 GMT+0530 (India Standard Time))
2024-02-19 13:55:19:689 [Appium] Attempting to find matching driver for automationName 'Mac2' and platformName 'Mac'
2024-02-19 13:55:19:689 [Appium] The 'mac2' driver was installed and matched caps.
2024-02-19 13:55:19:689 [Appium] Will require it at /Users/airbuild/.appium/node_modules/appium-mac2-driver
2024-02-19 13:55:19:689 [Appium] Requiring driver at /Users/airbuild/.appium/node_modules/appium-mac2-driver/build/index.js
2024-02-19 13:55:19:689 [AppiumDriver@1b0f] Appium v2.5.1 creating new Mac2Driver (v1.10.2) session
2024-02-19 13:55:19:689 [AppiumDriver@1b0f] Checking BaseDriver versions for Appium and Mac2Driver
2024-02-19 13:55:19:690 [AppiumDriver@1b0f] Appium's BaseDriver version is 9.5.2
2024-02-19 13:55:19:690 [AppiumDriver@1b0f] Mac2Driver's BaseDriver version is 9.5.2
2024-02-19 13:55:19:690 [AppiumDriver@1b0f] Applying relaxed security to 'Mac2Driver' as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
2024-02-19 13:55:19:690 [Mac2Driver@5e4f] Creating session with W3C capabilities: {
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]   "alwaysMatch": {
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]     "platformName": "Mac",
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]     "appium:automationName": "Mac2",
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]     "appium:showServerLogs": true,
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]     "appium:systemPort": 10101,
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]     "appium:serverStartupTimeout": 24000
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]   },
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]   "firstMatch": [
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]     {}
2024-02-19 13:55:19:690 [Mac2Driver@5e4f]   ]
2024-02-19 13:55:19:691 [Mac2Driver@5e4f] }
2024-02-19 13:55:19:692 [Mac2Driver@5e4f (7beabdb4)] Session created with session id: 7beabdb4-77db-4942-96cd-863d4a2bc084
2024-02-19 13:55:19:692 [WebDriverAgentMac] Using bootstrap root: /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac
2024-02-19 13:55:19:692 [WebDriverAgentMac] Using xcodebuild binary at '/usr/bin/xcodebuild'
2024-02-19 13:55:19:693 [WebDriverAgentMac] There is no need to perform the project cleanup. A fresh install has been detected
2024-02-19 13:55:19:693 [WebDriverAgentMac] Using 127.0.0.1 as server host
2024-02-19 13:55:19:693 [WebDriverAgentMac] Using port 10101
2024-02-19 13:55:19:694 [WebDriverAgentMac] Starting Mac2Driver host process: xcodebuild build-for-testing test-without-building -project /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj -scheme WebDriverAgentRunner COMPILER_INDEX_STORE_ENABLE\=NO
2024-02-19 13:55:19:696 [WD Proxy] Matched '/status' to command name 'getStatus'
2024-02-19 13:55:19:697 [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10101/status] with no body
2024-02-19 13:55:19:698 [WD Proxy] connect ECONNREFUSED 127.0.0.1:10101
2024-02-19 13:55:20:589 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:20.588 xcodebuild[9348:69650] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
2024-02-19 13:55:20:593 [WebDriverAgentMac] [xcodebuild] Command line invocation:
2024-02-19 13:55:20:593 [WebDriverAgentMac] [xcodebuild] /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild build-for-testing test-without-building -project /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj -scheme WebDriverAgentRunner COMPILER_INDEX_STORE_ENABLE=NO
2024-02-19 13:55:20:593 [WebDriverAgentMac] 
2024-02-19 13:55:20:593 [WebDriverAgentMac] User defaults from command line:
2024-02-19 13:55:20:593 [WebDriverAgentMac]     IDEPackageSupportUseBuiltinSCM = YES
2024-02-19 13:55:20:593 [WebDriverAgentMac] 
2024-02-19 13:55:20:593 [WebDriverAgentMac] Build settings from command line:
2024-02-19 13:55:20:593 [WebDriverAgentMac]     COMPILER_INDEX_STORE_ENABLE = NO
2024-02-19 13:55:20:698 [WD Proxy] Matched '/status' to command name 'getStatus'
2024-02-19 13:55:20:698 [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:10101/status] with no body
2024-02-19 13:55:20:700 [WD Proxy] connect ECONNREFUSED 127.0.0.1:10101
2024-02-19 13:55:20:772 [WebDriverAgentMac] [xcodebuild] --- xcodebuild: WARNING: Using the first of multiple matching destinations:
2024-02-19 13:55:20:772 [WebDriverAgentMac] { platform:macOS, arch:x86_64, id:422D5C6F-EF69-CA29-7098-1D8F98860FE8 }
2024-02-19 13:55:20:772 [WebDriverAgentMac] { platform:macOS, name:Any Mac }
2024-02-19 13:55:21:025 [WebDriverAgentMac] [xcodebuild] Computing target dependency graph and provisioning inputs
2024-02-19 13:55:21:075 [WebDriverAgentMac] [xcodebuild] Create build description
2024-02-19 13:55:21:099 [WebDriverAgentMac] [xcodebuild] note: Building targets in dependency order
2024-02-19 13:55:21:115 [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/airbuild/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx13.3-22E245-.sdkstatcache
2024-02-19 13:55:21:115 [WebDriverAgentMac]     cd /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj
2024-02-19 13:55:21:115 [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/airbuild/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx13.3-22E245-.sdkstatcache
2024-02-19 13:55:21:168 [WebDriverAgentMac] [xcodebuild] ** TEST BUILD SUCCEEDED **
2024-02-19 13:55:21:169 [WebDriverAgentMac] [xcodebuild] --- xcodebuild: WARNING: Using the first of multiple matching destinations:
2024-02-19 13:55:21:169 [WebDriverAgentMac] { platform:macOS, arch:x86_64, id:422D5C6F-EF69-CA29-7098-1D8F98860FE8 }
2024-02-19 13:55:21:169 [WebDriverAgentMac] { platform:macOS, name:Any Mac }
2024-02-19 13:55:21:181 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:21.180 xcodebuild[9348:69650] [MT] IDETestingSystemActivityDebug: Failed to suppress screen saver (SACSetScreenSaverCanRun returned 22)
2024-02-19 13:55:21:249 [WebDriverAgentMac] [xcodebuild] *** If you believe this error represents a bug, please attach the result bundle at /Users/airbuild/Library/Developer/Xcode/DerivedData/WebDriverAgentMac-fdrjklffbzkvilhgtqdkpzgwtddm/Logs/Test/Test-WebDriverAgentRunner-2024.02.19_19-25-20-+0530.xcresult
2024-02-19 13:55:21:255 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:21.255 xcodebuild[9348:69704]  IDETestOperationsObserverDebug: Failure collecting logarchive: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.testmanagerd.control was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.testmanagerd.control was invalidated: failed at lookup with error 3 - No such process.}
2024-02-19 13:55:21:258 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:21.258 xcodebuild[9348:69650] [MT] IDETestOperationsObserverDebug: 0.024 elapsed -- Testing started completed.
2024-02-19 13:55:21:258 [WebDriverAgentMac] [xcodebuild] 2024-02-19 19:25:21.258 xcodebuild[9348:69650] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
2024-02-19 13:55:21:258 [WebDriverAgentMac] 2024-02-19 19:25:21.258 xcodebuild[9348:69650] [MT] IDETestOperationsObserverDebug: 0.024 sec, +0.024 sec -- end
2024-02-19 13:55:21:362 [WebDriverAgentMac] [xcodebuild] Test session results, code coverage, and logs:
2024-02-19 13:55:21:363 [WebDriverAgentMac] 	/Users/airbuild/Library/Developer/Xcode/DerivedData/WebDriverAgentMac-fdrjklffbzkvilhgtqdkpzgwtddm/Logs/Test/Test-WebDriverAgentRunner-2024.02.19_19-25-20-+0530.xcresult
2024-02-19 13:55:21:363 [WebDriverAgentMac] [xcodebuild] Testing failed:
2024-02-19 13:55:21:363 [WebDriverAgentMac] 	The test runner encountered an error (Failed to establish communication with the test runner. If you believe this error represents a bug, please attach the result bundle at /Users/airbuild/Library/Developer/Xcode/DerivedData/WebDriverAgentMac-fdrjklffbzkvilhgtqdkpzgwtddm/Logs/Test/Test-WebDriverAgentRunner-2024.02.19_19-25-20-+0530.xcresult. (Underlying Error: CouldnĆ¢ā‚¬ā„¢t communicate with a helper application. Try your operation again. If that fails, quit and relaunch the application and try again. The connection to service named com.apple.testmanagerd.control was invalidated: failed at lookup with error 3 - No such process.))
2024-02-19 13:55:21:363 [WebDriverAgentMac] 
2024-02-19 13:55:21:363 [WebDriverAgentMac] ** TEST EXECUTE FAILED **
2024-02-19 13:55:21:363 [WebDriverAgentMac] [xcodebuild] Testing started
2024-02-19 13:55:21:373 [WebDriverAgentMac] Mac2Driver host process has exited with code 65, signal null
2024-02-19 13:55:21:701 [WebDriverAgentMac] Mac2Driver session cannot be stopped, because the server is not running
2024-02-19 13:55:21:701 [AppiumDriver@1b0f] Event 'newSessionStarted' logged at 1708350921701 (19:25:21 GMT+0530 (India Standard Time))
2024-02-19 13:55:21:701 [AppiumDriver@1b0f] Encountered internal error running command: Error: An unknown server-side error occurred while processing the command. Original error: 'GET /status' cannot be proxied to Mac2 Driver server because its process is not running (probably crashed). Check the Appium log for more details
2024-02-19 13:55:21:701 [AppiumDriver@1b0f]     at WDAMacServer.isProxyReady (/Users/airbuild/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:316:15)
2024-02-19 13:55:21:701 [AppiumDriver@1b0f]     at waitMs (/Users/airbuild/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:412:44)
2024-02-19 13:55:21:701 [AppiumDriver@1b0f]     at spin (/Users/airbuild/.appium/node_modules/appium-mac2-driver/node_modules/asyncbox/lib/asyncbox.js:219:20)
2024-02-19 13:55:21:702 [AppiumDriver@1b0f]     at spin (/Users/airbuild/.appium/node_modules/appium-mac2-driver/node_modules/asyncbox/lib/asyncbox.js:229:14)
2024-02-19 13:55:21:702 [AppiumDriver@1b0f]     at spin (/Users/airbuild/.appium/node_modules/appium-mac2-driver/node_modules/asyncbox/lib/asyncbox.js:229:14)
2024-02-19 13:55:21:702 [AppiumDriver@1b0f]     at waitForCondition (/Users/airbuild/.appium/node_modules/appium-mac2-driver/node_modules/asyncbox/lib/asyncbox.js:236:10)
2024-02-19 13:55:21:702 [AppiumDriver@1b0f]     at WDAMacServer.startSession (/Users/airbuild/.appium/node_modules/appium-mac2-driver/lib/wda-mac.js:412:9)
2024-02-19 13:55:21:702 [AppiumDriver@1b0f]     at Mac2Driver.createSession (/Users/airbuild/.appium/node_modules/appium-mac2-driver/lib/driver.js:110:7)
2024-02-19 13:55:21:702 [AppiumDriver@1b0f]     at AppiumDriver.createSession (/Volumes/Extended/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/appium/lib/appium.js:717:35)
2024-02-19 13:55:21:703 [HTTP] <-- POST /session 500 2015 ms - 1092
2024-02-19 13:55:21:703 [HTTP] 

Can you suggest a tutorial for this? Would it be possible to create an image file containing all dependencies needed if I am running on a Jenkins node shared by other jobs?

I believe the error lies in starting Mac2 driver host process, not sure if it is possible to access this director /Users/airbuild/.appium/node_modules/appium-mac2-driver/WebDriverAgentMac/WebDriverAgentMac.xcodeproj from Jenkins workspace (I canā€™t seem to locate it to debug further) ?

Itā€™s very hard for me to recommend a tutorial for something that has not been named. I have guessed that you are running a VM, and it seems Iā€™m correct but Jenkins does not handle Virtual Machines. Therefore the conclusion must be that itā€™s still some service that you have not shared. I can keep guessing (AWS, Docker, Kubernetes, etc) but it seems we are really outside the Appium discussion topic. Whatever service you are running, read the documentation and look for tutorials for creating (and maintaining) a custom VM for that service.

I agree with you. Seems like you are heading in the right direction, but no advice since I donā€™t know the type of VM you are working with.

Yes, we are running it on ECS nodes. Will creating a custom VM be done in Jenkins?

No, Jenkins is a task manager (albeit one on steroids). I donā€™t use ECS, but I know you can create custom images. I did a web search for ā€œecs custom imageā€. First hit is the instructions from amazon:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-container-image.html

Full search:

https://duckduckgo.com/?q=ecs+custom+image&ia=web

This is way beyond Appium support, so I wish you good luck.

1 Like