I'm trying to set text into text inputs on the same activity (one by one).
Problem is that on first input is text filled correctly but on the second input i get exception message.
android.support.test.espresso.PerformException:
Error performing 'single click' on view 'with id: com.example.xxx.test:id/txtField2'.
Here is the test method:
@Test
public void buttonShouldUpdateText(){
this.clickOnActionBarMenuIcon();
this.clickOnActionBarMenuItem(10);
this.clickOnButton();
this.checkTextOnActivity("Hello world!");
this.insertTextIntoInput(R.id.txtFieldOne, "Hello world!"); // Works fine
this.insertTextIntoInput(R.id.txtFieldTwo, "Hello world2"); // Throws exception
}
And method is following:
public void insertTextIntoInput(Integer inputId, String text) {
onView(withId(inputId)).perform(typeText(text));
}
Layout is following:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="activities.SecondActivity">
<TextView android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1SecondView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtFieldOne"
android:layout_below="@+id/text1SecondView"
android:layout_alignParentStart="true"
android:layout_marginTop="103dp"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtFieldTwo"
android:layout_marginTop="51dp"
android:layout_below="@+id/txtFieldOne"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
How can i solve it and what i am doing wrong please?
Most likely you have a keyboard covering the edit text. Try closing it with
closeSoftKeyboard()
ViewAction when you enter text in first input field.
Keep in mind that closeSoftKeyboard() will not wait for keyboard animation to stop: https://code.google.com/p/android-test-kit/issues/detail?id=79
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With