Appium Java Test NG tests are not running in the AWS Device Farm

0

Hello Guys,

I am trying to run the appium Test NG automated tests using teng.xml file with device farm. However, my tests are not running after unzipping the tests.jar file. There is no error in the log file, so I am unable to find out the reason.

Custom environment yaml file:

version: 0.1

phases:
  install:
    commands:
      # This test execution environment uses Appium version 1.9.1 by default, however we enable you to change it using the Appium version manager (avm). An
      - 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

  # The pre-test phase includes commands that setup your test environment.
  pre_test:
    commands:
      # Setup environment variables for java
      - 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
        --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:
      # Your test package is downloaded in $DEVICEFARM_TEST_PACKAGE_PATH so we first change directory to that path.
      - echo "Navigate to test package directory"
      - cd $DEVICEFARM_TEST_PACKAGE_PATH

 # 1. Your testng.xml is inside the test jar after packaging step. Unzip it using commands:
      - echo "Unzipping TestNG tests jar"
      - unzip *-tests.jar
      # 2. Run your TestSuite by specifying the unzipped testng.xml using commands:
      - ls -ltr
      - which appium
      - appium -v
      - pwd
      - node -v
      - appium -v
      - which node
      - echo $DEVICEFARM_LOG_DIR
      - echo "Start Appium TestNG test"
      - java org.testng.TestNG -d $DEVICEFARM_LOG_DIR/test-output testng_android.xml

Error Log:

[DeviceFarm] echo "Start Appium TestNG test"
Start Appium TestNG test
[DeviceFarm] java org.testng.TestNG -d $DEVICEFARM_LOG_DIR/test-output testng_android.xml
log4j:WARN No appenders could be found for logger (mobile.common.filereader.ConfigFileReaderUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[TestNG] Running:
  /tmp/scratchDVpVKr.scratch/test-packagemJj_ph/testng_android.xml

===============================================
Android Regression Tests
Total tests run: 2, Failures: 0, Skips: 2
Configuration Failures: 2, Skips: 1
===============================================

https://us-west-2.console.aws.amazon.com/devicefarm/home?region=us-east-1#/mobile/projects/e7d85810-369a-443b-ac29-86ab38065b81/runs/6d8ad0d2-394c-4de5-898a-eed8e816745c/jobs/00000 Could someone please help me out ?

Regards, Sekar

asked 2 years ago959 views
3 Answers
1
Accepted Answer

Hello Sekar,

Thank you for reaching out to us .

You are getting above issue because you are trying to start server instance before execute any test cases. We recommend to have condition check that if the code is running on device farm then they do not need to start a server instance but instead connect to the one already created at 127.0.0.1:4723/wd/hub

Sample code attached

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
answered 2 years ago
profile picture
EXPERT
reviewed a month ago
0

Thank you, Narmadha/Team !!

The aforementioned solution worked for Android, but it's not working yet for iOS.

Sample run - https://us-west-2.console.aws.amazon.com/devicefarm/home?region=us-east-1#/mobile/projects/e071e911-872f-4500-9712-c6f70c427d9f/runs/13a9a74c-39c0-499d-9304-fa70cbcd29f3/jobs/00000

Error:

Failed to invoke configuration method mobile.iosapp.common.IosBaseTest.setUpIosApp:com.google.common.base.Platform.stringIsNullOrEmpty(Ljava/lang/String;)Z
[TestNG] FAILED CONFIGURATION: "iOS Regression Tests" - @BeforeClass mobile.iosapp.common.IosBaseTest.setUpIosApp(org.testng.ITestContext)(value(s): org.testng.TestRunner@2a7686a7) finished in 0 ms
[TestNG] java.lang.NoSuchMethodError: com.google.common.base.Platform.stringIsNullOrEmpty(Ljava/lang/String;)Z

BaseTest class:

`

DesiredCapabilities capabilities = new DesiredCapabilities();
loadConfigProperties();
if (System.getenv("DEVICEFARM_DEVICE_NAME") == null) {
  startServer();
  appiumDriver = iosCapabilities("ios_demo_app");
} else {
  System.out.println("####### new implementation - config properties are loading #######");
  capabilities.setCapability("BUNDLE_ID", configProperties.getProperty("ios_bundle_id"));
  capabilities.setCapability(
      "PLATFORM_NAME", configProperties.getProperty("ios_platform_name"));
  capabilities.setCapability(
      "AUTOMATION_NAME", configProperties.getProperty("ios_automation_name"));
  System.out.println("bundle id is : " + configProperties.getProperty("ios_bundle_id"));
  System.out.println("####### new implementation successful #######");

  appiumDriver = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
appiumDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);}`

Could you please help If the usage of any dependency is not correct ?

Reagrds, Sekar

answered 2 years ago
0

Hello Guys,

The aforementioned issue has been fixed after excluding the google collections jar in the maven-site-plugin. I am able to run the iOS tests in the AWS console successfully now.

<exclusion> <groupId>com.google.collections</groupId> <artifactId>google-collections</artifactId> </exclusion>

answered 2 years 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