Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TouchID Implementation [iOS Sim Only] #509

Merged
merged 21 commits into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
622 changes: 311 additions & 311 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ dependencies {
compile 'commons-validator:commons-validator:1.5.1'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'commons-io:commons-io:2.5'
compile 'com.google.code.gson:gson:2.6.2'
compile 'org.springframework:spring-context:4.3.2.RELEASE'
compile 'org.aspectj:aspectjweaver:1.8.9'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public static <T extends Object> T execute(ExecutesMethod executesMethod, String
return handleResponse(executesMethod.execute(command));
}

private static <T extends Object> T handleResponse(Response responce) {
if (responce != null) {
return (T) responce.getValue();
private static <T extends Object> T handleResponse(Response response) {
if (response != null) {
return (T) response.getValue();
}
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MobileCommand {
protected static final String GET_SESSION = "getSession";
//iOS
protected static final String SHAKE = "shake";
protected static final String TOUCH_ID = "touchId";
//Android
protected static final String CURRENT_ACTIVITY = "currentActivity";
protected static final String END_TEST_COVERAGE = "endTestCoverage";
Expand Down Expand Up @@ -94,6 +95,7 @@ private static Map<String, CommandInfo> createCommandRepository() {
result.put(GET_SESSION,getC("/session/:sessionId/"));
//iOS
result.put(SHAKE, postC("/session/:sessionId/appium/device/shake"));
result.put(TOUCH_ID, postC("/session/:sessionId/appium/simulator/touch_id"));
//Android
result.put(CURRENT_ACTIVITY,
getC("/session/:sessionId/appium/device/current_activity"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
public class IOSDriver<T extends WebElement>
extends AppiumDriver<T>
implements IOSDeviceActionShortcuts,
FindsByIosUIAutomation<T>, LocksIOSDevice {
FindsByIosUIAutomation<T>, LocksIOSDevice, PerformsTouchID {

private static final String IOS_PLATFORM = MobilePlatform.IOS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,15 @@ public class IOSMobileCommandHelper extends MobileCommand {
return new AbstractMap.SimpleEntry<>(
SHAKE, ImmutableMap.<String, Object>of());
}

/**
* This method forms a {@link java.util.Map} of parameters for the touchId simulator
*
* @param match If true, simulates a successful fingerprint scan. If false, simulates a failed fingerprint scan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc should end with a period everywhere.

*
*/
public static Map.Entry<String, Map<String, ?>> touchIdCommand(boolean match) {
return new AbstractMap.SimpleEntry<>(
TOUCH_ID, prepareArguments("match", match));
}
}
34 changes: 34 additions & 0 deletions src/main/java/io/appium/java_client/ios/PerformsTouchID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.java_client.ios;

import static io.appium.java_client.ios.IOSMobileCommandHelper.touchIdCommand;

import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;

public interface PerformsTouchID extends ExecutesMethod {

/**
* Simulate touchId event
*
* @param match If true, simulates a successful fingerprint scan. If false, simulates a failed fingerprint scan.
*/
default void performTouchID(boolean match) {
CommandExecutionHelper.execute(this, touchIdCommand(match));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class IOSGesturesTest extends BaseIOSTest {


@Test public void tapTest() {
driver.findElementById("IntegerA").sendKeys("2");
driver.findElementById("IntegerB").sendKeys("4");
driver.findElementById("IntegerA").sendKeys("2");
driver.findElementById("IntegerB").sendKeys("4");

MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton");
driver.tap(2, e, 2000);
Expand Down
16 changes: 14 additions & 2 deletions src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.appium.java_client.ios;


import static org.junit.Assert.assertEquals;

import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.IOSMobileCapabilityType;
Expand All @@ -31,8 +34,6 @@

import java.io.File;

import static org.junit.Assert.assertEquals;

public class XCUIAutomationTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpgraham Can you add some tests here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the test. It doesn't do any assertions because there isn't anything to check, it just calls the methods to verify that there aren't any exceptions.


protected static IOSDriver<MobileElement> driver;
Expand Down Expand Up @@ -91,4 +92,15 @@ public class XCUIAutomationTest {
driver.rotate(landscapeLeftRotation);
assertEquals(driver.rotation(), landscapeLeftRotation);
}

@Test public void testTouchId() {
try {
driver.performTouchID(true);
driver.performTouchID(false);
assertEquals(true, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual Usecase of API touchID is to unlock or sign in to any application using touchID. Since we dont have our test app built with any registration or sign in feature, we cannot use that scenario.

Otherwise Can we lock the simulator and unlock the simulator using driver.touchID(true).Ideal case this should be working fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So test scenario should be something like,

   try {
            driver.lockDevice(2);
            driver.touchId(true);
        } catch (Exception e) {
            assertTrue(false);
        }

} catch (Exception e) {
assertEquals(true, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpgraham I think it is more senseful to throw an exception.
Otherwice we have a risk to produce and invalid build or to not react to server changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test should throw the exception.

At least you can do that

try {
//do something
//assert the result
} catch (Exception e) {
    throw e;
} finally {
//attemt to stabilize the simulator
//or something else
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpgraham Can you update tests here as suggested please?

}

}
}