perform(click())在android 11中不起作用,但在android 10中起作用

fumotvh3  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(326)

我有一个测试用例,我想点击片段按钮,它会将我导航到不同的屏幕。
这是我在功能文件中的测试用例。

@abc
  Scenario: As a RM, I should be able to see accepted on coming to admin approval screen
    Given User is at XYZ screen for scenario "approved"
    And User is able to see that verification is accepted
    When User clicks on next button
    Then User will be navigated to abc screen

当执行“用户单击下一个按钮”测试用例时,该方法将使用按钮id调用。

Espresso.onView(ViewMatchers.withId(R.id.add_button))
            .perform(ViewActions.click())

在“then”之后,将使用这个方法执行这种情况,我将导航到不同的片段。

/**
   * Match destination to which user will be navigated.
   * Assert that mock nav controller has action for destination.
   * 
   * @param id : This is fragment action id
   */
  fun matchIntendedDestination(id: Int) {
    SystemClock.sleep(1000)
    val idCapture = ArgumentCaptor.forClass(Int::class.java)
    Mockito.verify(BaseHelper.getMockNavController()).navigate(idCapture.capture())
    Assert.assertEquals(id, idCapture.value)
  }

渐变版本

classpath 'com.android.tools.build:gradle:4.2.1'

浓缩咖啡图书馆

testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
    androidTestImplementation "androidx.test.espresso:espresso-contrib:3.2.0"
    androidTestImplementation('androidx.test:runner:1.1.0')
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'io.cucumber:cucumber-android:4.3.1'
    androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.6.0'
    debugImplementation 'androidx.fragment:fragment-testing:1.2.4'
    androidTestImplementation "org.mockito:mockito-android:3.3.3"

得到这个错误

Wanted but not invoked:
navController.navigate(<Capturing argument>);
-> at com.rupeek.loanreleaseapp.helper.ReleaseRejectionHelper.matchIntendedDestination(ReleaseRejectionHelper.kt:117)
Actually, there were zero interactions with this mock.

但问题是,这段代码在android 10中成功执行,但在android 11中却没有。有谁能帮我看看android 11中缺少了什么。我还检查了所有库的更新情况。
当我调试代码时,我发现perform(click())没有调用片段中的任何内容。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题