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

Additional changes of the #473 #786

Merged
merged 5 commits into from
Dec 18, 2017
Merged
Changes from 1 commit
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
118 changes: 60 additions & 58 deletions src/test/java/io/appium/java_client/android/FingerPrintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.appium.java_client.android;

import static io.appium.java_client.MobileBy.AndroidUIAutomator;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.openqa.selenium.By.id;

import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
Expand All @@ -26,20 +28,21 @@
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;
private static AndroidDriver<AndroidElement> driver;

private static void initDriver() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability("appPackage", "com.android.settings");
capabilities.setCapability("appActivity", "Settings");
driver = new AndroidDriver<>(service.getUrl(), capabilities);
driver.manage().timeouts().implicitlyWait(15, SECONDS);
}

/**
* initialization.
Expand All @@ -62,77 +65,76 @@ public class FingerPrintTest {
}
}

private AndroidElement findElementByText(String text) {
return driver.findElements(id("android:id/title")).stream().filter(androidElement ->
text.equals(androidElement.getText())).findFirst()
.orElseThrow(() ->
new NoSuchElementException(String.format("There is no element with the text '%s'", text)));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I was so used to localization testing that my mind automatically blocked using text to find an element :)
using text is much better and easier in this case 👍


private void clickNext() {
driver.findElementById("com.android.settings:id/next_button").click();
}

private void clickOKInPopup() {
driver.findElementById("android:id/button1").click();
}

private void enterPasswordAndContinue() {
driver.findElementById("com.android.settings:id/password_entry")
.sendKeys("1234\n");
}

private void clickOnSecurity() {
driver.findElement(AndroidUIAutomator("new UiScrollable(new UiSelector()"
+ ".scrollable(true)).scrollIntoView("
+ "new UiSelector().text(\"Security\"));")).click();
}

/**
* 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();
initDriver();
clickOnSecurity();
findElementByText("Screen lock").click();
findElementByText("PIN").click();
enterPasswordAndContinue();
enterPasswordAndContinue();
clickNext();
}

/**
* 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();
@Test public void fingerPrintTest() {
findElementByText("Fingerprint").click();
clickNext();
enterPasswordAndContinue();
clickNext();

driver.fingerPrint(2);
try {
clickNext(driver);
driver.findElementById("com.android.settings:id/next_button").click();
Copy link
Member

Choose a reason for hiding this comment

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

Should be clickNext()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Will improve today.

} 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");
}
initDriver();
clickOnSecurity();

private void clickNext(AndroidDriver driver) throws InterruptedException {
driver.findElementById("com.android.settings:id/next_button").click();
}
findElementByText("Screen lock").click();

private void clickOKInPopup(AndroidDriver driver) throws InterruptedException {
driver.findElementById("android:id/button1").click();
enterPasswordAndContinue();
findElementByText("None").click();
clickOKInPopup();
driver.quit();
}
}
}