Test in different time zones (Android)
Change the Android device time zone through the Settings app, by region or by UTC offset, so you can test time-dependent features in any zone.
Features that depend on the time of day, such as delivery windows, opening hours, countdowns, or "today" and "yesterday" labels, can behave differently depending on the user's time zone. A test that passes on your laptop in London can fail on a device that is set to New York, or the other way round.
Locally, an emulator matches your machine timezone by default. In Maestro Cloud, devices start in a fixed zone (see Default device timezones). Maestro doesn't drive an app, it drives the whole device, so on Android we can drive a change in the device settings.
Credits
This approach was inspired by the team at GlossGenius, who needed to test how their app handles daylight saving time changes.
The workflow
The time zone setting is a few screens deep in Settings, and the picker it opens depends on how the current zone was chosen. The Flows in this recipe handle that for you:
Open the Settings app and go to System > Date & time.
Turn off Set automatically, so you can pick the time zone yourself.
Open the time zone picker and switch it to the mode you need: by region, or by UTC offset.
Choose the zone.
Choose a Flow based on what your test needs:
By region, when your app shows local times. The zone follows daylight saving time, just as a user's phone does.
By UTC offset, when you need a fixed offset that doesn't change during the year. The offset list only has whole hours, so you can't use it for zones such as India (GMT+05:30).
Both Flows were tested on Android 14-16 (API 34-36), on local emulators and on Maestro Cloud. Other Android versions may name the screens slightly differently.
1. Set the time zone by region
REGION is the country as Settings lists it, such as Japan, United States, or Canada. CITY is the city Settings names for the zone, such as Los Angeles, Toronto, or Vancouver. For a country with more than one time zone, the Flow uses it to pick the zone from a list of cities.
Always pass REGION and CITY together, even for a country with a single time zone. The Flow ends by checking that the time zone shows CITY, such as Tokyo for Japan.
2. Set a fixed UTC offset
OFFSET is the entry as the Select UTC offset list shows it, such as GMT-05:00 or GMT+09:00.
Interacting with a system app takes a few precautions that your own app's Flows don't need:
The time zone row is greyed out until automatic time zone is off. Rather than reading the state of the Set automatically switch, the Flows check whether the row that starts with
GMTis disabled. This works whatever the switch's position on screen.Settings remembers how the current zone was picked. A device whose zone was picked by region opens the region picker, and one whose zone was picked by UTC offset opens the offset list. Maestro Cloud Android devices start on UTC, picked by offset. The
whenconditions switch modes through the More options menu only when needed, so the same Flow works on a fresh emulator and on Cloud.speed: 80makes the first scroll fast. System is near the bottom of Settings. A higher speed makes each swipe so short that Android treats it as a tap and opens whichever row is under it.The offset you see isn't the zone ID. Picking
GMT-05:00sets the zoneEtc/GMT+5, because those IDs reverse the sign. This matters only if you check the zone outside the Settings app, for example withadb shell getprop persist.sys.timezone.
3. Implementation
The time zone is a device setting, so the device keeps it after the test. Set it at the start of every Flow that depends on it, rather than relying on an earlier Flow. Call the Flow as a subflow, then launch your app, so it starts in the new zone:
launchApp restarts your app if it was already running, so it reads the new time zone.
To run either Flow on its own, for example to set up a device before a test run:
Because REGION, CITY, and OFFSET use the ${NAME || "default"} form, the Flows use their defaults when run on their own, and the values you pass when you call them from another Flow or with -e. A plain value in the subflow's env header would replace the values you pass in.
Related content
Explore these pages to learn more about the concepts used in this recipe:
Parameters and constants: Learn how default values let a subflow run standalone or as part of a larger suite.
Conditions: Review how the
whenparameter lets one Flow cope with different starting states.App locales and device timezones: Check the default time zones of Maestro Cloud devices.
launchApp: Review the options for starting and restarting your app.
Last updated