Appium CSharp (C#) Testing

Appium CSharp (C#) 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 Specflow, NUnit2, NUnit3 and MSTest on real Android/iOS devices on Momentum Suite. In this guide, you will learn how to test with latest Nunit3

  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:
    • .NET Core SDK 3.1 If you don’t have it installed, 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/csharp-dotnet-appium-nunit-momentumsuite.git

 
  • Run the following command in the project’s base directory to install all dependency packages.
 
cd examples
dotnet build

 

  1. Configure and run your first test:
{   
    "CLOUD" : {
      "momentumUser": "<momentum-suite-username>",
      "momentumToken": "<momentum-suite-access-key>",
       "momentumHost": "https://console.momentumsuite.com/gateway/wd/hub",
       "ios" : {
            "momentumApp": "ms://<hashed-app-id>",
            "momentumDeviceList": [9999]
        },
        "android" : {
          "momentumApp": "ms://<hashed-app-id>",
            "momentumDeviceList": [9998]
            }
    },
   
   "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 test_settings.json file within the array list.
AndroidiOS
            AppiumOptions caps = new AppiumOptions();
            Dictionary<string, object> momentumOptions = new Dictionary<string, object>();
            caps.AddAdditionalCapability("plarformName", "Android");
            caps.AddAdditionalCapability("appium:automationName", "UiAutomator2");
            caps.AddAdditionalCapability("appium:autoGrantPermissions", true);
            caps.AddAdditionalCapability("appium:language", "en");
            caps.AddAdditionalCapability("appium:locale", "en");
            caps.AddAdditionalCapability("appium:deviceName", "");
            caps.AddAdditionalCapability("appium:udid", "");
            caps.AddAdditionalCapability("appium:app", momentumApp);
            caps.AddAdditionalCapability("appium:fullReset", true);
            caps.AddAdditionalCapability("appium:noReset", false);
            momentumOptions.Add("user",momentumUser);
            momentumOptions.Add("token", momentumToken);
            momentumOptions.Add("gw", momentumDeviceId);
            caps.AddAdditionalCapability("momentum:options", momentumOptions);
            AppiumOptions caps = new AppiumOptions();
            Dictionary<string, object> momentumOptions = new Dictionary<string, object>();
            caps.AddAdditionalCapability("appium:automationName", "XCUITest");
            caps.AddAdditionalCapability("appium:autoAcceptAlerts", true);
            caps.AddAdditionalCapability("appium:language", "en");
            caps.AddAdditionalCapability("appium:locale", "en");
            caps.AddAdditionalCapability("appium:deviceName", "");
            caps.AddAdditionalCapability("appium:udid", "");
            caps.AddAdditionalCapability("appium:app", momentumApp);
            caps.AddAdditionalCapability("appium:fullReset", true);
            caps.AddAdditionalCapability("appium:noReset", false);
            caps.AddAdditionalCapability("appium:remoteDebugProxy", "gw+2000");
            momentumOptions.Add("user",momentumUser);
            momentumOptions.Add("token", momentumToken);
            momentumOptions.Add("gw", momentumDeviceId);
            caps.AddAdditionalCapability("momentum:options", momentumOptions);
  • Run the following command in the project’s base directory to run the Android getting started project :
cd examples
dotnet test --filter AndroidFirstTest

  • Run the following command in the project’s base directory to run the iOS getting started project :
cd examples
dotnet test --filter IOSFirstTest


All other available commands to start mobile testing:

AndroidiOS
dotnet test --filter AndroidLocalTest
dotnet test --filter AndroidFirstTest
dotnet test --filter IOSLocalTest
dotnet test --filter IOSFirstTest
  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.

cd examples
allure serve bin/Debug/netcoreapp3.1/allure-results

Related Posts
Leave a Reply

Your email address will not be published.