Appium Java tests are not running in the AWS Device Farm

0

Hello Guys,

I am trying to run the appium automated tests with device farm. However, my tests are not running and failing with the below error.

[TestNG] RUNNING: Suite: "Command line test 41826786-55ed-4502-bf04-08c38bd76f95" containing "17" Tests (config: null)
[Invoker 254801937] Keeping method AndroidBaseTest.setUpAndroidApp(org.testng.ITestContext)[pri:0, instance:mobile.androidapp.androidnativedemo.ApiDemoTestAndroid@32d2fa64] for class [TestClass name=class mobile.androidapp.androidnativedemo.ApiDemoTestAndroid]
[Invoker 254801937] Invoking @BeforeClass AndroidBaseTest.setUpAndroidApp(org.testng.ITestContext)[pri:0, instance:mobile.androidapp.androidnativedemo.ApiDemoTestAndroid@32d2fa64]
[TestNG] INVOKING CONFIGURATION: "Command line test 41826786-55ed-4502-bf04-08c38bd76f95" - @BeforeClass mobile.androidapp.common.AndroidBaseTest.setUpAndroidApp(org.testng.ITestContext)(value(s): org.testng.TestRunner@71c3b41)
Failed to invoke configuration method mobile.androidapp.common.AndroidBaseTest.setUpAndroidApp:The main Appium script does not exist at '/usr/lib/node_modules/appium/build/lib/main.js'
[TestNG] FAILED CONFIGURATION: "Command line test 41826786-55ed-4502-bf04-08c38bd76f95" - @BeforeClass mobile.androidapp.common.AndroidBaseTest.setUpAndroidApp(org.testng.ITestContext)(value(s): org.testng.TestRunner@71c3b41) finished in 0 ms
[TestNG] io.appium.java_client.service.local.InvalidServerInstanceException: The main Appium script does not exist at '/usr/lib/node_modules/appium/build/lib/main.js'

Custom environment yaml file:

version: 0.1

phases:
  install:
    commands:
      - export APPIUM_VERSION=1.18.0
      - 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:
      - export CLASSPATH=$CLASSPATH:$DEVICEFARM_TESTNG_JAR
      - export CLASSPATH=$CLASSPATH:$DEVICEFARM_TEST_PACKAGE_PATH/*
      - export CLASSPATH=$CLASSPATH:$DEVICEFARM_TEST_PACKAGE_PATH/dependency-jars/*
      - echo "Start appium server"
      - >-
        appium --log-timestamp --log-level debug:error
        --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 package directory"
      - cd $DEVICEFARM_TEST_PACKAGE_PATH
      - echo "Start Appium TestNG test"
      - ls -ltr
      - which appium
      - echo $JAVA_HOME
      - which node
      - node -v
      - appium -v
      - java -Dappium.screenshots.dir=$DEVICEFARM_SCREENSHOT_PATH org.testng.TestNG -testjar *-tests.jar -d $DEVICEFARM_LOG_DIR/test-output -verbose 10

  post_test:
    commands:

artifacts:
  # By default, Device Farm will collect your artifacts from following directories
  - $DEVICEFARM_LOG_DIR

https://us-west-2.console.aws.amazon.com/devicefarm/home?region=us-east-1#/mobile/projects/e7d85810-369a-443b-ac29-86ab38065b81/runs/2277ddb7-82ce-4aa5-8d40-3454f1baa009/jobs/00000 Could someone help me ?

Regards, Sekar

asked 2 years ago786 views
1 Answer
0

Hello,

It appears you’re trying to start the server instance before executing any test cases.

We recommend having a condition to check if the code is running on device farm, then you do not need to start a server instance but instead connect to the one already created at 127.0.0.1:4723/wd/hub

A bit of sample code:


final String URL_STRING = "http://127.0.0.1:4723/wd/hub";
    URL url = new URL(URL_STRING);

    //Use a empty DesiredCapabilities object
    DesiredCapabilities capabilities = new DesiredCapabilities();

    if (System.getenv("DEVICEFARM_DEVICE_NAME") == null) {
        //Start an Appium server and set the DesiredCapabilities capabilities only for local development
        
    }
    // Else, I am running on Device Farm, so I dont need to set capabilities

    driver = new AndroidDriver(url, capabilities);

AWS
SUPPORT ENGINEER
Tim_P
answered 2 years ago
profile picture
EXPERT
reviewed 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions