-
-
Notifications
You must be signed in to change notification settings - Fork 755
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
Additional changes of the #473 #786
Merged
TikhomirovSergey
merged 5 commits into
appium:master
from
TikhomirovSergey:alizelzele-finger-print
Dec 18, 2017
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8946c1
add finger print command to android Driver
alizelzele 48d703c
Merge branch 'finger-print' of https://github.com/alizelzele/java-cli…
TikhomirovSergey 0a3f463
Additional changes of the #473:
TikhomirovSergey 2585bba
Additional changes of the #473: improvements of FingerPrintTest
TikhomirovSergey eb4116f
Additional changes of the #473: improvements of FingerPrintTest
TikhomirovSergey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/io/appium/java_client/android/AuthenticatesByFinger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.appium.java_client.android; | ||
|
||
import static io.appium.java_client.android.AndroidMobileCommandHelper.fingerPrintCommand; | ||
|
||
import io.appium.java_client.CommandExecutionHelper; | ||
import io.appium.java_client.ExecutesMethod; | ||
|
||
public interface AuthenticatesByFinger extends ExecutesMethod { | ||
|
||
/** | ||
* Authenticate users by using their finger print scans on supported emulators. | ||
* | ||
* @param fingerPrintId finger prints stored in Android Keystore system (from 1 to 10) | ||
*/ | ||
default void fingerPrint(int fingerPrintId) { | ||
CommandExecutionHelper.execute(this, fingerPrintCommand(fingerPrintId)); | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
src/test/java/io/appium/java_client/android/FingerPrintTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* 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.android; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
|
||
import io.appium.java_client.remote.MobileCapabilityType; | ||
import io.appium.java_client.service.local.AppiumDriverLocalService; | ||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.NoSuchElementException; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
|
||
/** | ||
* It is necessary to make this test passing | ||
* - emulator API Level 23 Nexus device | ||
* - perform 'adb emu finger touch' 1 on Windows | ||
*/ | ||
public class FingerPrintTest { | ||
|
||
private static final String PASSWORD_INPUT_ID = "com.android.settings:id/password_entry"; | ||
private static final String FIRST_IN_LIST_XPATH = "//android.widget.ListView[1]/android.widget.LinearLayout[1]"; | ||
private static AppiumDriverLocalService service; | ||
|
||
/** | ||
* initialization. | ||
*/ | ||
@BeforeClass public static void beforeClass() { | ||
service = AppiumDriverLocalService.buildDefaultService(); | ||
service.start(); | ||
|
||
if (service == null || !service.isRunning()) { | ||
throw new ExceptionInInitializerError("An appium server node is not started!"); | ||
} | ||
} | ||
|
||
/** | ||
* finishing. | ||
*/ | ||
@AfterClass public static void afterClass() { | ||
if (service != null) { | ||
service.stop(); | ||
} | ||
} | ||
|
||
/** | ||
* enable system security which is required for finger print activation. | ||
*/ | ||
@Before public void before() throws Exception { | ||
final AndroidDriver driver = getAndroidDriver("ChooseLockGeneric"); | ||
// clicking the pin lock mode | ||
driver.findElement(By.xpath("//android.widget.LinearLayout[4]")).click(); | ||
try { | ||
// line below will throw exception if secure startup window is popped up | ||
driver.findElementById(PASSWORD_INPUT_ID); | ||
} catch (NoSuchElementException e) { | ||
// in secure startup window | ||
driver.findElementById("com.android.settings:id/encrypt_require_password").click(); | ||
SECONDS.sleep(2); | ||
clickOKInPopup(driver); | ||
clickNext(driver); | ||
} | ||
enterPasswordAndContinue(driver); | ||
enterPasswordAndContinue(driver); | ||
clickNext(driver); | ||
driver.quit(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather move driver create/quit into before/after each method |
||
} | ||
|
||
/** | ||
* add a new finger print to security. | ||
*/ | ||
@Test public void pressKeyCodeTest() throws InterruptedException { | ||
final AndroidDriver driver = getAndroidDriver(".fingerprint.FingerprintSettings"); | ||
enterPasswordAndContinue(driver); | ||
// click add fingerprint | ||
driver.findElementByXPath(FIRST_IN_LIST_XPATH).click(); | ||
driver.fingerPrint(2); | ||
try { | ||
clickNext(driver); | ||
} catch (Exception e) { | ||
Assert.fail("fingerprint command fail to execute"); | ||
} finally { | ||
driver.quit(); | ||
} | ||
} | ||
|
||
/** | ||
* disabling pin lock mode. | ||
*/ | ||
@After public void after() throws InterruptedException { | ||
final AndroidDriver driver = getAndroidDriver("ChooseLockGeneric"); | ||
enterPasswordAndContinue(driver); | ||
driver.findElementByXPath(FIRST_IN_LIST_XPATH).click(); | ||
clickOKInPopup(driver); | ||
driver.quit(); | ||
} | ||
|
||
private static AndroidDriver getAndroidDriver(String activity) { | ||
DesiredCapabilities capabilities = new DesiredCapabilities(); | ||
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); | ||
capabilities.setCapability("appPackage", "com.android.settings"); | ||
capabilities.setCapability("appActivity", activity); | ||
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(service.getUrl(), capabilities); | ||
driver.manage().timeouts().implicitlyWait(15, SECONDS); | ||
return driver; | ||
} | ||
|
||
private void enterPasswordAndContinue(AndroidDriver driver) throws InterruptedException { | ||
driver.findElementById(PASSWORD_INPUT_ID).sendKeys("1234\n"); | ||
} | ||
|
||
private void clickNext(AndroidDriver driver) throws InterruptedException { | ||
driver.findElementById("com.android.settings:id/next_button").click(); | ||
} | ||
|
||
private void clickOKInPopup(AndroidDriver driver) throws InterruptedException { | ||
driver.findElementById("android:id/button1").click(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service cannot be
null
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mykola-mokhnach it was copied from BaseAndroidTest and for sure it can not be null here :)