How to use getDeviceTime method of io.appium.java_client.HasDeviceTime class

Best io.appium code snippet using io.appium.java_client.HasDeviceTime.getDeviceTime

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

HasDeviceTime.java

Source: HasDeviceTime.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client;
18
19import static io.appium.java_client.MobileCommand.GET_DEVICE_TIME;
20
21import com.google.common.collect.ImmutableList;
22import com.google.common.collect.ImmutableMap;
23
24import org.openqa.selenium.remote.DriverCommand;
25import org.openqa.selenium.remote.Response;
26
27import java.util.Map;
28
29public interface HasDeviceTime extends ExecutesMethod {
30
31    /**
32     * Gets device date and time for both iOS(host time is returned for simulators) and Android devices.
33     *
34     * @param format The set of format specifiers. Read
35     *               https://momentjs.com/docs/ to get the full list of supported
36     *               datetime format specifiers. The default format is
37     *               `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601
38     * @since Appium 1.18
39     * @return Device time string
40     */
41    default String getDeviceTime(String format) {
42        Map<String, ?> params = ImmutableMap.of(
43                "script", "mobile: getDeviceTime",
44                "args", ImmutableList.of(ImmutableMap.of("format", format))
45        );
46        Response response = execute(DriverCommand.EXECUTE_SCRIPT, params);
47        return response.getValue().toString();
48    }
49
50    /**
51     * Gets device date and time for both iOS(host time is returned for simulators) and Android devices.
52     * The default format since Appium 1.8.2 is `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601.
53     *
54     * @return Device time string
55     */
56    default String getDeviceTime() {
57        Response response = execute(GET_DEVICE_TIME);
58        return response.getValue().toString();
59    }
60}
61
Full Screen

DeviceActionShortcuts.java

Source: DeviceActionShortcuts.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client;
18
19import static io.appium.java_client.MobileCommand.GET_DEVICE_TIME;
20import static io.appium.java_client.MobileCommand.HIDE_KEYBOARD;
21
22import org.openqa.selenium.remote.Response;
23
24@Deprecated
25/**
26 * This interface is deprecated and won't be supported anymore.
27 * Please use {@link HasDeviceTime} and {@link HidesKeyboard} API instead.
28 */
29public interface DeviceActionShortcuts extends ExecutesMethod {
30
31    /**
32     * Hides the keyboard if it is showing.
33     * On iOS, there are multiple strategies for hiding the keyboard.
34     * Defaults to the "tapOutside" strategy (taps outside the keyboard).
35     * Switch to using hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done") if this doesn't work.
36     */
37    default void hideKeyboard() {
38        execute(HIDE_KEYBOARD);
39    }
40
41    /*
42        Gets device date and time for both iOS(Supports only real device) and Android devices
43     */
44    default String getDeviceTime() {
45        Response response = execute(GET_DEVICE_TIME);
46        return response.getValue().toString();
47    }
48
49}
50
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in HasDeviceTime

Trigger getDeviceTime code on LambdaTest Cloud Grid

Execute automation tests with getDeviceTime on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)