Appium Java Testing

Appium Java Testing

Automation with M-Live Connect enables you to test native and hybrid mobile applications using the Appium automation framework. It’s easy to run your Appium tests written using Selenium, TestNG, Junit, Cucumber and Gauge on real Android/iOS devices on Momentum Suite. In this guide, you will learn how to test with TestNG.

  1. Check requirements
  2. Create your account
  3. Upload your app
  4. Clone sample code
  5. Configure and run your first test
  6. View test execution results
  1. Check requirements:
    • Java 11+ If you don’t have it installed, download it from here.
    • Maven is required to run commands. Download it from here.
    • Install the Allure command-line tool, to process the results directory after the test run.
    • You will need access to your Android app (.apk or .aab file) or iOS app (.ipa file) for app testing.
  2. Create your account:
    • You will need a Momentum Suite user and token. If you haven’t created an account yet, sign up for a free trial or purchase a paid plan.
    • After signup, you can obtain your access credentials from the device info popup on any device.
  3. Upload your app:
    • Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to Momentum Suite servers using our GUI. Go to Application Library and Upload your app file.
    • Example uploaded file URL format will be ms://d3fb… You can use it as your Appium’s app capability value.
    • We will automatically resign your IPA iOS file with ours.
    • Optionally you can use a publicly accessible web URL.
  4. Clone sample code:
 
git clone https://github.com/momentumsuite/java-appium-testng-momentumsuite.git

 
  • Run the following command in the project’s base directory to install all dependency packages.
 
mvn clean

 

  1. Configure and run your first test:
{   
    "CLOUD" : {
       "momentum.user": "<momentum-suite-username>",
       "momentum.token": "<momentum-suite-access-key>",
       "momentum.host": "https://console.momentumsuite.com/gateway/wd/hub",
       "ios" : {
            "momentum.app": "ms://<hashed-app-id>",
            "momentum.deviceList": [9998]
        },
        "android" : {
            "momentum.app": "ms://<hashed-app-id>",
            "momentum.deviceList": [9999]
            }
    },
   
   "LOCAL" : {
       "host": "http://127.0.0.1:4723/wd/hub",
       "ios" : {
            "app": "https://momentumsuite.com/downloads/sample.ipa",
            "deviceName": "iPhone 13"
        },
        "android" : {
            "app": "https://momentumsuite.com/downloads/sample.apk",
            "deviceName": "emulator-5554"
        }
    }       
}
  • user (momentum-suite-username), Usually it could be your login email address
  • token (momentum-suite-access-key), Your unique access token learned from momentumsuite.com device-info popup
  • gw (momentum-suite-device-id), Comma-separated Momentum Suite mobile device ID list (4 digit number) to run the test. The first number will be your default phone for all except parallel testing.
  • app (ms://hashed-app-id), Your uploaded IPA, APK or AAB app file from Momentum Suite Application Library. The example format is ms:// Optionally you can use a publicly accessible web URL.
  • This is the sample code part for Appium Capabilities. Do not set deviceName and udid capability values and send an empty value for both. We will handle this for the cloud with gw Appium capability option. 4-digit unique numbers were used, Learn deviceId from the device info popup and update it on testSettings.json file within the array list.
AndroidiOS
        DesiredCapabilities capabilities = new DesiredCapabilities();
        HashMap<String, Object> momentumOptions = new HashMap<String, Object>();
        momentumOptions.put("user", momentumUser);
        momentumOptions.put("token", momentumToken);
        momentumOptions.put("gw", momentumAndroidDeviceId);
        capabilities.setCapability("momentum:options", momentumOptions);
        capabilities.setCapability("appium:platformName", "Android");
        capabilities.setCapability("appium:automationName", "UIAutomator2");
        capabilities.setCapability("appium:autoGrantPermissions", true);
        capabilities.setCapability("appium:language", "en");
        capabilities.setCapability("appium:locale", "en");
        capabilities.setCapability("appium:deviceName", "");
        capabilities.setCapability("appium:udid", "");
        capabilities.setCapability("appium:app", momentumAndroidApp);
        capabilities.setCapability("appium:fullReset", true);
        capabilities.setCapability("appium:noReset", false);
        DesiredCapabilities capabilities = new DesiredCapabilities();
        HashMap<String, Object> momentumOptions = new HashMap<String, Object>();
        momentumOptions.put("user", momentumUser);
        momentumOptions.put("token", momentumToken);
        momentumOptions.put("gw", momentumIOSDeviceId);
        capabilities.setCapability("momentum:options", momentumOptions);
        capabilities.setCapability("appium:platformName", "iOS");
        capabilities.setCapability("appium:automationName", "XCUITest");
        capabilities.setCapability("appium:autoAcceptAlerts", true);
        capabilities.setCapability("appium:language", "en");
        capabilities.setCapability("appium:locale", "en");
        capabilities.setCapability("appium:deviceName", "");
        capabilities.setCapability("appium:udid", "");
        capabilities.setCapability("appium:app", momentumIOSApp);
        capabilities.setCapability("appium:fullReset", true);
        capabilities.setCapability("appium:noReset", false);
        capabilities.setCapability("appium:remoteDebugProxy", "gw+2000");
  • Run the following command in the project’s base directory to run the Android getting started project :
 mvn clean test -P android-first


  • Run the following command in the project’s base directory to run the iOS getting started project :
 mvn clean test -P ios-first


All other available commands to start mobile testing:

AndroidiOS
mvn clean test -P android-first
mvn clean test -P android-local
mvn clean test -P android-parallel
mvn clean test -P android-chrome
mvn clean test -P ios-first
mvn clean test -P ios-local
mvn clean test -P ios-parallel
mvn clean test -P ios-safari
  1. View test execution results

Run the following command in the project’s base directory after the completed test run. This command will open a browser window with HTML test results.

allure serve allure-results

Related Posts