8

uiautomatorがパスワードEditTextを選択することは可能ですか?android:hintプロパティで他のEditTextビューを見つけるのに問題はありませんが、uiautomatorviewerはすべてのパスワードフィールドをNAFとして表示します。パスワードフィールドの内容の説明を設定しようとしましたが、それも機能しませんでした。

それが不可能な場合、テスターが手動でパスワードを入力するためのタイムアウトをどのように設定しますか?

4

3 に答える 3

9

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();
于 2013-03-31T11:13:18.380 に答える
0

の中にレンダリングされたWebページ内のテキストフィールドにプログラムで入力する必要がある場合など、sViewにがない場合があります。すなわちResourceIdWebView

// 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();
}
于 2017-06-26T11:12:55.670 に答える
-1

私はそれらをidで見つけるだけです:

onView(withId(R.id.input_password)).perform(typeText("password"));

UI Automator Viewerにresource-idプロパティも表示されるようになりました。これは、コードにアクセスできない場合に役立ちます。

于 2016-04-04T14:09:58.037 に答える