How to use ShakesDevice class of io.appium.java_client.ios package

Best io.appium code snippet using io.appium.java_client.ios.ShakesDevice

Run io.appium automation tests on LambdaTest cloud grid

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

MobileDevice.java

Source: MobileDevice.java Github

copy
1package com.epam.jdi.light.mobile.elements.common;
2
3import io.appium.java_client.AppiumDriver;
4import io.appium.java_client.LocksDevice;
5import io.appium.java_client.MobileDriver;
6import io.appium.java_client.android.AndroidDriver;
7import io.appium.java_client.android.AuthenticatesByFinger;
8import io.appium.java_client.battery.BatteryInfo;
9import io.appium.java_client.ios.IOSDriver;
10import io.appium.java_client.ios.PerformsTouchID;
11import io.appium.java_client.ios.ShakesDevice;
12import org.openqa.selenium.DeviceRotation;
13import org.openqa.selenium.ScreenOrientation;
14import org.openqa.selenium.WebDriver;
15import org.openqa.selenium.html5.Location;
16
17import java.time.Duration;
18import java.util.function.Consumer;
19import java.util.function.Function;
20
21import static com.epam.jdi.light.common.Exceptions.exception;
22import static com.epam.jdi.light.driver.WebDriverFactory.getDriver;
23import static com.epam.jdi.light.mobile.MobileUtils.executeDriverMethod;
24
25public class MobileDevice {
26    public static void rotate(DeviceRotation rotation) {
27        executeDriverMethod(AppiumDriver.class, (AppiumDriver driver) -> driver.rotate(rotation));
28    }
29    public static DeviceRotation getRotation() {
30        return executeDriverMethod(AppiumDriver.class,
31                (Function<AppiumDriver, DeviceRotation>) AppiumDriver::rotation);
32    }
33    public static void rotate(ScreenOrientation orientation) {
34        executeDriverMethod(AppiumDriver.class, (AppiumDriver driver) -> driver.rotate(orientation));
35    }
36    public static ScreenOrientation getOrientation() {
37        return executeDriverMethod(AppiumDriver.class,
38                (Function<AppiumDriver, ScreenOrientation>) AppiumDriver::getOrientation);
39    }
40    public static void lockDevice() {
41        executeDriverMethod(LocksDevice.class, (Consumer<LocksDevice>) LocksDevice::lockDevice);
42    }
43    public static void lockDevice(Duration duration) {
44        executeDriverMethod(LocksDevice.class, (LocksDevice driver) ->  driver.lockDevice(duration));
45    }
46    public static void unlockDevice() {
47        executeDriverMethod(LocksDevice.class, LocksDevice::unlockDevice);
48    }
49    public static boolean isLocked() {
50        return executeDriverMethod(LocksDevice.class, LocksDevice::isDeviceLocked);
51    }
52    public static BatteryInfo getBatteryInfo() {
53        WebDriver driver = getDriver();
54        if (driver instanceof IOSDriver) {
55            return ((IOSDriver) driver).getBatteryInfo();
56        } else if (driver instanceof AndroidDriver) {
57            return ((AndroidDriver) driver).getBatteryInfo();
58        } else {
59            throw exception("This method is not supported by the driver. The driver needs to be the instance of either Ios or Android driver");
60        }
61    }
62    public static Location getLocation() {
63        return executeDriverMethod(AppiumDriver.class, (Function<AppiumDriver, Location>) AppiumDriver::location);
64    }
65    public static void setLocation(Location location) {
66        executeDriverMethod(AppiumDriver.class, (AppiumDriver driver) -> driver.setLocation(location));
67    }
68    public static String getDeviceTime() {
69        return executeDriverMethod(MobileDriver.class, (Function<MobileDriver, String>) MobileDriver::getDeviceTime);
70    }
71    public static String getDeviceTime(String format) {
72        return executeDriverMethod(MobileDriver.class, (MobileDriver driver) -> driver.getDeviceTime(format));
73    }
74
75    // the next methods are for IOS only
76    public static void shake() {
77        executeDriverMethod(ShakesDevice.class, ShakesDevice::shake);
78    }
79    public static void performTouchId(boolean match) {
80        executeDriverMethod(PerformsTouchID.class, (PerformsTouchID driver) -> driver.performTouchID(match));
81    }
82    public static void toggleTouchIDEnrollment(boolean enabled) {
83        executeDriverMethod(PerformsTouchID.class, (PerformsTouchID driver) -> driver.toggleTouchIDEnrollment(enabled));
84    }
85
86    // the next methods are for Android only
87    public static void fingerPrint(int fingerPrintId) {
88        executeDriverMethod(AuthenticatesByFinger.class, (AuthenticatesByFinger driver) -> driver.fingerPrint(fingerPrintId));
89    }
90}
91
Full Screen

IOSWebDriverStub.java

Source: IOSWebDriverStub.java Github

copy
1package net.thucydides.core.webdriver.stubs;
2
3import io.appium.java_client.FindsByIosClassChain;
4import io.appium.java_client.FindsByIosNSPredicate;
5import io.appium.java_client.HidesKeyboardWithKeyName;
6import io.appium.java_client.LocksDevice;
7import io.appium.java_client.ios.PerformsTouchID;
8import io.appium.java_client.ios.PushesFiles;
9import io.appium.java_client.ios.ShakesDevice;
10import org.openqa.selenium.By;
11import org.openqa.selenium.WebElement;
12import org.openqa.selenium.remote.Response;
13
14import java.util.*;
15
16public class IOSWebDriverStub extends WebDriverStub implements HidesKeyboardWithKeyName, ShakesDevice,
17        PerformsTouchID, FindsByIosNSPredicate, FindsByIosClassChain, PushesFiles, LocksDevice {
18
19    @Override
20    public void get(String s) {
21    }
22
23    @Override
24    public String getCurrentUrl() {
25        return "";
26    }
27
28    @Override
29    public String getTitle() {
30        return "";
31    }
32
33    @Override
34    public List<WebElement> findElements(By by) {
35        return new ArrayList<>();
36    }
37
38    @Override
39    public WebElement findElement(By by) {
40        return new WebElementFacadeStub();
41    }
42
43    @Override
44    public String getPageSource() {
45        return "";
46    }
47
48    @Override
49    public void close() {
50
51    }
52
53    @Override
54    public void quit() {
55
56    }
57
58    @Override
59    public Set<String> getWindowHandles() {
60        return new HashSet<>();
61    }
62
63    @Override
64    public String getWindowHandle() {
65        return "";
66    }
67
68    @Override
69    public TargetLocator switchTo() {
70        return new TargetLocatorStub(this);
71    }
72
73    @Override
74    public Navigation navigate() {
75        return new NavigationStub();
76    }
77
78    @Override
79    public Options manage() {
80        return new ManageStub();
81    }
82
83
84    @Override
85    public Response execute(String s, Map<String, ?> map) {
86        return new Response();
87    }
88
89    @Override
90    public Response execute(String s) {
91        return new Response();
92    }
93
94    @Override
95    public void hideKeyboard(String keyName) {
96
97    }
98
99    @Override
100    public void hideKeyboard(String strategy, String keyName) {
101
102    }
103
104    @Override
105    public void hideKeyboard() {
106
107    }
108
109    @Override
110    public WebElement findElement(String s, String s1) {
111        return new WebElementFacadeStub();
112    }
113
114    @Override
115    public List findElements(String s, String s1) {
116        return new ArrayList();
117    }
118
119//    @Override
120//    public WebElement findElementByIosUIAutomation(String using) {
121//        return new WebElementFacadeStub();
122//    }
123//
124//    @Override
125//    public List findElementsByIosUIAutomation(String using) {
126//        return new ArrayList();
127//    }
128
129    @Override
130    public void shake() {
131
132    }
133
134    void nativeWebTap(Boolean enabled) {
135
136    }
137
138}
139
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 methods in ShakesDevice

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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)