KasperskyLab / Kaspresso

Android UI test framework
https://kasperskylab.github.io/Kaspresso/
Apache License 2.0
1.77k stars 149 forks source link

hasDrawable not working with imageview as expected #263

Closed TheReprator closed 1 year ago

TheReprator commented 3 years ago

Hi Team,

First thanks for this great UI Testing framework. Currently i am trying to check drawable with imageview but i am getting below error, as follows,

androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with drawable id -1 or provided instance' doesn't match the selected view.

Exception: junit.framework.AssertionFailedError: 'with drawable id -1 or provided instance' doesn't match the selected view. Expected: with drawable id -1 or provided instance Got: "AppCompatImageView{id=2131230883, res-name=factImage, visibility=VISIBLE, width=180, height=220, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@af535b6, tag=null, root-is-layout-requested=false, has-input-connection=false, x=508.0, y=65.0}"

at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1720)
at com.kaspersky.kaspresso.failure.FailureLoggingProviderImpl.describedWith(FailureLoggingProviderImpl.kt:91)
at com.kaspersky.kaspresso.failure.FailureLoggingProviderImpl.logDescriptionAndThrow(FailureLoggingProviderImpl.kt:69)
at com.kaspersky.kaspresso.failure.LoggingFailureHandler.logDescriptionAndThrow(Unknown Source:2)
at com.kaspersky.kaspresso.failure.LoggingFailureHandler.handle(LoggingFailureHandler.kt:21)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:103)
at androidx.test.espresso.ViewInteraction.check(ViewInteraction.java:31)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor$interceptCheck$1.invoke(KakaoViewInterceptor.kt:29)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor$interceptCheck$1.invoke(KakaoViewInterceptor.kt:16)
at com.kaspersky.kaspresso.autoscroll.AutoScrollProviderImpl.withAutoScroll(AutoScrollProviderImpl.kt:30)
at com.kaspersky.kaspresso.interceptors.behavior.impl.autoscroll.AutoScrollViewBehaviorInterceptor.withAutoScroll(Unknown Source:12)
at com.kaspersky.kaspresso.interceptors.behavior.impl.autoscroll.AutoScrollViewBehaviorInterceptor.intercept(AutoScrollViewBehaviorInterceptor.kt:26)
at com.kaspersky.kaspresso.interceptors.behavior.impl.autoscroll.AutoScrollViewBehaviorInterceptor.intercept(AutoScrollViewBehaviorInterceptor.kt:14)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor$interceptCheck$$inlined$fold$lambda$1.invoke(KakaoViewInterceptor.kt:34)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor$interceptCheck$$inlined$fold$lambda$1.invoke(KakaoViewInterceptor.kt:16)
at com.kaspersky.kaspresso.systemsafety.SystemDialogSafetyProviderImpl.passSystemDialogs(SystemDialogSafetyProviderImpl.kt:51)
at com.kaspersky.kaspresso.interceptors.behavior.impl.systemsafety.SystemDialogSafetyViewBehaviorInterceptor.passSystemDialogs(Unknown Source:7)
at com.kaspersky.kaspresso.interceptors.behavior.impl.systemsafety.SystemDialogSafetyViewBehaviorInterceptor.intercept(SystemDialogSafetyViewBehaviorInterceptor.kt:28)
at com.kaspersky.kaspresso.interceptors.behavior.impl.systemsafety.SystemDialogSafetyViewBehaviorInterceptor.intercept(SystemDialogSafetyViewBehaviorInterceptor.kt:15)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor$interceptCheck$$inlined$fold$lambda$1.invoke(KakaoViewInterceptor.kt:34)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor$interceptCheck$$inlined$fold$lambda$1.invoke(KakaoViewInterceptor.kt:16)
at com.kaspersky.kaspresso.flakysafety.algorithm.FlakySafetyAlgorithm.invokeFlakySafely(FlakySafetyAlgorithm.kt:32)
at com.kaspersky.kaspresso.flakysafety.algorithm.FlakySafetyAlgorithm.invokeFlakySafely$default(FlakySafetyAlgorithm.kt:24)
at com.kaspersky.kaspresso.flakysafety.FlakySafetyProviderSimpleImpl.flakySafely(FlakySafetyProviderSimpleImpl.kt:27)
at com.kaspersky.kaspresso.interceptors.behavior.impl.flakysafety.FlakySafeViewBehaviorInterceptor.flakySafely(Unknown Source:7)
at com.kaspersky.kaspresso.interceptors.behavior.impl.flakysafety.FlakySafeViewBehaviorInterceptor.intercept(FlakySafeViewBehaviorInterceptor.kt:26)
at com.kaspersky.kaspresso.interceptors.behavior.impl.flakysafety.FlakySafeViewBehaviorInterceptor.intercept(FlakySafeViewBehaviorInterceptor.kt:14)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor$interceptCheck$$inlined$fold$lambda$1.invoke(KakaoViewInterceptor.kt:34)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor$interceptCheck$$inlined$fold$lambda$1.invoke(KakaoViewInterceptor.kt:16)
at com.kaspersky.kaspresso.interceptors.tolibrary.kakao.KakaoViewInterceptor.interceptCheck(KakaoViewInterceptor.kt:36)
at com.kaspersky.kaspresso.interceptors.tolibrary.LibraryInterceptorsInjector$injectKaspressoInKakao$1$1$1.invoke(LibraryInterceptorsInjector.kt:54)
at com.kaspersky.kaspresso.interceptors.tolibrary.LibraryInterceptorsInjector$injectKaspressoInKakao$1$1$1.invoke(LibraryInterceptorsInjector.kt:22)
at com.agoda.kakao.delegate.Delegate$DefaultImpls.interceptOnCheck(Delegate.kt:61)
at com.agoda.kakao.delegate.Delegate$DefaultImpls.access$interceptOnCheck(Delegate.kt:13)
at com.agoda.kakao.delegate.Delegate$interceptCheck$1.invoke(Delegate.kt:28)
at com.agoda.kakao.delegate.Delegate$DefaultImpls.interceptCheck(Delegate.kt:33)
at com.agoda.kakao.delegate.ViewInteractionDelegate.interceptCheck(ViewInteractionDelegate.kt:21)
at com.agoda.kakao.delegate.ViewInteractionDelegate.interceptCheck(ViewInteractionDelegate.kt:21)
at com.agoda.kakao.delegate.ViewInteractionDelegate.check(ViewInteractionDelegate.kt:26)
at com.agoda.kakao.image.ImageViewAssertions$DefaultImpls.hasDrawable(ImageViewAssertions.kt:45)
at com.agoda.kakao.image.KImageView.hasDrawable(KImageView.kt:17)
at com.agoda.kakao.image.ImageViewAssertions$DefaultImpls.hasDrawable$default(ImageViewAssertions.kt:44)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3$1$1$1$1$1.invoke(FactListKaspressoTest.kt:228)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3$1$1$1$1$1.invoke(FactListKaspressoTest.kt:24)
at com.agoda.kakao.common.views.KBaseView.invoke(KBaseView.kt:83)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3$1$1$1.invoke(FactListKaspressoTest.kt:219)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3$1$1$1.invoke(FactListKaspressoTest.kt:24)
at com.agoda.kakao.recycler.KRecyclerView.invoke(KRecyclerView.kt:197)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3$1$1.invoke(FactListKaspressoTest.kt:213)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3$1$1.invoke(FactListKaspressoTest.kt:24)
at com.agoda.kakao.screen.Screen.invoke(Screen.kt:119)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3$1.invoke(FactListKaspressoTest.kt:211)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3$1.invoke(FactListKaspressoTest.kt:24)
at com.kaspersky.kaspresso.testcases.core.testcontext.TestContext.step(TestContext.kt:39)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3.invoke(FactListKaspressoTest.kt:208)
at reprator.wipro.factlist.test.FactListKaspressoTest$imageViewDrawableComparison$3.invoke(FactListKaspressoTest.kt:24)
at com.kaspersky.kaspresso.testcases.core.TestRunner.runMainTestSection(TestRunner.kt:144)
at com.kaspersky.kaspresso.testcases.core.TestRunner.run(TestRunner.kt:58)
at com.kaspersky.kaspresso.testcases.core.sections.MainTestSection.run(MainTestSection.kt:29)
at reprator.wipro.factlist.test.FactListKaspressoTest.imageViewDrawableComparison(FactListKaspressoTest.kt:207)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at dagger.hilt.android.internal.testing.MarkThatRulesRanRule$1.evaluate(MarkThatRulesRanRule.java:106)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2198)

