Change device date and time on BrowserStack real devices
You can change the date or time on BrowserStack devices while running an appium test session to test functionalities such as timers, timed notifications or alerts, and more present in your app. App Automate supports this feature through an automated test script.
In this guide, you will learn about
- Supported functionalities on devices and OS
- How to set the device date and time via custom BrowserStack javascript executor
Supported functionalities on devices and OS
The following table lists the devices and OS versions on which different functionalities are currently supported:
OS | Devices | OS version | Functionality |
---|---|---|---|
iOS | iPhones and iPads | v13 and above | Change device time |
Android | Phones and tablets | v6 and above | Change device date and time |
Set the device date and time using custom BrowserStack executor
iOS
Set the action type as updateIosDeviceSettings
and provide the desired device time as input to the argument customTime
in the BrowserStack JavaScript executor to change the device time while running the test sessions.
The following table lists the allowed input values for customTime
argument:
Argument | Input Format | Allowed Values |
---|---|---|
customTime | HH:MM |
HH allowed values: 00 to 23 MM allowed values: 00 to 59 |
As an example, the following code snippet demonstrates how to use the BrowserStack JavaScript executor to change the device time to 14:05
:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {
\"action\":\"updateIosDeviceSettings\",
\"arguments\": {
\"customTime\" : \"14:05\"
}
}"
);
await driver.execute("browserstack_executor: {
\"action\":\"updateIosDeviceSettings\",
\"arguments\": {
\"customTime\" : \"14:05\"
}
}"
);
driver.execute_script("browserstack_executor: {
\"action\":\"updateIosDeviceSettings\",
\"arguments\": {
\"customTime\" : \"14:05\"
}
}"
);
caps["javascriptEnabled"] = "true" #include this capability for JavaScript executors to work
driver.execute_script("browserstack_executor: {
\"action\":\"updateIosDeviceSettings\",
\"arguments\": {
\"customTime\" : \"14:05\"
}
}"
);
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {
\"action\":\"updateIosDeviceSettings\",
\"arguments\": {
\"customTime\" : \"14:05\"
}
}"
);
Android
Set the action type as updateAndroidDeviceSettings
and provide the desired device date and time as input to the argument customDate
and customTime
respectively in the BrowserStack JavaScript executor to change the device date and time while running the test sessions.
The following table lists the allowed input values for customDate
and customTime
arguments:
Argument | Input Format | Allowed Values |
---|---|---|
customDate | HH:MM |
HH allowed values: 00 to 23 MM allowed values: 00 to 59 |
customTime | MMM DD YYYY |
MMM allowed values: Jan, Feb, Mar, Apr, Jun, Jul, Aug, Sep, Oct, Nov, Dec DD allowed values: 01 to 31 YYYY allowed values: 2015 to 2035 |
As an example, the following code snippet demonstrates how to use the BrowserStack JavaScript executor to change the device date to Sep 15 2023
and time to 14:05
:
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {
\"action\":\"updateAndroidDeviceSettings\",
\"arguments\": {
\"customDate\" : \"Sep 15 2023\",
\"customTime\" : \"14:05\"
}
}"
);
await driver.execute("browserstack_executor: {
\"action\":\"updateAndroidDeviceSettings\",
\"arguments\": {
\"customDate\" : \"Sep 15 2023\",
\"customTime\" : \"14:05\"
}
}"
);
driver.execute_script("browserstack_executor: {
\"action\":\"updateAndroidDeviceSettings\",
\"arguments\": {
\"customDate\" : \"Sep 15 2023\",
\"customTime\" : \"14:05\"
}
}"
);
caps["javascriptEnabled"] = "true" #include this capability for JavaScript executors to work
driver.execute_script("browserstack_executor: {
\"action\":\"updateAndroidDeviceSettings\",
\"arguments\": {
\"customDate\" : \"Sep 15 2023\",
\"customTime\" : \"14:05\"
}
}"
);
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {
\"action\":\"updateAndroidDeviceSettings\",
\"arguments\": {
\"customDate\" : \"Sep 15 2023\",
\"customTime\" : \"14:05\"
}
}"
);
- Bring your app under test to the foreground using the Appium activateApp command after running the javascript executor command.
- Retrieve device date & time from the Browserstack mobile device by using the Appium getDeviceTime command.
Related topics
Check this page for a list of various JavaScript Executors that BrowserStack offers.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!