├── README.md ├── android.py └── ios.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-customName) using the Appium & Python Language 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 | from appium import webdriver 96 | from appium.webdriver.common.mobileby import MobileBy 97 | from selenium.webdriver.support.ui import WebDriverWait 98 | from selenium.webdriver.support import expected_conditions as EC 99 | import time 100 | import os 101 | 102 | desired_caps = { 103 | "deviceName":"iPhone 12", 104 | "platformName":"ios", 105 | "platformVersion":"14", 106 | "isRealMobile":True, 107 | 108 | #Enter the Custom_ID here that was used to upload your application 109 | #Example is shown here from the Example Upload mentioned above. 110 | 111 | "app":"Proverbial Android v1.56", 112 | 113 | "build":"Python Vanilla iOS", 114 | "name":"Sample Test - Python", 115 | "network":True, 116 | "visual":True, 117 | "video":True 118 | } 119 | 120 | def startingTest(): 121 | if os.environ.get("LT_USERNAME") is None: 122 | username = "username" #Enter LT username here if environment variables have not been added 123 | else: 124 | username = os.environ.get("LT_USERNAME") 125 | if os.environ.get("LT_ACCESS_KEY") is None: 126 | accesskey = "accesskey" #Enter LT accesskey here if environment variables have not been added 127 | else: 128 | accesskey = os.environ.get("LT_ACCESS_KEY") 129 | 130 | try: 131 | driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://"+username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") 132 | time.sleep(3) 133 | colorElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"color"))) 134 | colorElement.click() 135 | textElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"Text"))) 136 | textElement.click() 137 | toastElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"toast"))) 138 | toastElement.click() 139 | notification = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"notification"))) 140 | notification.click() 141 | 142 | driver.quit() 143 | except: 144 | driver.quit() 145 | 146 | startingTest() 147 | 148 | ``` 149 | 150 | ## Executing The Tests 151 | 152 | Run the following command in the directory where your project has been saved to execute your build. 153 | 154 | 155 | 156 | 157 | 158 | ```bash 159 | python3 ios.py 160 | ``` 161 | 162 | 163 | 164 | 165 | 166 | ```bash 167 | python3 android.py 168 | ``` 169 | 170 | 171 | 172 | 173 | 174 | 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). 175 | 176 | ## Additional Links 177 | 178 | - [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/) 179 | - [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) 180 | - [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/) 181 | 182 | ## Documentation & Resources :books: 183 | 184 | 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. 185 | 186 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 187 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 188 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 189 | * [LambdaTest Community](http://community.lambdatest.com/) 190 | 191 | ## LambdaTest Community :busts_in_silhouette: 192 | 193 | 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 🌎 194 | 195 | ## What's New At LambdaTest ❓ 196 | 197 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) 198 | 199 | ## About LambdaTest 200 | 201 | [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. 202 | 203 | ### Features 204 | 205 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. 206 | * Real-time cross browser testing on 3000+ environments. 207 | * Test on Real device cloud 208 | * Blazing fast test automation with HyperExecute 209 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. 210 | * Smart Visual Regression Testing on cloud 211 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. 212 | * Automated Screenshot testing across multiple browsers in a single click. 213 | * Local testing of web and mobile apps. 214 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. 215 | * Geolocation testing of web and mobile apps across 53+ countries. 216 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports 217 | 218 | [](https://accounts.lambdatest.com/register) 219 | 220 | ## We are here to help you :headphones: 221 | 222 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com) 223 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python-customName) 224 | -------------------------------------------------------------------------------- /android.py: -------------------------------------------------------------------------------- 1 | from appium import webdriver 2 | from appium.webdriver.common.mobileby import MobileBy 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | import time 6 | import os 7 | 8 | desired_caps = { 9 | "deviceName":"Galaxy S20", 10 | "platformName":"Android", 11 | "platformVersion":"10", 12 | 13 | #Enter the Custom_ID here that was used to upload your application 14 | 15 | "app":"ENTER_CUSTOM_ID_HERE", 16 | 17 | "isRealMobile":True, 18 | "build":"Python Vanilla Android", 19 | "name":"Sample Test - Python", 20 | "network":True, 21 | "visual":True, 22 | "video":True 23 | } 24 | 25 | def startingTest(): 26 | if os.environ.get("LT_USERNAME") is None: 27 | username = "username" #Enter LT username here if environment variables have not been added 28 | else: 29 | username = os.environ.get("LT_USERNAME") 30 | if os.environ.get("LT_ACCESS_KEY") is None: 31 | accesskey = "accesskey" #Enter LT accesskey here if environment variables have not been added 32 | else: 33 | accesskey = os.environ.get("LT_ACCESS_KEY") 34 | 35 | try: 36 | driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://"+username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") 37 | colorElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/color"))) 38 | colorElement.click() 39 | 40 | textElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/Text"))) 41 | textElement.click() 42 | 43 | toastElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/toast"))) 44 | toastElement.click() 45 | 46 | notification = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/notification"))) 47 | notification.click() 48 | 49 | driver.quit() 50 | except: 51 | driver.quit() 52 | 53 | startingTest() 54 | -------------------------------------------------------------------------------- /ios.py: -------------------------------------------------------------------------------- 1 | from appium import webdriver 2 | from appium.webdriver.common.mobileby import MobileBy 3 | from selenium.webdriver.support.ui import WebDriverWait 4 | from selenium.webdriver.support import expected_conditions as EC 5 | import time 6 | import os 7 | 8 | desired_caps = { 9 | "deviceName":"iPhone 12", 10 | "platformName":"ios", 11 | "platformVersion":"14", 12 | "isRealMobile":True, 13 | 14 | #Enter the Custom_ID here that was used to upload your application 15 | 16 | "app":"ENTER_CUSTOM_ID_HERE", 17 | 18 | "build":"Python Vanilla iOS", 19 | "name":"Sample Test - Python", 20 | "network":True, 21 | "visual":True, 22 | "video":True 23 | } 24 | 25 | def startingTest(): 26 | if os.environ.get("LT_USERNAME") is None: 27 | username = "username" #Enter LT username here if environment variables have not been added 28 | else: 29 | username = os.environ.get("LT_USERNAME") 30 | if os.environ.get("LT_ACCESS_KEY") is None: 31 | accesskey = "accesskey" #Enter LT accesskey here if environment variables have not been added 32 | else: 33 | accesskey = os.environ.get("LT_ACCESS_KEY") 34 | 35 | try: 36 | driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://"+username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") 37 | time.sleep(3) 38 | colorElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"color"))) 39 | colorElement.click() 40 | textElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"Text"))) 41 | textElement.click() 42 | toastElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"toast"))) 43 | toastElement.click() 44 | notification = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"notification"))) 45 | notification.click() 46 | 47 | driver.quit() 48 | except: 49 | driver.quit() 50 | 51 | startingTest() 52 | --------------------------------------------------------------------------------