用 Espresso 单击弹出菜单按钮?

问题描述 投票:0回答:1

有没有办法单击锚定到 ListView 项目的膨胀 PopupMenu 中的项目?

我有一个通过单击 ListView 内的按钮创建的 PopupMenu。我需要按 id 单击弹出窗口内的项目。

这是我的测试:

val item = onData(anything()).inAdapterView(withId(R.id.profiles_list)).atPosition(index)
val menuButton = item.onChildView(withId(R.id.options_button))
menuButton.perform(click()) // This opens the popup (anchored to menuButton)

这是单击选项按钮后创建菜单的方式:

val popup = PopupMenu(context, menuButton)
popup.setOnMenuItemClickListener {
    when (it.itemId) {
        R.id.profile_rename -> {
            // Action to perform
            true
        }
        else -> false
    }
}
popup.menuInflater.inflate(R.menu.list_item_profile, popup.menu)
popup.show()

我尝试使用 isPlatformPopup,但没有找到弹出窗口:

menuButton.inRoot(isPlatformPopup()).onChildView(withId(R.id.profile_rename)).perform(click())
kotlin junit android-view android-espresso
1个回答
0
投票

发现可以使用withText()检索该项目,而不是使用onChildView(withId())

onView(withText(R.string.rename)).inRoot(isPlatformPopup()).perform(click())

基于使用浓缩咖啡验证弹出菜单中的项目

的解决方案
© www.soinside.com 2019 - 2024. All rights reserved.