浓缩咖啡片段交易测试

时间:2019-02-21 12:03:35

标签: android android-fragments kotlin android-espresso ui-testing

我正在做这个项目。我开始使用Espresso来学习工具测试,以编写UI测试。我有一个底视图,每个底视图选项卡都有一个父片段及其子片段。我执行了一个错误的片段事务,即从“服务底部视图”选项卡主页导航到“主页底部视图”选项卡,但显示了服务片段。

我想测试是否单击主页底视图选项卡上的主页片段。我已经尝试过这样的代码,但是它也传递了错误的情况

我也浏览了以下StackOverflow帖子,但没有用

Determine fragment change while espresso testing

How to test if a fragment is visible with Espresso

@Test
fun testHomeFragment_isDisplayed() {

    //click on home navigation button of bottom view
    onView(withId(R.id.navigation_home)).perform(click())

    //click on services navigation button of bottom view
    onView(withId(R.id.navigation_more)).perform(click())

    //click on recycler view item at given position
    onView(withId(R.id.more_rv)).perform(
            RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
                    1,
                    MyViewAction.clickChildViewWithId(R.id.row_more_parent)));

    //Again click on home navigation button of bottom view
    onView(withId(R.id.navigation_home)).perform(click())

    //check that the home fragment is displayed or not.
    onView(allOf(withId(R.id.home_pager), withParent(withId(R.id.papa)))).
            check(matches(isCompletelyDisplayed()))

}

如何知道屏幕上当前显示的片段?

0 个答案:

没有答案