Skip to content

Commit 3e9c949

Browse files
dpgrahamTikhomirovSergey
authored andcommitted
TouchID Implementation [iOS Sim Only] (appium#509)
* Fixed broken tests Tests were failing because of an indentation problem in IOSGesturesTest.java and because a static import in XCUIAutomationTest.java was coming after the rest of the imports instead of before * Added 'touch_id' endpoint (See https://support.apple.com/en-ca/HT201371 for description of the Touch ID feature) This endpoint simulates the TouchID feature. * removed obselete gson-2.6.2 dependency. (appium#507) * Fix documentation * Fix documentation * Don't commit 'touchID()' This will be added post release * Added touchId test This test only executes the driver.touchId method, it doesn't do any assertions. Just verifies that it doesn't throw any exceptions. * Added assertion to keep codacy happy * Fixed broken tests Tests were failing because of an indentation problem in IOSGesturesTest.java and because a static import in XCUIAutomationTest.java was coming after the rest of the imports instead of before * Added 'touch_id' endpoint (See https://support.apple.com/en-ca/HT201371 for description of the Touch ID feature) This endpoint simulates the TouchID feature. * Fix documentation * Fix documentation * Don't commit 'touchID()' This will be added post release * Added touchId test This test only executes the driver.touchId method, it doesn't do any assertions. Just verifies that it doesn't throw any exceptions. * Added assertion to keep codacy happy * Moved touchID into new file -Moved touchID out of IOSDeviceActionShorcuts and into PerformsTouchID -Made IOSDriver implement PerformsTouchID -Fixed typo that I noticed in CommandExecutionHelper -Fixed linting errors * Fixed conflicts * Update IOSMobileCommandHelper.java * Throws exception instead of bogus assertion
1 parent 9f214cd commit 3e9c949

File tree

8 files changed

+378
-319
lines changed

8 files changed

+378
-319
lines changed

README.md

Lines changed: 311 additions & 311 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public static <T extends Object> T execute(ExecutesMethod executesMethod, String
3131
return handleResponse(executesMethod.execute(command));
3232
}
3333

34-
private static <T extends Object> T handleResponse(Response responce) {
35-
if (responce != null) {
36-
return (T) responce.getValue();
34+
private static <T extends Object> T handleResponse(Response response) {
35+
if (response != null) {
36+
return (T) response.getValue();
3737
}
3838
return null;
3939
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class MobileCommand {
5151
protected static final String GET_SESSION = "getSession";
5252
//iOS
5353
protected static final String SHAKE = "shake";
54+
protected static final String TOUCH_ID = "touchId";
5455
//Android
5556
protected static final String CURRENT_ACTIVITY = "currentActivity";
5657
protected static final String END_TEST_COVERAGE = "endTestCoverage";
@@ -94,6 +95,7 @@ private static Map<String, CommandInfo> createCommandRepository() {
9495
result.put(GET_SESSION,getC("/session/:sessionId/"));
9596
//iOS
9697
result.put(SHAKE, postC("/session/:sessionId/appium/device/shake"));
98+
result.put(TOUCH_ID, postC("/session/:sessionId/appium/simulator/touch_id"));
9799
//Android
98100
result.put(CURRENT_ACTIVITY,
99101
getC("/session/:sessionId/appium/device/current_activity"));

src/main/java/io/appium/java_client/ios/IOSDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
public class IOSDriver<T extends WebElement>
5151
extends AppiumDriver<T>
5252
implements IOSDeviceActionShortcuts,
53-
FindsByIosUIAutomation<T>, LocksIOSDevice {
53+
FindsByIosUIAutomation<T>, LocksIOSDevice, PerformsTouchID {
5454

5555
private static final String IOS_PLATFORM = MobilePlatform.IOS;
5656

src/main/java/io/appium/java_client/ios/IOSMobileCommandHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,15 @@ public class IOSMobileCommandHelper extends MobileCommand {
8181
return new AbstractMap.SimpleEntry<>(
8282
SHAKE, ImmutableMap.<String, Object>of());
8383
}
84+
85+
/**
86+
* This method forms a {@link java.util.Map} of parameters for the touchId simulator.
87+
*
88+
* @param match If true, simulates a successful fingerprint scan. If false, simulates a failed fingerprint scan.
89+
*
90+
*/
91+
public static Map.Entry<String, Map<String, ?>> touchIdCommand(boolean match) {
92+
return new AbstractMap.SimpleEntry<>(
93+
TOUCH_ID, prepareArguments("match", match));
94+
}
8495
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
17+
package io.appium.java_client.ios;
18+
19+
import static io.appium.java_client.ios.IOSMobileCommandHelper.touchIdCommand;
20+
21+
import io.appium.java_client.CommandExecutionHelper;
22+
import io.appium.java_client.ExecutesMethod;
23+
24+
public interface PerformsTouchID extends ExecutesMethod {
25+
26+
/**
27+
* Simulate touchId event
28+
*
29+
* @param match If true, simulates a successful fingerprint scan. If false, simulates a failed fingerprint scan.
30+
*/
31+
default void performTouchID(boolean match) {
32+
CommandExecutionHelper.execute(this, touchIdCommand(match));
33+
}
34+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class IOSGesturesTest extends BaseIOSTest {
2626

2727

2828
@Test public void tapTest() {
29-
driver.findElementById("IntegerA").sendKeys("2");
30-
driver.findElementById("IntegerB").sendKeys("4");
29+
driver.findElementById("IntegerA").sendKeys("2");
30+
driver.findElementById("IntegerB").sendKeys("4");
3131

3232
MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
3333
driver.tap(2, e, 2000);

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package io.appium.java_client.ios;
1818

19+
20+
import static org.junit.Assert.assertEquals;
21+
1922
import io.appium.java_client.MobileElement;
2023
import io.appium.java_client.remote.AutomationName;
2124
import io.appium.java_client.remote.IOSMobileCapabilityType;
@@ -31,8 +34,6 @@
3134

3235
import java.io.File;
3336

34-
import static org.junit.Assert.assertEquals;
35-
3637
public class XCUIAutomationTest {
3738

3839
protected static IOSDriver<MobileElement> driver;
@@ -91,4 +92,15 @@ public class XCUIAutomationTest {
9192
driver.rotate(landscapeLeftRotation);
9293
assertEquals(driver.rotation(), landscapeLeftRotation);
9394
}
95+
96+
@Test public void testTouchId() {
97+
try {
98+
driver.performTouchID(true);
99+
driver.performTouchID(false);
100+
assertEquals(true, true);
101+
} catch (Exception e) {
102+
throw e;
103+
}
104+
105+
}
94106
}

0 commit comments

Comments
 (0)