Hi Elk,

Yes, I wanted to do a paste into a field just as a user would:  long
press for context menu, then select Paste.  Particularly, I had
identified a problem with pasting a value into a field rather than
entering with individual key presses (my bad, not an Android
problem).  This isn't a functional test really, rather a component
test focused on the UI for a single field--I have detailed JUnit tests
for the app's data model.   I find the Android JUnit framework to be
quite handy for testing this.  But if you have a favorite tool for
functional testing, I'd like to know about it.

Your suggestion was spot on.  Thank you!  The code for the working
test follows.

--Z

    /* Verify proper formatting of values in the bill total field
     * when data is pasted into the field.
     */
    public void testBillTotalPaste() {
        mActivity.runOnUiThread(
                        new Runnable() {
                                public void run() {
                                                
billTotalEntryView.requestFocus();
                                }
                        }
                );
        mInstrumentation.waitForIdleSync();

        mActivity.runOnUiThread(
                        new Runnable() {
                                public void run() {
                                        ClipboardManager clipboardManager
                                                = (ClipboardManager) 
mActivity.getSystemService
                                                
(android.content.Context.CLIPBOARD_SERVICE);
                                        clipboardManager.setText("120.56");
                                }
                        }
                );
        mInstrumentation.waitForIdleSync();

        TouchUtils.longClickView(this, billTotalEntryView);
        mInstrumentation.waitForIdleSync();

        int[] keyCodes = {
                        KeyEvent.KEYCODE_DPAD_DOWN,
                        KeyEvent.KEYCODE_DPAD_DOWN,
                        KeyEvent.KEYCODE_DPAD_DOWN,
                        KeyEvent.KEYCODE_DPAD_DOWN,
                        KeyEvent.KEYCODE_DPAD_DOWN,
                        KeyEvent.KEYCODE_DPAD_CENTER
                        };
        for (int keyCode : keyCodes) {
                this.sendKeys(keyCode);
        }
        mInstrumentation.waitForIdleSync();

        assertEquals("Incorrect pasted value", "120.56",
                        billTotalEntryView.getText().toString());
    }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to