How to change IP geolocation in Real Devices with Appium PHP on LambdaTest cloud?

How to change IP geolocation in Real Devices with Appium PHP on LambdaTest cloud?

Hi Rebecca,

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.

The following is an example on how to set geoLocation in the capabilities:

```
php
    require __dir__.'/vendor/autoload.php';
    use Facebook\WebDriver\Remote\DesiredCapabilities;
    use Facebook\WebDriver\Remote\RemoteWebDriver;
    use Facebook\WebDriver\WebDriverBy;

    $caps = array(
        "app"=>"lt://", //Enter app_url here
        "deviceName" => "Galaxy S20",
        "platformName" => "Android",
        "platformVersion" => "10",
        "isRealMobile" => TRUE,
        "visual" => TRUE,
        "video" => TRUE,
        "name" => "Php - Android test",
        "build" => "Php Vanilla - Android",

        //ADD GEOLOCATION BASED ON COUNTRY CODE
        "geoLocation" => "fr" 

    );

    $username = getenv("LT_USERNAME") ? getenv("LT_USERNAME") : "username"; //Enter username here
    $accesskey = getenv("LT_ACCESS_KEY") ? getenv("LT_ACCESS_KEY") : "accesskey"; //Enter accesskey here

    $driver = RemoteWebDriver::create("https://$username:$accesskey@mobile-hub.lambdatest.com/wd/hub",$caps);

 try{
    $color_element = $driver->findElement(WebDriverBy::id('color'));
    $color_element->click();

    $text_element = $driver->findElement(WebDriverBy::id('Text'));
    $text_element->click();

    $toast_element = $driver->findElement(WebDriverBy::id('toast'));
    $toast_element->click();

    $notification_element = $driver->findElement(WebDriverBy::id('notification'));
    $notification_element->click();
    $driver->quit();

 } finally {
    $driver->quit();
 }

```

Here’s the GitHub repo for the same: https://github.com/saanvisavlani/appium-php-geolocation