The following are few APIs supported by Robotium to test the Text Fields,
- searchEditText(String text)
- clickOnEditText(int index)
- clearEditText(int index)
- typeText(int index, String text)
- enterText(int index, String text)
Test case for verifying the Text Fields :
Steps :- Wait for the activity to launch
- Enter a text in the Text Field
- Verify the text entered in the Text Field
- Clear the Text Entered in the Text Field
- Enter a new Test again and Verify the text entered.
1: public void testEditField() throws Exception {
2: solo.waitForActivity("MainActivity");
3:
4: solo.clickOnEditText(0);
5: String strInput = "Sample code 1";
6: solo.enterText(0, strInput);
7: boolean actual = solo.searchEditText(strInput);
8: assertEquals("text entered is not matching",true, actual);
9:
10: solo.clearEditText(0);
11: strInput = "Sample code 2";
12: solo.typeText(0, strInput);
13: actual = solo.searchEditText(strInput);
14: assertEquals("text entered is not matching",true, actual);
15: }
Explanation:
- solo.waitforActivity( ), is to wait for the activity to launch
- Enter Text in the Text Field : to enter a text in the Text filed, both ‘solo.enterText()’ and ‘solo.typeText()’ can be used.
- in ‘enterText(int index, String text)’, index is the index of the Text Field.
- if multiple Text Fields exists, first one will be assigned an index of 0, second one will get an index 1 and so on.. index increases from Top to Bottom or Left to Right
- Verify the Text Entered : to verify the text contained in the Text Filed, ‘solo.searchEditText()’ can be used. it returns True, if pattern matches otherwise return False
- Clear the Text in the Text Field : to clear the Text exist in the Text Field, ‘solo.clearEditText()’ can be used.
- ‘assertEquals()’, can be used to assert True/False
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.