App & Browser Testing Made Easy

Give your users a seamless experience by testing on 3000+ real devices and browsers. Don't compromise with emulators and simulators

Home Guide How to change Time Zones for Mobile App Testing using Appium

How to change Time Zones for Mobile App Testing using Appium

By Apeksha Gupta, Community Contributor -

Often influential brands, and businesses with mobile apps want to expand their wings at the global level to international outreach customers and maximize profit.

Releasing apps globally helps companies establish the business and also helps people in different regions and countries to have access to those apps, but it needs an ample amount of testing too to mitigate any possible bugs and issues. The same mobile app in a different region might need different levels of security and feature testing.

Need For App Testing in a Different Timezone

A mobile app is often released in different versions for different regions according to the people and business requirements. Even security threats and privacy levels differ with geolocation. In such scenarios, thorough geolocation testing is necessary for all regions where it is planned to be rolled out. To perform such testing, testers would require changing the subsequent location and time zone in the mobile device.

Apps can be tested manually or through automation in different time zones, like in Appium. Testing apps in various geo locations and different devices manually is cumbersome as to execute such testing; testers need to change the location manually in mobile devices.

How to Test Time Zones for Mobile App using Automation

In automation testing, the default geolocation setting needs to be changed in Appium, and the same can be done speedily by using a one-liner function to change the required location in Appium.

BrowserStack enables the user to set a custom Timezone on any BrowserStack mobile device. Custom Timezone can be set using Browserstack Appium capability browserstack.timezone and users can choose any of BrowserStack’s supported timezones.

Prerequisites to Test Time Zones in Appium

  1.  Appium desktop client
  2. JDK
  3. Development IDE/Eclipse

Steps to Change Time Zones For Mobile App Testing Using Appium

Ensure that you have the Appium setup and testing dependencies configured on your system.

  1. Create a new java project.
  2. Create a package and a class
  3. Add all required capabilities
  4. Function to scroll down and take action

Code to Change Time Zone using Appium

package testing;
import java.net.URL;
import java.util.List;
import java.util.function.Function;
import java.net.MalformedURLException;
import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.ScreenOrientation;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

public class Timezone {

public static void main(String[] args) throws MalformedURLException, InterruptedException {

DesiredCapabilities caps = new DesiredCapabilities();

// Set your access credentials
caps.setCapability("browserstack.user”, <user-name>);
caps.setCapability("browserstack.key", <access-key>);

// Set URL of the application under test
caps.setCapability("app", "Browserstack generated URL for the test app uploaded");
// Specify device and os_version for testing
caps.setCapability("device", "Samsung Galaxy A52");
caps.setCapability("os_version", "11.0");

// Set other BrowserStack capabilities
caps.setCapability("project", "First Java Project");
caps.setCapability("build", "browserstack-build-1");
caps.setCapability("name", "first_test");
// set desired location to change timezone
caps.setCapability("browserstack.timezone", "Kolkata"); // time zones available for automation testing using Browserstack capability
// Initialise the remote Webdriver using BrowserStack remote URL
// and desired capabilities defined above
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(
new URL("http://hub.browserstack.com/wd/hub"), caps);

//Get device timezone using deviceInfo command
driver.executeScript("mobile:deviceInfo");

//Returns device time as per device's Timezone
String time = driver.getDeviceTime();
System.out.println("time: "+ time);
System.out.println("test completed");

// Invoke driver.quit() after the test to close the driver session.
driver.quit();

}
}

Test Result

Timezone KolkataTimezone Kolkata

Timezone New YorkTimezone New York

By using the above Appium capability, provided by Browserstack, timezone can be set to any region/location easily worldwide depending on user’s requirement and use case.

In case, user is looking to test their website or apps on different browsers and devices, BrowserStack offers 3000+ real browsers and devices for manual and automation testing. QAs can test Android or iOS apps on thousands of real mobile devices, both latest and legacy. They can integrate seamlessly with the BrowserStack cloud via numerous testing frameworks – Appium, Espresso, XCUITest, or EarlGrey.

Try BrowserStack Now

Tags
Appium

Featured Articles

How to scroll down to an element in Appium

Top Appium Commands every Developer must know

Curated for all your Testing Needs

Actionable Insights, Tips, & Tutorials delivered in your Inbox
By subscribing , you agree to our Privacy Policy.
thank you illustration

Thank you for Subscribing!

Expect a curated list of guides shortly.