Search code examples
ui-automationandroid-espressoandroid-testinggui-testingkakao

Android Kaspresso (Kakao) how to pick file from downloads


How to pick file from Downloads folder with Kaspresso/Kakao/UI Automator? Cannot find any info about it.


Solution

  • I've found the solution. Kaspresso:

    @Test
    fun sendReceiveFile() {
    
        ChatMainScreen {
            addAttachmentBtn {
                isVisible()
                click()
            }
            val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
    
            UiScrollable(UiSelector().scrollable(true).instance(0)).scrollIntoView(
                UiSelector().textContains("test_pdf2").instance(0)
            ) // we need to scroll to this element if not visible
    
            val okButton: UiObject2? = device.findObject(
                By.textContains("test_pdf2")
            )
    
            device.performActionAndWait({ okButton?.click() }, Until.newWindow(), 4000)
            sendMessageBtn {
                isVisible()
                click()
            }
            chatItemsRecyclerView {
                hasDescendant { containsText("test_pdf2") }
            }
        }
    }