Can you show me an example of a pipeline for CircleCI?

High Confidence (77%)

Example of a CircleCI pipeline to run Appium tests with Genymotion SaaS

> Objective: Build the APK, start Genymotion Cloud devices, run Appium tests in parallel, and stop the devices.

Prerequisites
  • Genymotion Cloud account (https://cloud.genymotion.com)
  • API credentials stored as environment variables in the CircleCI project:
  • GMCLOUD_SAAS_EMAIL
  • GMCLOUD_SAAS_PASSWORD
  • Node.js installed in the job image (we'll use cimg/node:20.12.0)
  • Appium test script (test/appium.test.js) ready.

---

1️⃣ File Structure

.project-root/
├── .circleci/
│   └── config.yml          <-- pipeline
├── test/
│   └── appium.test.js      <-- your tests
├── package.json
└── android/
    └── app/
        └── app-debug.apk  <-- built APK

---

2️⃣ config.yml Content

# .circleci/config.yml
version: 2.1

# Orbs that simplify integration
orbs:
  # Official Genymotion orb (available at https://circleci.com/orbs/registry/orb/genymotion/genymotion)
  genymotion: genymotion/genymotion@1.0.0

executors:
  # Default executor (image with Node and JDK)
  node-executor:
    docker:
      - image: cimg/node:20.12.0

jobs:
  build:
    executor: node-executor
    steps:
      - checkout
      - run:
          name: Install dependencies
          command: npm ci
      - run:
          name: Build APK
          command: |
            ./gradlew assembleDebug  # or another build command
      - persist_to_workspace:
          root: .
          paths:
            - android/app/build/outputs/apk/debug/app-debug.apk

  start_devices:
    executor: node-executor
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Start Genymotion devices
          command: |
            # Installing gmsaas if not already installed
            npm i -g @genymotion/gmsaas
            gmsaas start --udid 1 --count 2  # 2 parallel devices
      - persist_to_workspace:
          root: .
          paths:
            - devices.json   # gmsaas saves device info

  run_tests:
    executor: node-executor
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Run Appium tests
          command: |
            # Exporting test variables so the script knows where each device is
            export DEVICES=$(cat devices.json | jq -r '.devices[] | "localhost:\(.port)"' | tr '\n' ',')
            # Example execution (adjust according to your framework)
            npx wdio wdio.conf.js --capabilities.udid="$DEVICES"

  stop_devices:
    executor: node-executor
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Stop Genymotion devices
          command: |
            gmsaas stop

workflows:
  version: 2
  android-ci:
    jobs:
      - build
      - start_devices:
          requires:
            - build
      - run_tests:
          requires:
            - start_devices
      - stop_devices:
          requires:
            - run_tests

Quick Explanation

| Step | What happens | Why | |------|---------------|-----| | build | Builds the APK | Necessary for Appium to test. | | start_devices | Starts 2 Genymotion devices via gmsaas | Enables parallelism and isolation. | | run_tests | Runs Node/Appium tests | Uses DEVICES to point to each emulator. | | stop_devices | Stops the devices | Avoids unnecessary costs/resources. |

---

3️⃣ Configuring Appium (simple example)

// wdio.conf.js
exports.config = {
  runner: 'local',
  path: '/wd/hub',
  port: 4723,
  specs: ['./test/**/*.js'],
  capabilities: [
    {
      platformName: 'Android',
      automationName: 'UiAutomator2',
      app: './android/app/build/outputs/apk/debug/app-debug.apk',
      // `udid` will be replaced with multiple values in execution
    },
  ],
  services: ['appium'],
};

In the test script (`