Appium getText() returns android:hint value from EditText?

I just started investigating the use of Appium for test automation of a native Android app. In this app, the XML layout for the UI contains the following declaration for an EditText control:

    android:hint="Type or paste text here"
    android:text="" />

When the app runs, the text value of the EditText is obviously empty so it displays the hint value (“Type or paste text here”). In my test case, after I find the EditText element and then call getText() on it, the return value I get back is not an empty string as I was expecting. Instead, I get back the hint value of the EditText (“Type or paste text here”). This is the first time I’ve used Appium so it’s possible that this is the expected behavior. But if that’s the case, how do I assert that the text value of the EditText is, in fact, empty if getText() returns the value of the hint? I suppose I could assert that the value returned by getText() is equal to “Type or paste text here” but then if the user actually entered that exact text, how would I know the difference?

1 Like

This is how I will do in Java.

public void verifyEditTextFieldIsEmpty() {

    String hint1 = "Type or paste text here";

    Assert.assertTrue(isEditTextFieldIsEmpty(editTextLocatorId.getText(), hint1);

Now create a boolean method

private boolean isEditTextFieldIsEmpty(String editTextFiled, String... hints) {
    return (editTextFiled != null && (editTextFiled.isEmpty() || Arrays.asList(hints).contains(editTextFiled.toLowerCase())));