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 Behave, Lettuce, Pytest and Robot Framework on real Android/iOS devices on Momentum Suite. In this guide, you will learn how to test with pytest.
- Check requirements
- Create your account
- Upload your app
- Clone sample code
- Configure and run your first test
- View test execution results
- Check requirements:
- Python version 3.7+ (required by Appium Python Client v2.2 and pytest)
- 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.
- Create your account:
- You will need a Momentum Suite
user
andtoken
. 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.
- You will need a Momentum Suite
- 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.
- Upload your Android app (
- Clone sample code:
- Clone the pytest sample code from our GitHub repository.
git clone https://github.com/browserstack/python-appium-app-browserstack.git
- Run the following command in the project’s base directory to install all dependency packages.
pip3 install -r requirements.txt
- Configure and run your first test:
- Open for editing your test_settings.json file under the root directory.
{ "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 test_settings.json file within the array list.
AndroidiOS
desired_caps = { "platformName": "Android", "appium:automationName": "uiautomator2", "appium:app": cloudAndroidApp, "appium:autoGrantPermissions": True, "appium:language": "en", "appium:locale": "en", "appium:fullReset": True, "appium:noReset": False, "appium:deviceName": "", "appium:udid": "", "momentum:options": { "user": cloudUser, "token": cloudToken, "gw": cloudAndroidDeviceName, }, }
desired_caps = { "platformName": "iOS", "appium:automationName": "XCUITest", "appium:app": cloudIosApp, "appium:autoAcceptAlerts": True, "appium:language": "en", "appium:locale": "en", "appium:fullReset": True, "appium:noReset": False, "appium:deviceName": "", "appium:udid": "", "appium:remoteDebugProxy": "gw+2000", "momentum:options": { "user": cloudUser, "token": cloudToken, "gw": cloudIosDeviceName, }, }
- Run the following command in the project’s base directory to run the Android getting started project :
python3 -m pytest examples/getting_started/first_android_test.py --alluredir=allure_results
- Run the following command in the project’s base directory to run the iOS getting started project :
python3 -m pytest examples/getting_started/first_ios_test.py --alluredir=allure_results
All other available commands to start mobile testing:
AndroidiOS
python3 -m pytest examples/getting_started/first_android_test.py --alluredir=allure_results python3 -m pytest examples/local_test/local_android_test.py --alluredir=allure_results python3 -m pytest examples/pom_test/tests/pom_android_test.py --alluredir=allure_results
python3 -m pytest examples/getting_started/first_ios_test.py --alluredir=allure_results python3 -m pytest examples/local_test/local_ios_test.py --alluredir=allure_results python3 -m pytest examples/pom_test/tests/pom_ios_test.py --alluredir=allure_results
- 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