KakaoCup / Kakao

Nice and simple DSL for Espresso in Kotlin
https://kakaocup.github.io/Kakao/
Apache License 2.0
324 stars 28 forks source link

TextInputLayoutAssertions methods has false-positive behaviour #91

Closed timofei-malygin closed 1 year ago

timofei-malygin commented 1 year ago

Steps to reproduce:

  1. Create an XML file with TextInputEditText and add tags for TextInputEditText ( tagTextInputEditText) and for EditText inside the TextInputEditText (tagEditText). add to Hint any text (e.x. "hint")
  2. create a UI test running the activity with this XML.
  3. add this code KTextInputLayout { withTag(tagEditText) }.hasHint("any text _"+ UUID.randomUUID())

Observed Results:

The Test will pass

Expected Result

The Test should fail! Expected an AssertionError that EditText is not TextInputLayout

Relevant Code:

The problem is that methods check instances and do not throw an exception if it is different than expected

fun hasHint(hint: String) {
        view.check(ViewAssertion { view, notFoundException ->
            if (view is TextInputLayout) {
                if (hint != view.hint.toString()) {
                    throw AssertionError(
                        "Expected hint is $hint," +
                                " but actual is ${view.hint}"
                    )
                }
            } else {
                notFoundException?.let { throw AssertionError(it) } // here code should throw AssertionError("expected TextInputLayout, but got $view") if notFoundException is null
            }
        })
  // code here