Skip to content

Commit 7cbdcd4

Browse files
author
Mykola Mokhnach
authored
Add an optional format argument to getDeviceTime and update the documentation (#939)
* Update device time getters * Update the docstring * Tune conditions
1 parent 9eca2e3 commit 7cbdcd4

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/main/java/io/appium/java_client/HasDeviceTime.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,31 @@
1818

1919
import static io.appium.java_client.MobileCommand.GET_DEVICE_TIME;
2020

21+
import com.google.common.collect.ImmutableMap;
22+
2123
import org.openqa.selenium.remote.Response;
2224

2325
public interface HasDeviceTime extends ExecutesMethod {
24-
/*
25-
Gets device date and time for both iOS(Supports only real device) and Android devices
26+
27+
/**
28+
* Gets device date and time for both iOS(host time is returned for simulators) and Android devices.
29+
*
30+
* @param format The set of format specifiers. Read
31+
* https://momentjs.com/docs/ to get the full list of supported
32+
* datetime format specifiers. The default format is
33+
* `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601
34+
* @return Device time string
35+
*/
36+
default String getDeviceTime(String format) {
37+
Response response = execute(GET_DEVICE_TIME, ImmutableMap.of("format", format));
38+
return response.getValue().toString();
39+
}
40+
41+
/**
42+
* Gets device date and time for both iOS(host time is returned for simulators) and Android devices.
43+
* The default format since Appium 1.8.2 is `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601.
44+
*
45+
* @return Device time string
2646
*/
2747
default String getDeviceTime() {
2848
Response response = execute(GET_DEVICE_TIME);

src/test/java/io/appium/java_client/android/AndroidDriverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public class AndroidDriverTest extends BaseAndroidTest {
118118

119119
@Test public void getDeviceTimeTest() {
120120
String time = driver.getDeviceTime();
121-
assertTrue(time.length() == 28);
121+
assertFalse(time.isEmpty());
122122
}
123123

124124
@Test public void isAppInstalledTest() {

src/test/java/io/appium/java_client/ios/IOSDriverTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030

3131
public class IOSDriverTest extends AppIOSTest {
3232

33-
//TODO There is no ability to check this function usibg simulators.
34-
// When CI will have been set up then this test will be returned
33+
@Test
3534
public void getDeviceTimeTest() {
3635
String time = driver.getDeviceTime();
37-
assertTrue(time.length() == 28);
36+
assertFalse(time.isEmpty());
3837
}
3938

4039
@Test public void resetTest() {

0 commit comments

Comments
 (0)