我使用Espresso框架进行UI测试,现在我想使用Kakao。我有一个带有某些视图的MainPage,可以通过以下方式找到该视图:
class MainPage() {
val screenTitle =
CoreMatchers.allOf(
withText("Main page"),
withParent(withId(R.id.mediaViewToolbar))
)
}
在Espresso测试用例中,这些行正常运行,没有问题
val mainPage = MainPage()
onView(mainPage.screenTitle).check(matches(isDisplayed()))
然后我试图用Kakao样式的视图重写此MainPage:
class MainScreen : Screen<MainScreen>() {
// here i faced a problem
val screenTitle = KBaseView<Matcher<View>>{ // this 2-nd line* is refferenced by error
CoreMatchers.allOf(
ViewMatchers.withText("Main page"),
ViewMatchers.withParent(ViewMatchers.withId(R.id.mediaViewToolbar))
)
}
}
如果尝试以Kakao风格编写测试用例,则>]
val mainScreen = MainScreen() mainScreen { screenTitle { isDisplayed() } }
然后我得到下一个错误:
E/TestRunner: failed: should_check_main_page(com.project.online.MainScreenKaspressoTest) ----- begin exception ----- java.lang.IllegalStateException: No matchers inside InteractionBuilder at com.agoda.kakao.common.builders.ViewBuilder.getViewInteractionDelegate(ViewBuilder.kt:395) at com.agoda.kakao.common.views.KBaseView.<init>(KBaseView.kt:42) at com.project.online.MainScreen.<init>(MainScreen.kt:2)* - 2-nd line
我知道我以错误的方式在MainScreen中指定了
screenTitle
,但如何正确?谢谢!
我使用Espresso框架进行UI测试,现在我想使用Kakao。我有一个带有某些视图的MainPage,该视图可以通过以下方式找到:类MainPage(){val screenTitle = ...
Kakao依靠其ViewBuilder
DSL为视图建立必要的匹配器。这是您应如何定义它: