├── .DS_Store ├── .idea ├── .gitignore ├── compiler.xml ├── encodings.xml ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── README.md ├── pom.xml ├── src └── test │ └── java │ ├── vanilla_android.java │ └── vanilla_ios.java └── target ├── AppTesting-1.0-SNAPSHOT.jar ├── maven-archiver └── pom.properties ├── maven-status └── maven-compiler-plugin │ └── testCompile │ └── default-testCompile │ ├── createdFiles.lst │ └── inputFiles.lst └── test-classes ├── vanilla_android.class └── vanilla_ios.class /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himanshuseth004/java-appium-ip-geolocation/e699ba446131067f57b73f256039764615458715/.DS_Store -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to change IP geographic location in Java with Appium on [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=appium-java-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-java). 4 | 5 | # Steps: 6 | 7 | The following is an example on how to set geoLocation in the capabilities. You can make the change in the ```vanilla_android.java``` and ```vanilla_ios.java``` file: 8 | 9 | Below is the ```vanilla_android.java``` example shown: 10 | 11 | ```java 12 | public class vanilla_android { 13 | public static String userName = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Add username here 14 | : System.getenv("LT_USERNAME"); 15 | public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Add accessKey here 16 | : System.getenv("LT_ACCESS_KEY"); 17 | 18 | private static AppiumDriver driver; 19 | 20 | public static void main(String args[]) throws MalformedURLException, InterruptedException { 21 | 22 | try { 23 | DesiredCapabilities capabilities = new DesiredCapabilities(); 24 | capabilities.setCapability("deviceName", "Galaxy S20"); 25 | capabilities.setCapability("platformVersion", "11"); 26 | capabilities.setCapability("platformName", "Android"); 27 | capabilities.setCapability("isRealMobile", true); 28 | capabilities.setCapability("app", "lt://"); //Enter your app url 29 | capabilities.setCapability("deviceOrientation", "PORTRAIT"); 30 | capabilities.setCapability("build", "Java Vanilla - iOS"); 31 | capabilities.setCapability("name", "Sample Test Java"); 32 | capabilities.setCapability("console", true); 33 | capabilities.setCapability("network", false); 34 | capabilities.setCapability("visual", true); 35 | capabilities.setCapability("devicelog", true); 36 | 37 | //ADD GEOLOCATION BASED ON COUNTRY CODE 38 | capabilities.setCapability("geoLocation", "fr"); 39 | 40 | driver = new AppiumDriver(new URL("https://" +userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), capabilities); 41 | 42 | MobileElement color = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color")); 43 | color.click(); 44 | 45 | MobileElement text = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text")); 46 | text.click(); 47 | 48 | MobileElement toast = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast")); 49 | toast.click(); 50 | 51 | MobileElement notification = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/notification")); 52 | notification.click(); 53 | 54 | } catch (AssertionError a) { 55 | ((JavascriptExecutor) driver).executeScript("lambda-status=failed"); 56 | a.printStackTrace(); 57 | driver.quit(); 58 | } 59 | } 60 | } 61 | ``` 62 | 63 | ##Executing The Test 64 | 65 | Execute the following commands to install the required dependencies: 66 | 67 | ```mvn clean install``` 68 | The tests can be executed in the terminal using the following command: 69 | 70 | Android: 71 | 72 | ```bash 73 | mvn test -P android 74 | ``` 75 | 76 | iOS: 77 | 78 | ```bash 79 | mvn test -P ios 80 | ``` 81 | 82 | Info: 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. 83 | 84 | 85 | 86 | 87 | 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). 88 | 89 | ## Additional Links 90 | 91 | - [Advanced Configuration for Capabilities](https://www.lambdatest.com/support/docs/desired-capabilities-in-appium/) 92 | - [How to test locally hosted apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) 93 | - [How to integrate LambdaTest with CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/) 94 | 95 | ## Documentation & Resources :books: 96 | 97 | 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. 98 | 99 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 100 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 101 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=LT-appium-python) 102 | * [LambdaTest Community](http://community.lambdatest.com/) 103 | 104 | ## LambdaTest Community :busts_in_silhouette: 105 | 106 | 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 🌎 107 | 108 | ## What's New At LambdaTest ❓ 109 | 110 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) 111 | 112 | ## About LambdaTest 113 | 114 | [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. 115 | 116 | ### Features 117 | 118 | - Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. 119 | - Real-time cross browser testing on 3000+ environments. 120 | - Test on Real device cloud 121 | - Blazing fast test automation with HyperExecute 122 | - Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. 123 | - Smart Visual Regression Testing on cloud 124 | - 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. 125 | - Automated Screenshot testing across multiple browsers in a single click. 126 | - Local testing of web and mobile apps. 127 | - Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. 128 | - Geolocation testing of web and mobile apps across 53+ countries. 129 | - LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports 130 | 131 | [](https://accounts.lambdatest.com/register) 132 | 133 | ## We are here to help you :headphones: 134 | 135 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com) 136 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=appium-java-geoLocation) -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | App 7 | AppTesting 8 | 1.0-SNAPSHOT 9 | 10 | 11 | UTF-8 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | org.seleniumhq.selenium 20 | selenium-java 21 | 3.141.59 22 | 23 | 24 | 25 | 26 | com.github.lambdatest 27 | lambdatest-tunnel-binary 28 | 1.0.5 29 | 30 | 31 | 32 | 33 | io.github.bonigarcia 34 | webdrivermanager 35 | 4.3.1 36 | 37 | 38 | commons-io 39 | commons-io 40 | 2.11.0 41 | 42 | 43 | org.seleniumhq.selenium 44 | selenium-support 45 | 2.52.0 46 | 47 | 48 | io.appium 49 | java-client 50 | 7.6.0 51 | 52 | 53 | org.testng 54 | testng 55 | 6.14.3 56 | 57 | 58 | commons-lang 59 | commons-lang 60 | 2.6 61 | 62 | 63 | 64 | org.apache.commons 65 | commons-lang3 66 | 3.0 67 | 68 | 69 | 70 | info.cukes 71 | cucumber-java 72 | 1.2.5 73 | 74 | 75 | 76 | junit 77 | junit 78 | 4.12 79 | test 80 | 81 | 82 | org.json 83 | json 84 | 20160810 85 | 86 | 87 | org.seleniumhq.selenium 88 | selenium-remote-driver 89 | 3.141.59 90 | 91 | 92 | io.rest-assured 93 | rest-assured 94 | 4.3.0 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | org.apache.maven.plugins 103 | maven-surefire-plugin 104 | 2.22.2 105 | 106 | 107 | org.apache.maven.plugins 108 | maven-compiler-plugin 109 | 3.8.1 110 | 111 | 1.8 112 | 1.8 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | android 121 | 122 | 123 | 124 | org.codehaus.mojo 125 | exec-maven-plugin 126 | 1.1.1 127 | 128 | 129 | test 130 | 131 | java 132 | 133 | 134 | vanilla_android 135 | test 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | ios 146 | 147 | 148 | 149 | org.codehaus.mojo 150 | exec-maven-plugin 151 | 1.1.1 152 | 153 | 154 | test 155 | 156 | java 157 | 158 | 159 | vanilla_ios 160 | test 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /src/test/java/vanilla_android.java: -------------------------------------------------------------------------------- 1 | import io.appium.java_client.AppiumDriver; 2 | import io.appium.java_client.MobileBy; 3 | import io.appium.java_client.MobileElement; 4 | import org.openqa.selenium.JavascriptExecutor; 5 | import org.openqa.selenium.remote.DesiredCapabilities; 6 | import org.openqa.selenium.remote.RemoteWebDriver; 7 | import java.net.MalformedURLException; 8 | import java.net.URL; 9 | 10 | public class vanilla_android { 11 | public static String userName = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Add username here 12 | : System.getenv("LT_USERNAME"); 13 | public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Add accessKey here 14 | : System.getenv("LT_ACCESS_KEY"); 15 | 16 | private static AppiumDriver driver; 17 | 18 | public static void main(String args[]) throws MalformedURLException, InterruptedException { 19 | 20 | try { 21 | DesiredCapabilities capabilities = new DesiredCapabilities(); 22 | capabilities.setCapability("deviceName", "Galaxy S20"); 23 | capabilities.setCapability("platformVersion", "11"); 24 | capabilities.setCapability("platformName", "Android"); 25 | capabilities.setCapability("isRealMobile", true); 26 | capabilities.setCapability("app", "lt://"); //Enter your app url 27 | capabilities.setCapability("deviceOrientation", "PORTRAIT"); 28 | capabilities.setCapability("build", "Java Vanilla - Android"); 29 | capabilities.setCapability("name", "Sample Test Java"); 30 | capabilities.setCapability("console", true); 31 | capabilities.setCapability("visual", true); 32 | capabilities.setCapability("devicelog", true); 33 | 34 | //ADD GEOLOCATION BASED ON COUNTRY CODE 35 | capabilities.setCapability("geoLocation", "fr"); 36 | 37 | 38 | driver = new AppiumDriver(new URL("https://" +userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), capabilities); 39 | 40 | MobileElement color = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/color")); 41 | color.click(); 42 | 43 | MobileElement text = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/Text")); 44 | text.click(); 45 | 46 | MobileElement toast = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/toast")); 47 | toast.click(); 48 | 49 | MobileElement notification = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/notification")); 50 | notification.click(); 51 | 52 | MobileElement geo = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/geoLocation")); 53 | geo.click(); 54 | Thread.sleep(5000); 55 | 56 | MobileElement el3 = (MobileElement) driver.findElementByAccessibilityId("Home"); 57 | MobileElement browser = (MobileElement) driver.findElement(MobileBy.AccessibilityId("Browser")); 58 | browser.click(); 59 | 60 | MobileElement url = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/url")); 61 | url.sendKeys("https://www.lambdatest.com"); 62 | MobileElement find = (MobileElement) driver.findElement(MobileBy.id("com.lambdatest.proverbial:id/find")); 63 | find.click(); 64 | 65 | ((JavascriptExecutor) driver).executeScript("lambda-status=passed"); 66 | 67 | } catch (AssertionError a) { 68 | ((JavascriptExecutor) driver).executeScript("lambda-status=failed"); 69 | a.printStackTrace(); 70 | driver.quit(); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/vanilla_ios.java: -------------------------------------------------------------------------------- 1 | import io.appium.java_client.AppiumDriver; 2 | import io.appium.java_client.MobileBy; 3 | import io.appium.java_client.MobileElement; 4 | import io.appium.java_client.ios.IOSDriver; 5 | 6 | import org.openqa.selenium.JavascriptExecutor; 7 | import org.openqa.selenium.remote.DesiredCapabilities; 8 | import org.openqa.selenium.support.ui.ExpectedConditions; 9 | import org.openqa.selenium.support.ui.WebDriverWait; 10 | 11 | import java.net.URL; 12 | 13 | public class vanilla_ios { 14 | 15 | public static String userName = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" //Add username here 16 | : System.getenv("LT_USERNAME"); 17 | public static String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" //Add accessKey here 18 | : System.getenv("LT_ACCESS_KEY"); 19 | 20 | public static IOSDriver driver = null; 21 | 22 | public static void main(String[] args) throws Exception { 23 | 24 | try { 25 | DesiredCapabilities caps = new DesiredCapabilities(); 26 | caps.setCapability("platformVersion", "15"); 27 | caps.setCapability("deviceName", "iPhone 12"); 28 | caps.setCapability("isRealMobile", true); 29 | caps.setCapability("app", "lt://"); //Enter your app url 30 | caps.setCapability("platformName", "iOS"); 31 | caps.setCapability("build", "Java Vanilla - iOS"); 32 | caps.setCapability("name", "Sample Test Java"); 33 | caps.setCapability("devicelog", true); 34 | caps.setCapability("network", true); 35 | 36 | //ADD GEOLOCATION BASED ON COUNTRY CODE 37 | caps.setCapability("geoLocation", "fr"); 38 | 39 | 40 | driver = new IOSDriver(new URL("https://" + userName + ":" + accessKey + "@mobile-hub.lambdatest.com/wd/hub"), caps); 41 | 42 | Thread.sleep(2000); 43 | 44 | driver.findElement(MobileBy.id("color")).click(); 45 | Thread.sleep(1000); 46 | 47 | driver.findElement(MobileBy.id("Text")).click(); 48 | Thread.sleep(1000); 49 | 50 | driver.findElement(MobileBy.id("toast")).click(); 51 | Thread.sleep(1000); 52 | 53 | driver.findElement(MobileBy.id("notification")).click(); 54 | Thread.sleep(2000); 55 | 56 | driver.findElement(MobileBy.id("geoLocation")).click(); 57 | Thread.sleep(4000); 58 | driver.navigate().back(); 59 | Thread.sleep(1000); 60 | 61 | driver.findElement(MobileBy.id("speedTest")).click(); 62 | Thread.sleep(5000); 63 | driver.navigate().back(); 64 | 65 | MobileElement browser = (MobileElement) driver.findElementByAccessibilityId("Browser"); 66 | browser.click(); 67 | Thread.sleep(3000); 68 | 69 | WebDriverWait el7 = new WebDriverWait(driver, 30); 70 | el7.until(ExpectedConditions.elementToBeClickable(MobileBy.id("url"))); 71 | driver.findElementById("url").sendKeys("https://www.lambdatest.com/"); 72 | 73 | WebDriverWait el = new WebDriverWait(driver,90); 74 | MobileElement el4 = (MobileElement) driver.findElementByAccessibilityId("find"); 75 | el.until(ExpectedConditions.elementToBeClickable(el4)); 76 | el4.click(); 77 | el4.sendKeys("Lambdatest"); 78 | 79 | ((JavascriptExecutor) driver).executeScript("lambda-status=passed"); 80 | driver.quit(); 81 | 82 | } catch (Exception t) { 83 | ((JavascriptExecutor) driver).executeScript("lambda-status=failed"); 84 | t.printStackTrace(); 85 | driver.quit(); 86 | } 87 | } 88 | } 89 | 90 | -------------------------------------------------------------------------------- /target/AppTesting-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himanshuseth004/java-appium-ip-geolocation/e699ba446131067f57b73f256039764615458715/target/AppTesting-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /target/maven-archiver/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven 2 | #Wed Jun 22 23:23:12 IST 2022 3 | artifactId=AppTesting 4 | groupId=App 5 | version=1.0-SNAPSHOT 6 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | vanilla_ios.class 2 | vanilla_android.class 3 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Users/shantanuw/Desktop/LT-appium-java/src/test/java/vanilla_ios.java 2 | /Users/shantanuw/Desktop/LT-appium-java/src/test/java/vanilla_android.java 3 | -------------------------------------------------------------------------------- /target/test-classes/vanilla_android.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himanshuseth004/java-appium-ip-geolocation/e699ba446131067f57b73f256039764615458715/target/test-classes/vanilla_android.class -------------------------------------------------------------------------------- /target/test-classes/vanilla_ios.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/himanshuseth004/java-appium-ip-geolocation/e699ba446131067f57b73f256039764615458715/target/test-classes/vanilla_ios.class --------------------------------------------------------------------------------