Unable to start Appium server

Unable to start Appium server, this is the error I’m seeing:

io.appium.java_client.service.local.InvalidServerInstanceException: The main Appium script does not exist at ‘/usr/local/lib/node_modules/appium/build/lib/main.js’

I am able to run the project from my local machine.

My config.yml:

version: 2.1
jobs:
build:
docker:
- image: circleci/openjdk:8-jdk-node

environment:
  # Customize the JVM maximum heap limit
  MAVEN_OPTS: -Xmx3200m

steps:
  - checkout

  - restore_cache:
      keys:
      - v1-dependencies-{{ checksum "pom.xml" }}
      # fallback to using the latest cache if no exact match is found
      - v1-dependencies-

  - run:
      name: Install appium server
      command: |
        sudo npm update -g
        sudo npm install appium
        sudo npm install wd

  - run:
      name: Start appium
      command: appium &
      background: true

  - run: mvn dependency:go-offline

  - save_cache:
      paths:
        - ~/.m2
      key: v1-dependencies-{{ checksum "pom.xml" }}

  # run tests!
  - run: mvn test

  - run:
      name: Save test results
      command: |
        mkdir -p ~/testng/results/
        find . -type f -regex "./test-output/testng-results.xml" -exec cp {} ~/testng/results/ \;
      when: always
  - store_test_results:
      path: ~/testng/results/
  - store_artifacts:
      path: ~/testng/results/
  - store_artifacts:
      path:  testng/results/

workflows:
maven_test:
jobs:
- build

I’m curious if this might be a path issue and appium is not in the current path when attempting to execute it. The simplest method may just be to install all of those dependencies globally:

        sudo npm update -g
        sudo npm install -g appium
        sudo npm install -g wd

Beyond that, I do see that you are running appium & and also making that process a background: true. You will get more detailed output in that step if you remove the & as background: true should be enough to move that to the next step.

Also, once you have appium running, you may want to add a wait step after launching appium

- run: |
    while ! nc -z localhost 4723; do   
      sleep 2
    done

This would prevent mvn test from running before appium is available.