├── ios.py ├── android.py └── README.md /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 | "app":"lt://", #Enter app_url here 14 | "build":"Python Vanilla iOS", 15 | "name":"Sample Test - Python", 16 | "network":True, 17 | "visual":True, 18 | "video":True, 19 | "geoLocation":"fr" 20 | } 21 | 22 | def startingTest(): 23 | if os.environ.get("LT_USERNAME") is None: 24 | username = "username" #Enter LT username here if environment variables have not been added 25 | else: 26 | username = os.environ.get("LT_USERNAME") 27 | if os.environ.get("LT_ACCESS_KEY") is None: 28 | accesskey = "accesskey" #Enter LT accesskey here if environment variables have not been added 29 | else: 30 | accesskey = os.environ.get("LT_ACCESS_KEY") 31 | 32 | try: 33 | driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://"+username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") 34 | time.sleep(3) 35 | colorElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"color"))) 36 | colorElement.click() 37 | textElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"Text"))) 38 | textElement.click() 39 | toastElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"toast"))) 40 | toastElement.click() 41 | notification = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"notification"))) 42 | notification.click() 43 | time.sleep(3) 44 | geolocation = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"geoLocation"))) 45 | geolocation.click() 46 | time.sleep(5) 47 | driver.back() 48 | home = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"Home"))) 49 | home.click() 50 | speedTest = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"speedTest"))) 51 | speedTest.click() 52 | time.sleep(5) 53 | driver.back() 54 | browser = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"Browser"))) 55 | browser.click() 56 | url = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID,"url"))) 57 | url.send_keys("https://www.lambdatest.com") 58 | find = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBsy.ACCESSIBILITY_ID,"find"))) 59 | find.click() 60 | driver.quit() 61 | except: 62 | driver.quit() 63 | 64 | startingTest() 65 | -------------------------------------------------------------------------------- /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 | "app":"lt://", #Enter app_url here 13 | "isRealMobile":True, 14 | "build":"Python Vanilla Android", 15 | "name":"Sample Test - Python", 16 | "network":True, 17 | "visual":True, 18 | "video":True, 19 | "geoLocation":"fr" 20 | } 21 | 22 | def startingTest(): 23 | if os.environ.get("LT_USERNAME") is None: 24 | username = "username" #Enter LT username here if environment variables have not been added 25 | else: 26 | username = os.environ.get("LT_USERNAME") 27 | if os.environ.get("LT_ACCESS_KEY") is None: 28 | accesskey = "accesskey" #Enter LT accesskey here if environment variables have not been added 29 | else: 30 | accesskey = os.environ.get("LT_ACCESS_KEY") 31 | 32 | try: 33 | driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://"+username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") 34 | colorElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/color"))) 35 | colorElement.click() 36 | 37 | textElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/Text"))) 38 | textElement.click() 39 | 40 | toastElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/toast"))) 41 | toastElement.click() 42 | 43 | notification = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/notification"))) 44 | notification.click() 45 | 46 | geolocation = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/geoLocation"))) 47 | geolocation.click() 48 | time.sleep(5) 49 | 50 | driver.back() 51 | 52 | home = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/buttonPage"))) 53 | home.click() 54 | 55 | speedTest = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/speedTest"))) 56 | speedTest.click() 57 | time.sleep(5) 58 | 59 | driver.back() 60 | 61 | browser = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/webview"))) 62 | browser.click() 63 | 64 | url = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/url"))) 65 | url.send_keys("https://www.lambdatest.com") 66 | 67 | find = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/find"))) 68 | find.click() 69 | driver.quit() 70 | except: 71 | driver.quit() 72 | 73 | startingTest() 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to change IP geographic location in Python with Appium on on [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=appium-python-geoLocation) 2 | 3 | While performing app automation testing with appium on LambdaTest Grid, you may face a scenario where you would like to simulate location of a specific country. You can easily do that by using the lambdatest capability "GeoLocation" and refer the 2-letter country code in the automation script. You can refer to sample test repo [here](https://github.com/LambdaTest/LT-appium-python) 4 | 5 | # Steps: 6 | 7 | The following is an example on how to set geoLocation in the capabilities. 8 | 9 | ``` 10 | from appium import webdriver 11 | from appium.webdriver.common.mobileby import MobileBy 12 | from selenium.webdriver.support.ui import WebDriverWait 13 | from selenium.webdriver.support import expected_conditions as EC 14 | import time 15 | import os 16 | 17 | desired_caps = { 18 | "deviceName":"Galaxy S20", 19 | "platformName":"Android", 20 | "platformVersion":"10", 21 | "app":"lt://", #Enter app_url here 22 | "isRealMobile":True, 23 | "build":"Python Vanilla Android", 24 | "name":"Sample Test - Python", 25 | "network":True, 26 | "visual":True, 27 | "video":True, 28 | 29 | #ADD GEOLOCATION BASED ON COUNTRY CODE 30 | "geoLocation":"fr" 31 | 32 | } 33 | 34 | def startingTest(): 35 | if os.environ.get("LT_USERNAME") is None: 36 | username = "username" #Enter LT username here if environment variables have not been added 37 | else: 38 | username = os.environ.get("LT_USERNAME") 39 | if os.environ.get("LT_ACCESS_KEY") is None: 40 | accesskey = "accesskey" #Enter LT accesskey here if environment variables have not been added 41 | else: 42 | accesskey = os.environ.get("LT_ACCESS_KEY") 43 | 44 | try: 45 | driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://"+username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") 46 | colorElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/color"))) 47 | colorElement.click() 48 | 49 | textElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/Text"))) 50 | textElement.click() 51 | 52 | toastElement = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/toast"))) 53 | toastElement.click() 54 | 55 | notification = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/notification"))) 56 | notification.click() 57 | 58 | geolocation = WebDriverWait(driver,20).until(EC.element_to_be_clickable((MobileBy.ID,"com.lambdatest.proverbial:id/geoLocation"))) 59 | geolocation.click() 60 | time.sleep(5) 61 | 62 | driver.quit() 63 | except: 64 | driver.quit() 65 | 66 | startingTest() 67 | 68 | ``` 69 | 70 | ## Run your test 71 | 72 | ```bash 73 | python3 android.py 74 | ``` 75 | 76 | 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). 77 | 78 | ## Additional Links 79 | 80 | - [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/) 81 | - [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) 82 | - [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/) 83 | 84 | ## Documentation & Resources :books: 85 | 86 | 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. 87 | 88 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 89 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 90 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 91 | * [LambdaTest Community](http://community.lambdatest.com/) 92 | 93 | ## LambdaTest Community :busts_in_silhouette: 94 | 95 | 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 🌎 96 | 97 | ## What's New At LambdaTest ❓ 98 | 99 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) 100 | 101 | ## About LambdaTest 102 | 103 | [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. 104 | 105 | ### Features 106 | 107 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. 108 | * Real-time cross browser testing on 3000+ environments. 109 | * Test on Real device cloud 110 | * Blazing fast test automation with HyperExecute 111 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. 112 | * Smart Visual Regression Testing on cloud 113 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. 114 | * Automated Screenshot testing across multiple browsers in a single click. 115 | * Local testing of web and mobile apps. 116 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. 117 | * Geolocation testing of web and mobile apps across 53+ countries. 118 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports 119 | 120 | [](https://accounts.lambdatest.com/register) 121 | 122 | ## We are here to help you :headphones: 123 | 124 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com) 125 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=appium-python-geolocation) 126 | --------------------------------------------------------------------------------