suli1 / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

typeText enters wrong special characters #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Write a test for an activity which has a text input field
2. call onView(withId(R.id.input_field)).perform(typeText("@{!_)")); in your 
text to populate the field

What is the expected output?
The field should be filled with the string: @{!_)

What do you see instead?
The field is filled with the text "`!=

What version of the product are you using? On what operating system?
Newly released espresso build with custom dependencies
espresso-1.0-SNAPSHOT.jar etc

Test device is Android 4.1.1 Galaxy Note 2 for the Japanese market.

Please provide any additional information below.

Keyboard layout differs from the default android keyboard

the relevant part of the test code:

public LoginTest() {
        super(Login.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    @Test
    public void testLogin() {
        onView(withId(R.id.edit_login)).perform(typeText("@{!_)"));
...
}

Original issue reported on code.google.com by maik.vl...@vuzz.com on 23 Oct 2013 at 7:16

Attachments:

GoogleCodeExporter commented 9 years ago
I attached the output for the call

typeText("~!@#$%^&*()_+`=-[]{};:\";',.<>/?")

if that is of any help

Original comment by maik.vl...@vuzz.com on 23 Oct 2013 at 7:37

Attachments:

GoogleCodeExporter commented 9 years ago
This seems to be an IME specific issue. This IME has a different interpretation 
of these special characters then what is expected (we get from 
http://developer.android.com/reference/android/view/KeyCharacterMap.html)

As a workaround, you can setText directly on the EditText by using your own 
ViewAction... something like this:

final class SetTextAction implements ViewAction {
  private final String text;

  SetTextAction(String text) {
   this.text = checkNotNull(text);
  }

  @SuppressWarnings("unchecked")
  @Override
  public Matcher<View> getConstraints() {
    return allOf(isDisplayed(), isAssignableFrom(EditText.class));
  }

  @Override
  public void perform(UiController uiController, View view) {
    ((EditText) view).setText(text);
  }

  @Override
  public String getDescription() {
    return "set text";
  }
}

We should probably add this to Espresso's ViewActions collection.

Original comment by vale...@google.com on 23 Oct 2013 at 7:07

GoogleCodeExporter commented 9 years ago
Thanks for the fast reply. I incorporated the suggested code and it works. 
Thanks again

Original comment by maik.vl...@vuzz.com on 24 Oct 2013 at 1:11