Caused by: junit.framework.AssertionFailedError: 'with drawable id -1 or provided instance' doesn't match the selected view. Expected: with drawable id -1 or provided instance Got: "AppCompatImageView{id=2131230883, res-name=factImage, visibility=VISIBLE, width=180, height=220, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@af535b6, tag=null, root-is-layout-requested=false, has-input-connection=false, x=508.0, y=65.0}"

at androidx.test.espresso.matcher.ViewMatchers.assertThat(ViewMatchers.java:17)
at androidx.test.espresso.assertion.ViewAssertions$MatchesViewAssertion.check(ViewAssertions.java:15)
at com.kaspersky.kaspresso.proxy.ViewAssertionProxy.check(ViewAssertionProxy.kt:26)
at androidx.test.espresso.ViewInteraction$SingleExecutionViewAssertion.check(ViewInteraction.java:10)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:11)
at androidx.test.espresso.ViewInteraction$2.call(ViewInteraction.java:2)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7563)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

Repository: https://github.com/TheReprator/Wipro/blob/image_error/appModules/factList/src/androidTest/kotlin/reprator/wipro/factlist/test/FactListKaspressoTest.kt

Test Name: imageViewDrawableComparison

Looking forward for a solution.

Regards, Vikram Sing

matzuk commented 3 years ago

Hi @TheReprator! @Vacxe do you have ideas?

Vacxe commented 3 years ago

@TheReprator The main issue with hasDrawable that it using native bitmap comparation functionality. bitmap.sameAs(otherBitmap) -> .sameAs it's a massive pitfall because current image displayed in image view can be slightly different with expected.

However did u try

hasDrawable(R.drawable.ic_error)

instead of

val drawable = ResourcesCompat.getDrawable(
                                    appContext.resources,
                                    R.drawable.ic_error,
                                    appContext.theme
                                )
                                hasDrawable(drawable!!)
TheReprator commented 3 years ago

Yes, i had tried "hasDrawable(R.drawable.ic_error)" as well, but didn't worked

Vacxe commented 3 years ago

@TheReprator Could u create a PR to Kakao with same resource to reproduce the issue. - Then next we can investigate what's going wrong.

AzamatCherchesov commented 1 year ago

@Vacxe Hi! any news? =)

AzamatCherchesov commented 1 year ago

@Vacxe Hi! any news?)

Vacxe commented 1 year ago

@AzamatCherchesov Hey, you can close this PR for Kaspresso repo because it is not related for. Also it is outdated and I reached the author directly.

Nikitae57 commented 1 year ago

Closing this issue due to @Vacxe comment

MikhailShaidulinAD commented 6 months ago

@AzamatCherchesov Hey, you can close this PR for Kaspresso repo because it is not related for. Also it is outdated and I reached the author directly.

Hi. I'd appreciate it if you could share this information with everyone, because I have the same issue.