Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAttributes() does not work in detox 18.14.0 in Android #2846

Closed
1 task done
sandeep-bastola opened this issue Jun 18, 2021 · 27 comments · Fixed by #4203
Closed
1 task done

getAttributes() does not work in detox 18.14.0 in Android #2846

sandeep-bastola opened this issue Jun 18, 2021 · 27 comments · Fixed by #4203

Comments

@sandeep-bastola
Copy link

sandeep-bastola commented Jun 18, 2021

Describe the bug

The getAttributes() function does not work in Android with Detox 18.14.0.

It throws an error :
java.lang.ClassNotFoundException: com.google.android.material.slider.Slider

Steps To Reproduce

  • I have tested this issue on the latest Detox release (18.17.0) and it still reproduces
  1. Issue appeared in detox version 18.14.0 . Release note fo this version mentions that the getAttributes() function works in Android.
  2. Issue does not appear in iOS.

Expected behavior

Detox Trace-Logs

N/A

Device logs (adb logcat)

06-18 09:40:11.001  9652  9773 D DetoxWSClient: Received action 'invoke' (ID #33, params={"target":{"type":"Class","value":"com.wix.detox.espresso.EspressoDetox"},"method":"perform","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"androidx.test.espresso.Espresso"},"method":"onView","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxMatcher"},"method":"matcherForTestId","args":["homeScreen_stars_counter_value"]}}]}},{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxAction"},"method":"getAttributes","args":[]}}]})
06-18 09:40:11.001  9652  9771 I DetoxDispatcher: Handling action 'invoke' (ID #33)...
06-18 09:40:11.002  9652  9771 D Detox   : class com.wix.detox.espresso.DetoxMatcher, matcherForTestId, [homeScreen_stars_counter_value]
06-18 09:40:11.004  9652  9771 D Detox   : class androidx.test.espresso.Espresso, onView, [(with tag value: is "homeScreen_stars_counter_value" and view has effective visibility=VISIBLE)]
06-18 09:40:11.004  9652  9771 D Detox   : class com.wix.detox.espresso.DetoxAction, getAttributes, []
06-18 09:40:11.007  9652  9771 D Detox   : class com.wix.detox.espresso.EspressoDetox, perform, [androidx.test.espresso.ViewInteraction@4ba662b, com.wix.detox.espresso.action.GetAttributesAction@ec0ca88]
06-18 09:40:11.013  9652  9652 D IdlingResourceRegistry: All idling resources are idle.
06-18 09:40:11.015  9652  9652 D IdlingResourceRegistry: All idling resources are idle.
06-18 09:40:11.016  9652  9652 I ViewInteraction: Performing 'Get view attributes' action on view (with tag value: is "homeScreen_stars_counter_value" and view has effective visibility=VISIBLE)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: Test exception
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: java.lang.reflect.InvocationTargetException
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at java.lang.reflect.Method.invoke(Native Method)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at org.apache.commons.lang3.reflect.MethodUtils.invokeStaticMethod(MethodUtils.java:443)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at org.apache.commons.lang3.reflect.MethodUtils.invokeStaticMethod(MethodUtils.java:405)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.invoke.types.ClassTarget.execute(ClassTarget.java:23)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.invoke.types.Target.invoke(Target.java:59)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.invoke.MethodInvocation.invoke(MethodInvocation.java:35)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.invoke.MethodInvocation.invoke(MethodInvocation.java:26)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.invoke.MethodInvocation.invoke(MethodInvocation.java:20)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.detox.adapters.server.InvokeActionHandler.handle(DetoxActionHandlers.kt:56)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.detox.adapters.server.ActionsExecutor$executeAction$$inlined$let$lambda$1.run(DetoxActionsDispatcher.kt:64)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at android.os.Handler.handleCallback(Handler.java:883)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at android.os.Handler.dispatchMessage(Handler.java:100)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at android.os.Looper.loop(Looper.java:214)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.detox.adapters.server.ActionsExecutor$1.run(DetoxActionsDispatcher.kt:50)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at java.lang.Thread.run(Thread.java:919)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/material/slider/Slider;
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.detox.espresso.action.SliderAttributes.get(GetAttributesAction.kt:143)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.wix.detox.espresso.action.GetAttributesAction.perform(GetAttributesAction.kt:35)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:16)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:65)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at androidx.test.espresso.ViewInteraction.access$100(ViewInteraction.java:15)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:3)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:2)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at android.os.Handler.handleCallback(Handler.java:883)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at android.os.Handler.dispatchMessage(Handler.java:100)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at android.os.Looper.loop(Looper.java:214)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at android.app.ActivityThread.main(ActivityThread.java:7356)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at java.lang.reflect.Method.invoke(Native Method)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: Caused by: java.lang.ClassNotFoundException: com.google.android.material.slider.Slider
06-18 09:40:11.017  9652  9771 I DetoxActionHandlers: 	... 15 more
06-18 09:40:11.017  9652  9771 I DetoxWSClient: Sending out action 'testFailed' (ID #33)
06-18 09:40:11.017  9652  9771 I DetoxDispatcher: Done with action 'invoke'
06-18 09:40:11.055  1813  2087 E SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
06-18 09:40:11.144  1813  2087 E SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
06-18 09:40:11.161  9810  9810 D MPEG4Writer: Video track stopping. Stop source
06-18 09:40:11.161  9810  9810 D MPEG4Writer: Video track source stopping

Screenshots

Screen Shot 2021-06-18 at 8 30 44 AM

Environment (please complete the following information):

  • Detox: 18.14.0
  • React Native: 0.63.4
  • Node: 14.15.0
  • Device: Google Pixel XL API 29
  • OS: Android
  • Test-runner : jest
@noomorph
Copy link
Collaborator

Could you provide a code snippet to reproduce that component in React Native?

@sandeep-bastola
Copy link
Author

sandeep-bastola commented Jun 18, 2021

<ImageBackground style={styles.icon} source={this.props.icon}>
            <Text
              testID={this.props.testID + "_counter_value"}
              style={[styles.value, valueFontSize]}
            >
              {this.props.value}
            </Text>
            <Text style={[sharedStyle.textStyle.small2, styles.title]}>
              {this.props.title}
            </Text>
          </ImageBackground>

@noomorph
Copy link
Collaborator

Okay, I'll check if I can reproduce the result.

@noomorph
Copy link
Collaborator

Unfortunately, I won't be able to look earlier than Tuesday (22.06.21).
@d4vidi, @jonathanmos — if the stack trace provided makes some sense, you are welcome to take this earlier. 🙏

@d4vidi
Copy link
Collaborator

d4vidi commented Jun 20, 2021

@noomorph Yes I know where this is coming from. I'm looking into it.

@d4vidi
Copy link
Collaborator

d4vidi commented Jun 20, 2021

@sandeep-bastola for now, please add this to your android deps (in app/build.gradle):

dependencies {
    // ...
    testImplementation('com.google.android.material:material:1.3.0')
}

@d4vidi
Copy link
Collaborator

d4vidi commented Jun 20, 2021

@sandeep-bastola I've verified that this should in fact work even without adding the material dep explicitly.
I think that what you need is to rebuild your project from scratch (e.g. run ./gradlew clean inside your android/ directory).

@sandeep-bastola
Copy link
Author

Tested with both methods, neither did work.
However this worked:
dependencies {
// ...
implementation 'com.google.android.material:material:1.2.0-rc01'
}

@d4vidi
Copy link
Collaborator

d4vidi commented Jun 21, 2021

I fail to see why. Desperately trying to reproduce, yet in our example project getAttributes() works well even without the explicit dep. I suppose we'll have to stick the having the explicit dep as a workaround...

@martsie
Copy link

martsie commented Jul 19, 2021

We're having the same issue on our end

Test Failed: Didn't find class "com.google.android.material.slider.Slider" on path: DexPathList

When running getAttributes on an element.

Haven't been able to use any solutions from this thread because android build errors result in Cannot find a version of 'com.google.android.material:material' that satisfies the version constraints.

@d4vidi
Copy link
Collaborator

d4vidi commented Jul 19, 2021

@martsie Did you specify the latest version of com.google.android.material:material in your gradle scripts?

@martsie
Copy link

martsie commented Jul 19, 2021

We haven't specified any version of com.google.android.material:material in our project. I didn't find a reference on how to do that at https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md - is it something that needs to be defined?

The things that I did try is using:
androidTestImplementation('com.google.android.material:material:1.2.0-rc01') and androidTestImplementation('com.google.android.material:material:1.3.0') but doing that got us build errors like:

Cannot find a version of 'com.google.android.material:material' that satisfies the version constraints:
           Dependency path 'MobileApp:app:unspecified' --> 'com.google.android.material:material:1.2.0-rc01'
           Constraint path 'MobileApp:app:unspecified' --> 'com.google.android.material:material:{strictly 1.1.0}' because of the following reason: alphaDebugRuntimeClasspath uses version 1.1.0

Will continue to troubleshoot, if you've got any ideas we'd love to hear them.

@d4vidi
Copy link
Collaborator

d4vidi commented Jul 20, 2021

Theoretically, this shouldn't be defined explicitly by anyone. I'm surprised as you are - that this fails on anyone's build.

Try, instead:

implementation 'com.google.android.material:material:1.3.0'

@Peeeep
Copy link

Peeeep commented Aug 1, 2021

I am facing the same building issue, but only in release builds. Adding implementation 'com.google.android.material:material:1.2.1' did the trick for me for now.

@stale
Copy link

stale bot commented Aug 31, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

@stale stale bot added the 🏚 stale label Aug 31, 2021
@stale
Copy link

stale bot commented Sep 7, 2021

The issue has been closed for inactivity.

@stale stale bot closed this as completed Sep 7, 2021
@ShivamJoker
Copy link

ShivamJoker commented Nov 9, 2021

No it's not stale I am still getting this issue on detox 19 and react native 0.66

Although this fixes the issue, but it should be fixed by library itself

I am facing the same building issue, but only in release builds. Adding implementation 'com.google.android.material:material:1.2.1' did the trick for me for now.

@AshrafRizvi01
Copy link

This issue still happens and even doesn't work with the workaround.

@tran2
Copy link

tran2 commented Oct 1, 2022

For me, it works when I add this to proguard-rules:
-keep class com.google.android.material.** { *; }

@d4vidi
Copy link
Collaborator

d4vidi commented Oct 3, 2022

@AshrafRizvi01 @tran2 please try using Detox 19.12.5 (or newer); Be sure to remove any custom proguard rules before you do.

@martijnarts
Copy link

@d4vidi I'm hitting this on Detox 19.12.5

@SmartArray
Copy link

19.12.5 still yields the same issue.

@d4vidi
Copy link
Collaborator

d4vidi commented Oct 18, 2022

@SmartArray @martijnarts please review the section on proguard/minification in our Android setup guide.

If that doesn't help, try following the suggestions here about adding the proguard rule manually and android's material dependency (i.e. implementation 'com.google.android.material:material:1.2.1').

Please report back 🙏🏻

@SmartArray
Copy link

Thank you @d4vidi, I am going to check it out! I thought ProGuard is disabled by default, so I skipped the section

@aaronpliu
Copy link

Tried it on latest version v20.12.0. it still repro the issue. refer to history of discussion, I have to explicitly add implementation 'com.google.android.material:material:1.5.0 in android/app/build.gradle of my project.
There is no "implementation" of material in our project. I see com.google.android.material:material:1.2.1 in android/detox/build.gradle of Detox (v20.12.0). it should not be rely on tested project.

Is there any suggestion?

@d4vidi
Copy link
Collaborator

d4vidi commented Sep 19, 2023

Tried it on latest version v20.12.0. it still repro the issue. refer to history of discussion, I have to explicitly add implementation 'com.google.android.material:material:1.5.0 in android/app/build.gradle of my project. There is no "implementation" of material in our project. I see com.google.android.material:material:1.2.1 in android/detox/build.gradle of Detox (v20.12.0). it should not be rely on tested project.

Is there any suggestion?

Thanks @aaronpliu. We will try fixing this by switching to 100% reflection. PR's are welcome!

@asafkorem
Copy link
Contributor

asafkorem commented Sep 27, 2023

The fix for this issue was released with v20.12.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.