KasperskyLab / Kaspresso

Android UI test framework
https://kasperskylab.github.io/Kaspresso/
Apache License 2.0
1.81k stars 153 forks source link

SoftKeyboard is recognized as a SystemDialog #521

Closed AlexeyRybakov closed 1 year ago

AlexeyRybakov commented 1 year ago

Describe the bug

Kaspresso recognizes SoftKeyboard as a SystemDialog and tries to close it.

To Reproduce Steps to reproduce the behavior:

  1. Start a screen with opened SoftKeyboard
  2. Check not passing assertion to activate FlakySafely mechanism. For example, assert isDisplayed() for non-existent View.
  3. You can see log: The android system dialog/window was detected. The try #0 of the suppressing of SystemDialogs failed.

Expected behavior The SoftKeyboard should not trigger suspending of SystemDialogs.

Smartphone (please complete the following information):

Additional context It seems like the problem in this line: https://github.com/KasperskyLab/Kaspresso/blob/56067aab6410ce9b9492e5e0385b94a93346f34e/kaspresso/src/main/kotlin/com/kaspersky/kaspresso/systemsafety/SystemDialogSafetyProviderImpl.kt#L109 Where SoftKeyboard package is com.google.android.inputmethod.latin

Code to reproduce:

class SimpleTest : TestCase() {

    @get:Rule
    val activityRule = activityScenarioRule<MainActivity>()

    @Test
    fun test() = run {
        KButton { withTag("non-existent view") }.isDisplayed()
    }
}

Activity:

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <requestFocus/>
        </EditText>
<FrameLayout/> 

Logs:

16:46:33.457  I  ___________________________________________________________________________
16:46:33.462  I  ---------------------------------------------------------------------------
16:46:33.462  I  BEFORE TEST SECTION
16:46:33.462  I  ---------------------------------------------------------------------------
16:46:33.463  I  ---------------------------------------------------------------------------
16:46:33.463  I  TEST SECTION
16:46:33.463  I  ---------------------------------------------------------------------------
16:46:34.059  I  Checking 'com.kaspersky.kaspresso.proxy.ViewAssertionProxy@316e4e4' assertion on view (view.getTag() "non-existent view")
16:46:34.059  I  (view.getTag() "non-existent view")
16:46:34.068  E  Failed to interact with view matching: (view.getTag() "non-existent view") because of NoMatchingViewException
16:46:36.758  I  The android system dialog/window was detected
16:46:36.758  I  The suppressing of SystemDialogs starts
16:46:36.758  I  The suppressing of SystemDialogs on the try #0 starts
16:46:36.772  I  AdbServer. The command to execute=input keyevent KEYCODE_BACK
16:46:42.121  I  AdbServer. The command=input keyevent KEYCODE_BACK was performed with result=CommandResult(status=TIMEOUT, description=The time for the connection establishment is over, serviceInfo=null)
16:46:42.268  I  The try #0 of the suppressing of SystemDialogs failed
16:46:42.569  I  The android system dialog/window was detected
16:46:42.573  I  The suppressing of SystemDialogs on the try #1 starts
16:46:45.649  I  The try #1 of the suppressing of SystemDialogs failed
16:46:45.713  I  The android system dialog/window was detected
16:46:45.713  I  The suppressing of SystemDialogs on the try #2 starts
16:46:47.908  I  The try #2 of the suppressing of SystemDialogs failed
16:46:47.998  I  The android system dialog/window was detected
16:46:47.998  I  The suppressing of SystemDialogs on the try #3 starts
16:46:50.164  I  The try #3 of the suppressing of SystemDialogs failed
16:46:50.221  I  The android system dialog/window was detected
16:46:50.222  I  The suppressing of SystemDialogs on the try #4 starts
16:46:50.621  I  Checking 'com.kaspersky.kaspresso.proxy.ViewAssertionProxy@195a905' assertion on view (view.getTag() "non-existent view")
16:46:50.621  I  (view.getTag() "non-existent view")
16:46:50.623  E  Failed to interact with view matching: (view.getTag() "non-existent view") because of NoMatchingViewException
16:46:50.760  I  The try #4 of the suppressing of SystemDialogs failed
16:46:52.249  I  The try #4 of the suppressing of SystemDialogs failed. The reason is the error is not allowed or android system dialog is suppressed but the error is existing
16:46:52.762  E  All attempts to interact for 10000 ms totally failed because of NoMatchingViewException
16:46:52.766  I  ---------------------------------------------------------------------------
16:46:52.767  I  AFTER TEST SECTION
16:46:52.768  I  ---------------------------------------------------------------------------
16:46:52.770  I  ---------------------------------------------------------------------------
16:46:52.770  I  TEST FAILED
16:46:52.771  I  ---------------------------------------------------------------------------
16:46:52.771  I  ___________________________________________________________________________
primechord commented 1 year ago

In our case, the test does not fail, but it takes longer

AlexeyRybakov commented 1 year ago

In our case, the test does not fail, but it takes longer

You are right. But it could fail if you enable an AdbServer, than it will try to close a keyboard by a back action. The test would fail if you check that the keyboard is present.