How do I change IP geographic location in TestNG with Appium on LambdaTest cloud?
Hi Alex,
In order to change IP geographic location in TestNG with Appium on LambdaTest cloud, you can refer to these following steps. You can refer to the sample test repo:
The following is an example on how to set geoLocation in the capabilities.
import io.appium.java_client.AppiumDriver;
import org.testng.annotations.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileElement;
import java.net.URL;
public class AndroidApp {
String userName = System.getenv("LT_USERNAME") == null ?
"username" : System.getenv("LT_USERNAME"); //Enter your username here
String accessKey = System.getenv("LT_ACCESS_KEY") == null ?
"accessKey" : System.getenv("LT_ACCESS_KEY"); //Enter your accessKey here
public String gridURL = "@mobile-hub.lambdatest.com/wd/hub";
AppiumDriver driver;
@Test
@org.testng.annotations.Parameters(value = {"device", "version", "platform"})
public void AndroidApp1() {
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("build","Enter_your_build_name"); //Enter your build name here
capabilities.setCapability("name","Enter_your_test_name"); //Enter your test name here
capabilities.setCapability("deviceName", "Galaxy S21 5G");
capabilities.setCapability("platformVersion","12");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("isRealMobile", true);
capabilities.setCapability("app", "lt://"); //Enter your app url here
//ADD GEOLOCATION BASED ON COUNTRY CODE
capabilities.setCapability("geoLocation", "fr");
String hub = "https://" + userName + ":" + accessKey + gridURL;
driver = new AppiumDriver(new URL(hub), capabilities);
MobileElement color = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/color");
color.click();
MobileElement text = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/Text");
text.click();
MobileElement toast = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/toast");
toast.click();
MobileElement notification = (MobileElement) driver.findElementById("com.lambdatest.proverbial:id/notification");
notification.click();
Thread.sleep(2000);
driver.quit();
} catch (Exception e) {
e.printStackTrace();
driver.quit();
}
}
}
Here’s the GitHub repo for the same: GitHub - himanshuseth004/testng-appium-ip-geolocation: Change IP geographic location in TestNG with Appium on LambdaTest cloud.