├── README.md ├── features ├── AndroidFeature.feature └── IOSFeature.feature ├── pavement.py ├── requirements.txt └── steps ├── AndroidStepDef.py ├── IosStepDef.py └── appConfig.py /README.md: -------------------------------------------------------------------------------- 1 | # How to install apps in Real Devices using Custom App ID on [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python-behave-customName) using the Appium Python Behave Framework 2 | 3 | While performing app automation testing with Appium on LambdaTest Grid, you might face a scenario where the APP ID generated by you is lost/confusing since it looks something like this - ```lt://APP12430338390303038292```. 4 | You can easily change this to something readable like this - ```Proverbial Android v1.56```. 5 | Let's quickly learn how to achieve this. 6 | ### Setting Up Your Authentication 7 | 8 | Make sure you have your LambdaTest credentials with you to run test automation scripts on LambdaTest. To obtain your access credentials, [purchase a plan](https://billing.lambdatest.com/billing/plans) or access the [Automation Dashboard](https://appautomation.lambdatest.com/). 9 | 10 | Set LambdaTest `Username` and `Access Key` in environment variables. 11 | 12 | **For Linux/macOS:** 13 | 14 | ```js 15 | export LT_USERNAME="YOUR_LAMBDATEST_USERNAME" \ 16 | export LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY" 17 | ``` 18 | 19 | **For Windows:** 20 | 21 | ```js 22 | set LT_USERNAME="YOUR_LAMBDATEST_USERNAME" ` 23 | set LT_ACCESS_KEY="YOUR_LAMBDATEST_ACCESS_KEY" 24 | ``` 25 | 26 | ### Upload Your Application 27 | 28 | Upload your **_iOS_** application (.ipa file) or **_android_** application (.apk file) to the LambdaTest servers using our **REST API**. You need to provide your **Username** and **AccessKey** in the format `Username:AccessKey` in the **cURL** command for authentication. Make sure to add the path of the **appFile** in the cURL request. Here is an example cURL request to upload your app using our REST API: 29 | 30 | **Using App File:** 31 | 32 | **Linux/macOS:** 33 | 34 | ```js 35 | curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ 36 | --location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ 37 | --form 'name="Android_App"' \ 38 | --form 'appFile=@"/Users/macuser/Downloads/proverbial_android.apk"' \ 39 | --form 'custom_id="ENTER_CUSTOM_ID_HERE"' 40 | ``` 41 | 42 | **Windows:** 43 | 44 | ```js 45 | curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" -X POST "https://manual-api.lambdatest.com/app/upload/realDevice" -F "appFile=@"C:\Users\varunkumarb\Downloads\proverbial_android.apk"" -F "custom_id=ENTER_CUSTOM_ID_HERE" 46 | ``` 47 | 48 | **Using App URL:** 49 | 50 | **Linux/macOS:** 51 | 52 | ```js 53 | curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ 54 | --location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ 55 | --form 'name="Android_App"' \ 56 | --form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"' \ 57 | --form 'custom_id="ENTER_CUSTOM_ID_HERE"' 58 | ``` 59 | 60 | **For Windows:** 61 | 62 | ```js 63 | curl --location --request POST "https://manual-api.lambdatest.com/app/upload/realDevice" -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" --header "Content-Type: application/x-www-form-urlencoded" --data-urlencode "url=https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk" --data-urlencode "name=teest" --data-urlencode "custom_id=ENTER_CUSTOM_ID_HERE" 64 | ``` 65 | 66 | **Example using a Custom App ID** 67 | 68 | ```js 69 | curl -u "YOUR_LAMBDATEST_USERNAME:YOUR_LAMBDATEST_ACCESS_KEY" \ 70 | --location --request POST 'https://manual-api.lambdatest.com/app/upload/realDevice' \ 71 | --form 'name="Android_App"' \ 72 | --form 'url="https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk"' \ 73 | --form 'custom_id="Proverbial Android v1.56"' 74 | ``` 75 | 76 | **Tip:** 77 | 78 | - If you do not have any **.apk** or **.ipa** file, you can run your sample tests on LambdaTest by using our sample :link: [Android app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_android.apk) or sample :link: [iOS app](https://prod-mobile-artefacts.lambdatest.com/assets/docs/proverbial_ios.ipa). 79 | - Response of above cURL will be a **JSON** object containing the `App URL` of the format - and will be used in the next step. 80 | - Alternatively you can also use the `Custom ID` that you defined in your own words. 81 | 82 | ## Run Your First Test 83 | 84 | Once you are done with the above-mentioned steps, you can initiate your first Python test on LambdaTest. 85 | 86 | ### Configuring Your Test Capabilities 87 | 88 | You can update your custom capabilities in test scripts. In this sample project, we are passing platform name, platform version, device name and app url (generated earlier) along with other capabilities like build name and test name via capabilities object. The capabilities object in the sample code are defined as: 89 | 90 | 91 | 92 | 93 | 94 | ``` 95 | app_android_desired_caps = { 96 | "deviceName":"Galaxy S20", 97 | "platformName":"Android", 98 | "platformVersion":"10", 99 | "build":"Python Behave - Android", 100 | "name":"Sample Test Android", 101 | "isRealMobile":True, 102 | "network":True, 103 | "visual":True, 104 | "video":True, 105 | 106 | 107 | #Enter the Custom_ID here that was used to upload your application 108 | 109 | "app":"ENTER_CUSTOM_ID_HERE", 110 | } 111 | 112 | app_ios_desired_caps = { 113 | "deviceName":"iPhone 12", 114 | "platformName":"ios", 115 | "platformVersion":"14", 116 | "build":"Python Behave - iOS", 117 | "name":"Sample Test iOS", 118 | "isRealMobile":True, 119 | "network":True, 120 | "visual":True, 121 | "video":True, 122 | 123 | #Enter the Custom_ID here that was used to upload your application 124 | 125 | "app":"ENTER_CUSTOM_ID_HERE", 126 | } 127 | ``` 128 | 129 | ## Executing The Tests 130 | 131 | Run the following command in the directory where your project has been saved to execute your build. 132 | 133 | 134 | 135 | 136 | 137 | ```bash 138 | python3 ios.py 139 | ``` 140 | 141 | 142 | 143 | 144 | 145 | ```bash 146 | python3 android.py 147 | ``` 148 | 149 | 150 | 151 | 152 | 153 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on the [LambdaTest App Automation Dashboard](https://appautomation.lambdatest.com/build). 154 | 155 | ## Additional Links 156 | 157 | - [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/) 158 | - [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) 159 | - [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/) 160 | 161 | ## Documentation & Resources :books: 162 | 163 | Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. 164 | 165 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 166 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 167 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 168 | * [LambdaTest Community](http://community.lambdatest.com/) 169 | 170 | ## LambdaTest Community :busts_in_silhouette: 171 | 172 | The [LambdaTest Community](https://community.lambdatest.com/) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 173 | 174 | ## What's New At LambdaTest ❓ 175 | 176 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) 177 | 178 | ## About LambdaTest 179 | 180 | [LambdaTest](https://www.lambdatest.com) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. 181 | 182 | ### Features 183 | 184 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. 185 | * Real-time cross browser testing on 3000+ environments. 186 | * Test on Real device cloud 187 | * Blazing fast test automation with HyperExecute 188 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. 189 | * Smart Visual Regression Testing on cloud 190 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. 191 | * Automated Screenshot testing across multiple browsers in a single click. 192 | * Local testing of web and mobile apps. 193 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. 194 | * Geolocation testing of web and mobile apps across 53+ countries. 195 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports 196 | 197 | [](https://accounts.lambdatest.com/register) 198 | 199 | ## We are here to help you :headphones: 200 | 201 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com) 202 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python-behave-customName) -------------------------------------------------------------------------------- /features/AndroidFeature.feature: -------------------------------------------------------------------------------- 1 | Feature: Android real device app and web automation 2 | 3 | @androidApp 4 | Scenario: Android real device app automation 5 | Given Start the android app automation test -------------------------------------------------------------------------------- /features/IOSFeature.feature: -------------------------------------------------------------------------------- 1 | Feature: IOS real device web and app automation 2 | 3 | @iosApp 4 | Scenario: Android real device app automation 5 | Given Start the ios app automation test -------------------------------------------------------------------------------- /pavement.py: -------------------------------------------------------------------------------- 1 | from paver.easy import * 2 | from paver.setuputils import setup 3 | import multiprocessing 4 | import json 5 | import os 6 | 7 | setup( 8 | name="python-behave-proverbial", 9 | packages=['features'], 10 | version="1.0.0", 11 | url="https://www.lambdatest.com/", 12 | author="Lambdatest", 13 | description=("Behave Integration with Lambdatest"), 14 | license="MIT", 15 | author_email="support@lambdatest.com" 16 | ) 17 | 18 | 19 | def run_behave_test(env, index=0): 20 | """ 21 | runs the individual test 22 | :param env: 23 | :param index: 24 | :return: 25 | """ 26 | if env == "jenkins": 27 | sh('INDEX=%s env=%s behave features/test.feature ' % (index, env,)) 28 | else: 29 | sh('INDEX=%s env=%s behave features/test.feature ' % (index, env,)) 30 | 31 | 32 | @task 33 | @consume_args 34 | def run(args): 35 | """ 36 | runs the behave test 37 | :return: 38 | """ 39 | env = args[0] if len(args) > 0 else "" 40 | jobs = [] 41 | pool = get_pool_size() 42 | for i in range(pool): 43 | p = multiprocessing.Process(target=run_behave_test, args=(env, i,)) 44 | jobs.append(p) 45 | p.start() 46 | 47 | 48 | def get_pool_size(): 49 | """ 50 | sets the number of parallel test 51 | :return: 52 | """ 53 | if "LT_BROWSERS" in os.environ: 54 | CONFIG = json.loads(os.environ["LT_BROWSERS"]) 55 | pool = len(CONFIG) 56 | else: 57 | json_file = "config/config.json" 58 | with open(json_file) as data_file: 59 | CONFIG = json.load(data_file) 60 | pool = len(CONFIG) 61 | return pool 62 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Paver==1.3.4 2 | selenium 3 | behave==1.2.6 4 | Appium-Python-Client -------------------------------------------------------------------------------- /steps/AndroidStepDef.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | path = os.getcwd() 4 | sys.path.append(os.path.abspath(os.path.join(path, os.pardir))) 5 | from time import time 6 | from behave import given 7 | from appium import webdriver 8 | import appConfig as appConf 9 | from appium.webdriver.common.mobileby import MobileBy 10 | from selenium.webdriver.support.ui import WebDriverWait 11 | from selenium.webdriver.support import expected_conditions as EC 12 | 13 | @given("Start the android app automation test") 14 | def startAndroidAppAutomationTest(self): 15 | if os.environ.get("LT_USERNAME") is None: 16 | username = "username" #Enter LT username here if environment variables have not been added 17 | else: 18 | username = os.environ.get("LT_USERNAME") 19 | if os.environ.get("LT_ACCESS_KEY") is None: 20 | accesskey = "accesskey" #Enter LT accesskey here if environment variables have not been added 21 | else: 22 | accesskey = os.environ.get("LT_ACCESS_KEY") 23 | 24 | driver = webdriver.Remote( 25 | command_executor="https://"+username+":"+accesskey+"@beta-hub.lambdatest.com/wd/hub", 26 | desired_capabilities=appConf.app_android_desired_caps 27 | ) 28 | try: 29 | colorElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/color"))) 30 | colorElement.click() 31 | 32 | textElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/Text"))) 33 | textElement.click() 34 | 35 | toastElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/toast"))) 36 | toastElement.click() 37 | 38 | notification = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/notification"))) 39 | notification.click() 40 | 41 | driver.quit() 42 | except: 43 | driver.quit() 44 | -------------------------------------------------------------------------------- /steps/IosStepDef.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | path = os.getcwd() 4 | sys.path.append(os.path.abspath(os.path.join(path, os.pardir))) 5 | import appConfig as appConf 6 | from behave import given 7 | from appium import webdriver 8 | import time 9 | from appium.webdriver.common.mobileby import MobileBy 10 | from selenium.webdriver.support.ui import WebDriverWait 11 | from selenium.webdriver.support import expected_conditions as EC 12 | 13 | @given("Start the ios app automation test") 14 | def startIOSAppAutomationTest(self): 15 | if os.environ.get("LT_USERNAME") is None: 16 | username = "username" #Enter LT username here if environment variables have not been added 17 | else: 18 | username = os.environ.get("LT_USERNAME") 19 | if os.environ.get("LT_ACCESS_KEY") is None: 20 | accesskey = "accesskey" #Enter LT accesskey here if environment variables have not been added 21 | else: 22 | accesskey = os.environ.get("LT_ACCESS_KEY") 23 | 24 | driver = webdriver.Remote( 25 | command_executor="https://"+username+":"+accesskey+"@beta-hub.lambdatest.com/wd/hub", 26 | desired_capabilities=appConf.app_ios_desired_caps 27 | ) 28 | try: 29 | colorElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"color"))) 30 | colorElement.click() 31 | 32 | textElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"Text"))) 33 | textElement.click() 34 | 35 | toastElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"toast"))) 36 | toastElement.click() 37 | 38 | notification = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"notification"))) 39 | notification.click() 40 | time.sleep(3) 41 | 42 | driver.quit() 43 | except: 44 | driver.quit() 45 | -------------------------------------------------------------------------------- /steps/appConfig.py: -------------------------------------------------------------------------------- 1 | app_android_desired_caps = { 2 | "deviceName":"Galaxy S20", 3 | "platformName":"Android", 4 | "platformVersion":"10", 5 | "build":"Python Behave - Android", 6 | "name":"Sample Test Android", 7 | "isRealMobile":True, 8 | "network":True, 9 | "visual":True, 10 | "video":True, 11 | 12 | 13 | #Enter the Custom_ID here that was used to upload your application 14 | 15 | "app":"ENTER_CUSTOM_ID_HERE", 16 | } 17 | 18 | app_ios_desired_caps = { 19 | "deviceName":"iPhone 12", 20 | "platformName":"ios", 21 | "platformVersion":"14", 22 | "build":"Python Behave - iOS", 23 | "name":"Sample Test iOS", 24 | "isRealMobile":True, 25 | "network":True, 26 | "visual":True, 27 | "video":True, 28 | 29 | #Enter the Custom_ID here that was used to upload your application 30 | 31 | "app":"ENTER_CUSTOM_ID_HERE", 32 | } 33 | --------------------------------------------------------------------------------