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 8 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.

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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.DeviceActionShortcuts;
Expand Down Expand Up @@ -56,5 +57,14 @@ default void hideKeyboard(String strategy, String keyName) {
default void shake() {
CommandExecutionHelper.execute(this, shakeCommand());
}

Copy link
Contributor

@TikhomirovSergey TikhomirovSergey Nov 10, 2016

Choose a reason for hiding this comment

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

@dpgraham

I am against the adding to the IOSDeviceActionShortcuts. This interface is going to be deprecated. Please take a look at this working branch. IOSDeviceActionShortcuts is going to be deprecated.

It is better to add such interface:

package io.appium.java_client.ios;

public interface ChecksTouchId extends ExecutesMethod {

    /**
    * Simulate touchId event
    *
    * @param match If true, simulates a successful fingerprint scan. If false, simulates a failed fingerprint scan
    */     
    default void touchId(boolean match) {
        CommandExecutionHelper.execute(this, touchIdCommand(match));
    }
}

and make IOSDriver implement it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the input Sergey. I made the change.

/**
* Simulate touchId event
*
* @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.

If i'm not wrong, this will fail as per google style each doc line should end with a period.

*/
default void touchId(boolean match) {
Copy link
Member

@SrinivasanTarget SrinivasanTarget Nov 8, 2016

Choose a reason for hiding this comment

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

Can you add in doc as it is Simulator only?

CommandExecutionHelper.execute(this, touchIdCommand(match));
}

}
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));
}
}
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
15 changes: 13 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,14 @@ public class XCUIAutomationTest {
driver.rotate(landscapeLeftRotation);
assertEquals(driver.rotation(), landscapeLeftRotation);
}

@Test public void testTouchId() {
try {
driver.touchId(true);
driver.touchId(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?

}
}
}