Troubleshooting Appium: Resolving MacOS Version Detection Error

Troubleshooting Appium: Resolving MacOS Version Detection Error

5 April 2024 Stephan Petzl Leave a comment Tech-Help

If you’ve encountered an error with Appium that states it could not detect the MacOS X version from the sw_vers output, you’re not alone. This error can prevent Appium from functioning correctly, but with the correct approach, it can be resolved.

The error message typically appears as follows:

✔ Xcode is installed at: /Library/Developer/CommandLineTools
[Error: Could not detect Mac OS X Version from sw_vers output: '10.12
']
            

Identifying the Issue

The root of the problem lies within the Appium’s system files, where the MacOS version ‘10.12’ is not recognized correctly. To fix this, certain files within the Appium package need to be manually edited to include the missing version.

Step-by-Step Solution

  1. Open Terminal on your Mac.
  2. Locate the files that need to be edited by executing the following command:
    grep -rl "Could not detect Mac OS X Version from sw_vers output:" /Applications/Appium.app/
  3. The Terminal will display file paths that need to be edited. These will typically include paths to system.js files within the Appium.app directory.
  4. Edit each file using a text editor like vim. For example:
    vim /Applications/Appium.app//Contents/Resources/node_modules/appium/node_modules/appium-support/build/lib/system.js
  5. In each file, you will need to make the following changes:
    • Include ‘10.12’ in the MacOS versions array.

      Change From:

      case 10:
          _arr = ['10.8', '10.9', '10.10', '10.11'];
          _i = 0;
                                  

      To:

      case 10:
          _arr = ['10.8', '10.9', '10.10', '10.11', '10.12'];
          _i = 0;
                                  
    • Ensure that the output from the exec command is trimmed.

      Change From:

      try {
          stdout = (await exec('sw_vers', ['-productVersion'])).stdout;
      }
                                  

      To:

      try {
          stdout = (await exec('sw_vers', ['-productVersion'])).stdout.trim();
      }
                                  
    • Include ‘10.12’ in the version checking logic.

      Change From:

      for (let v of ['10.8', '10.9', '10.10', '10.11']) {
          if (stdout.indexOf(v) === 0) { return v; }
      }
                                  

      To:

      for (let v of ['10.8', '10.9', '10.10', '10.11', '10.12']) {
          if (stdout.indexOf(v) === 0) { return v; }
      }
                                  
  6. After making the changes, save the files and exit the text editor.
  7. Restart Appium and click on the stethoscope button to verify that the error has been resolved.

Conclusion

By following these steps, you should be able to resolve the MacOS version detection error in Appium. This will allow you to continue with your app testing and development activities without further hindrance.

Like this article? there’s more where that came from!