JGeovani / robotium

Automatically exported from code.google.com/p/robotium
1 stars 0 forks source link

Testing EditText for inputType not possible #62

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an EditText the following way:

<EditText                   android:id="@+id/test"          android:layout_width="fill_parent"              and
roid:layout_height="wrap_content"
android:inputType="phone"
android:digits="0123456789"
android:maxLength="7"
android:cursorVisible="true" 
/>

2. Solo.enterText(0, "abc");

What is the expected output? What do you see instead?
Nothing should be entered in the EditText. However "abc" will be entered.

What version of the product are you using? On what operating system?
Robotium 2.1

Please provide any additional information below.

Original issue reported on code.google.com by JoaRe...@gmail.com on 4 Feb 2011 at 10:40

GoogleCodeExporter commented 9 years ago
Thanks for this. In order to make this change a lot of logic needs to be 
implemented into enterText(). There is a huge amount of different input types. 
Unfortunately there is not enough time for that at the moment. It is a valid 
point that you make however in this case I believe it is up to the test case 
developer to only test valid inputs. 

Original comment by renasr...@gmail.com on 4 Feb 2011 at 12:20

GoogleCodeExporter commented 9 years ago
The problem is that Solo.enterText is changing the input type.
and does not resets the input type to its origin value.

I tested a EditText see below code:

The 1:st assertEquals is Passed:  Expected = 129 and Actual=129
The 2: nd assertEquals is Failed: Expected = 129 and Actual=0

 assertEquals("Password EditText is not set to text and hidden password",
            InputType.TYPE_CLASS_TEXT  | InputType.TYPE_TEXT_VARIATION_PASSWORD,
            ( (EditText)m_solo.getView( R.id.activity_login_password_editview ) )
                            .getInputType());
        m_solo.enterText(
            1,
            PASSWORD );

assertEquals("Password EditText is not set to text and hidden password",
            InputType.TYPE_CLASS_TEXT  | InputType.TYPE_TEXT_VARIATION_PASSWORD,
            ( (EditText)m_solo.getView( R.id.activity_login_password_editview ) )
                            .getInputType());

Original comment by rln.r...@gmail.com on 12 Oct 2011 at 11:04

GoogleCodeExporter commented 9 years ago
i have password EditText . and when i am using solo.enterText() . it is showing 
the text and not hiding it as "*" .
 So is the above comment is the reason for my problem . 
how can i solve it . when i ran i should be able to hide the text as "*" .

Original comment by avinash....@gmail.com on 12 Dec 2011 at 5:17

GoogleCodeExporter commented 9 years ago
Hi,
i have password EditText . and when i am using solo.enterText() . it is showing 
the text and not hiding it as "*" .
 So is the above comment is the reason for my problem . 
how can i solve it . when i ran i should be able to hide the text as "*" .
if any alternate solution for password encryption,please provide some suggestion

thanks
Bikash

Original comment by bikash.m...@photoninfotech.net on 25 May 2012 at 7:34

GoogleCodeExporter commented 9 years ago
I don't mind the showing of the text entered, however, when setting InputType 
to TYPE_NULL in some special cases, in my case a dialog, generates a 
nullpointer exception. The exception is:

java.lang.NullPointerException 
at 
android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnect
ionWrapper.java:78) at 
android.view.inputmethod.InputMethodManager.reportFinishInputConnection(InputMet
hodManager.java:799)

Using Android studio 1.0.1 on Windows 8.1
Java 1.8.0_20_b26 x64
Target SDK is 17
Verified on Galaxy s3 with Android 4.4.4 and Genymotion with 4.4.4

My workaround is to use a version of enterText when specific id's is entered. 
It'll need instrumentation o fcourse.

private void enterTextDialog(final EditText editText, final String text) {
        if(editText != null) {
            Editable previousTextEdit = editText.getText();
            if(previousTextEdit != null) {
                final String previousText = previousTextEdit.toString();
                instrumentation.runOnMainSync(new Runnable() {
                    public void run() {
                        editText.setInputType(InputType.TYPE_CLASS_TEXT); // can't use TYPE_NULL with dialog for some reason
                        editText.performClick();
                        if (text.equals("")) {
                            editText.setText(text);
                        }
                        else {
                            editText.setText(previousText + text);
                            editText.setCursorVisible(false);
                        }
                    }
                });

            }
        }
    }

Original comment by S.Za...@gmail.com on 20 Jan 2015 at 12:15