CESCO
CESCO

Reputation: 7768

How to run Node.js webdriverio Appium tests on AWS Device Farm

I got a working configuration locally. Running test with Node webdriverio But I want to automate this with de device farm

const webdriverIO = require("webdriverio");

const opts = {
    path: '/wd/hub',
    port: 4723,
    capabilities: {
        platformName: "Android",
        platformVersion: "9",
        deviceName: "emulator-5554",
        app: __dirname +"/app-debug.apk",
        appPackage: "com.ayga.cooktop",
        appActivity: ".MainActivity",
        automationName: "UiAutomator2"
    }
};


const main = async () => {
    const client = await webdriverIO.remote(opts);
    .... actual tests
};

void main();

My build file:

version: 0.1

phases:
  install:
    commands:
      - nvm install 12.16.1
      - echo "Navigate to test package directory"
      - cd $DEVICEFARM_TEST_PACKAGE_PATH
      - npm install *.tgz
      - export APPIUM_VERSION=1.14.2
      - avm $APPIUM_VERSION
      - ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium  /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js
  pre_test:
    commands:
      - echo "Start appium server"
      - >-
        appium --log-timestamp
        --default-capabilities "{\"deviceName\": \"$DEVICEFARM_DEVICE_NAME\", \"platformName\":\"$DEVICEFARM_DEVICE_PLATFORM_NAME\",
        \"app\":\"$DEVICEFARM_APP_PATH\", \"udid\":\"$DEVICEFARM_DEVICE_UDID\", \"platformVersion\":\"$DEVICEFARM_DEVICE_OS_VERSION\",
        \"chromedriverExecutable\":\"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE\"}"
        >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &

      - >-
        start_appium_timeout=0;
        while [ true ];
        do
            if [ $start_appium_timeout -gt 60 ];
            then
                echo "appium server never started in 60 seconds. Exiting";
                exit 1;
            fi;
            grep -i "Appium REST http interface listener started on 0.0.0.0:4723" $DEVICEFARM_LOG_DIR/appiumlog.txt >> /dev/null 2>&1;
            if [ $? -eq 0 ];
            then
                echo "Appium REST http interface listener started on 0.0.0.0:4723";
                break;
            else
                echo "Waiting for appium server to start. Sleeping for 1 second";
                sleep 1;
                start_appium_timeout=$((start_appium_timeout+1));
            fi;
        done;

  test:
    commands:
      - echo "Navigate to test source code"
      - cd $DEVICEFARM_TEST_PACKAGE_PATH/node_modules/*
      - echo "Start Appium Node test"
      - node index.js
  post_test:
    commands:
artifacts:
  - $DEVICEFARM_LOG_DIR

my test runs, but i was not able to find the apk

enter image description here

How to I tell AWS the apk, deviceName and etc

const opts = {
    path: '/wd/hub',
    port: 4723,
    capabilities: {
        platformName: "Android",
        platformVersion: "9",
        deviceName: "emulator-5554",
        app: __dirname +"/app-debug.apk",
        appPackage: "com.ayga.cooktop",
        appActivity: ".MainActivity",
        automationName: "UiAutomator2"
    }
};

Upvotes: 0

Views: 1499

Answers (1)

CESCO
CESCO

Reputation: 7768

You have to set the capabilities to the AWS provided ENVVARS just like below.

const apkInfo = {
    appPackage: "com.ayga.cooktopbt",
    appActivity: "com.ayga.cooktop.MainActivity",
    automationName: "UiAutomator2"
};

const awsOptions = {
    path: '/wd/hub',
    port: 4723,
    capabilities: {
        ...apkInfo,
        platformName: process.env.DEVICEFARM_DEVICE_PLATFORM_NAME,
        deviceName: process.env.DEVICEFARM_DEVICE_NAME,
        app: process.env.DEVICEFARM_APP_PATH,
    }
};

Upvotes: 2

Related Questions