uiautomatorがパスワードEditTextを選択することは可能ですか?android:hintプロパティで他のEditTextビューを見つけるのに問題はありませんが、uiautomatorviewerはすべてのパスワードフィールドをNAFとして表示します。パスワードフィールドの内容の説明を設定しようとしましたが、それも機能しませんでした。
それが不可能な場合、テスターが手動でパスワードを入力するためのタイムアウトをどのように設定しますか?
uiautomatorがパスワードEditTextを選択することは可能ですか?android:hintプロパティで他のEditTextビューを見つけるのに問題はありませんが、uiautomatorviewerはすべてのパスワードフィールドをNAFとして表示します。パスワードフィールドの内容の説明を設定しようとしましたが、それも機能しませんでした。
それが不可能な場合、テスターが手動でパスワードを入力するためのタイムアウトをどのように設定しますか?
APIv16でも同じ問題が発生しました。今日、私はv17(Android 4.2)でスクリプトを試しましたが、それは魅力のように機能しました。の最初のバージョンにuiautomator
はいくつかの大きなバグがあるようです。
これが私のコードです:
// click the admin button
new UiObject(new UiSelector().text("admin")).click();
// set pwd text
new UiObject(new UiSelector().description("pwdEditText")).setText("admin");
// click login button
new UiObject(new UiSelector().description("loginButton")).click();
の中にレンダリングされたWebページ内のテキストフィールドにプログラムで入力する必要がある場合など、sView
にがない場合があります。すなわちResourceId
WebView
// Fetch the EditText within the iOrder Webpage.
final UiObject lUiObject = UiDevice.getInstance(getInstrumentation()).findObject(new UiSelector().className(EditText.class).textContains("Enter Loyalty Code"));
このような場合、クラスを使用して;UiSelector
を動的に検索する必要があります。ただし、返されたメソッドと互換性がないEditText
ことがわかります。Matcher<View>
onView(with(...))
を使用する場合、以下のアプローチを使用して、プログラムで偽のキーを押すことへの参照をUiSelector
利用できます。UiDevice
/* Declare the KeyCodeMap. */
private static final KeyCharacterMap MAP_KEYCODE = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
/** Simulates typing within a UiObject. The typed text is appended to the Object. */
private final void type(final UiObject pUiObject, final String pString, final boolean pIsSimulateTyping, final boolean pIsClearField) throws Exception {
// Fetch the Instrumentation.
final Instrumentation lInstrumentation = getInstrumentation();
// Fetch the UiDevice.
final UiDevice lUiDevice = UiDevice.getInstance(lInstrumentation);
// Are we clearing the Field beforehand?
if(pIsClearField) {
// Reset the Field Text.
pUiObject.setText("");
}
// Are we going to simulate mechanical typing?
if(pIsSimulateTyping) {
// Click the Field. (Implicitly open Android's Soft Keyboard.)
pUiObject.click();
// Fetch the KeyEvents.
final KeyEvent[] lKeyEvents = SignUpTest.MAP_KEYCODE.getEvents(pString.toCharArray());
// Delay.
lInstrumentation.waitForIdleSync();
// Iterate the KeyEvents.
for(final KeyEvent lKeyEvent : lKeyEvents) {
// Is the KeyEvent a Release. (The KeyEvents contain both down and up events, whereas `pressKeyCode` encapsulates both down and up. This conditional statement essentially decimates the array.)
if(lKeyEvent.getAction() == KeyEvent.ACTION_UP) {
// Press the KeyEvent's corresponding KeyCode (Take account for special characters).
lUiDevice.pressKeyCode(lKeyEvent.getKeyCode(), lKeyEvent.isShiftPressed() ? KeyEvent.META_SHIFT_ON : 0);
// Delay.
lInstrumentation.waitForIdleSync();
}
}
// Close the keyboard.
lUiDevice.pressBack();
}
else {
// Write the String.
pUiObject.setText(pUiObject.getText() + pString);
}
// Delay.
lInstrumentation.waitForIdleSync();
}
私はそれらをidで見つけるだけです:
onView(withId(R.id.input_password)).perform(typeText("password"));
UI Automator Viewerにresource-idプロパティも表示されるようになりました。これは、コードにアクセスできない場合に役立ちます。