У меня есть активность с видом logsTv
, я хочу получить ее текст следующим способом:
fun ViewInteraction.getText(): String {
var text = ""
perform(object : ViewAction {
override fun getConstraints(): Matcher<View> {
return ViewMatchers.isAssignableFrom(TextView::class.java)
}
override fun getDescription(): String {
return "Text of the view"
}
override fun perform(uiController: UiController, view: View) {
val tv = view as TextView
text = tv.text.toString()
}
})
return text
}
и
private fun getLogsText(): String {
return onView(withId(R.id.logsTv))
.inRoot(withDecorView(`is`(getActivity()!!.window.decorView)))
.getText()
}
Проблема в том, что в данный момент есть активный диалог (и я не могу его скрыть), поэтому он не работает:
java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not request layout for 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus. Root:
Есть ли способ получить текст из logsTv
без закрытия диалога?
PS Мне нужно получить текст, а не соответствовать ему.