macOS Setting password in Keychain for UI tests fails 9/10 times


we’re currently migrating our CI jobs from Travis CI to Circle CI. The last job, which is about running UI tests for our Electron app, is giving me headaches. It’s working fine on Travis CI, but would fail 9 out of 10 times on Circle CI due to this error:

Error: User interaction is not allowed.

What we do is to bypass our login window by requesting login credentials programmatically and then we store those in the Keychain using keytar and its setPassword function. This almost all of the time just yields Error: User interaction is not allowed..

The keychain it’s trying to write to is /Users/distiller/Library/Keychains/login.keychain

Any ideas?

Solved this myself now. I am now creating another keychain, set it as default and unlock it and add a timeout before it locks again.

      - run:
          name: "Create and set the default keychain"
          command: |
            security create-keychain -p "" temporary
            security default-keychain -s temporary
            security unlock-keychain -p "" temporary
            security set-keychain-settings -lut 7200 temporary