material-components / material-components/material-components-android

[MaterialDatePicker] Unable to select date with espresso or/and reflection

Open
#2,574 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Issue: Test Needs Investigation Widget: DatePicker
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Description:**
I can't select a date with espresso or/and reflection:
1. Espresso
I'm trying to do something [similar](https://github.com/material-components/material-components-android/blob/cfc00aa5a361f3c1c8a784fa597f03266af22e6e/tests/javatests/com/google/android/material/datepicker/MaterialDatePickerTestUtils.java#L172), but Month is final and package-private...I can select the day, but not the year or month.
2. Reflection
Doesn't work, I get error NPE: null receiver
```
onView(
ViewMatchers.isRoot()
)
.perform(customViewAction { rootView ->
val context = rootView.context
val activity = if (context is ContextThemeWrapper) {
context.baseContext as AppCompatActivity
} else {
context as AppCompatActivity
}
val fragment = activity.supportFragmentManager.findFragmentByTag("myTag")
val field = MaterialDatePicker::class.java.getDeclaredField("dateSelector")
field.isAccessible = true
val value = field.get(fragment)
...
})
```

**Expected behavior:** Add the ability to select a date in ui tests or add examples of how to do this, if it is possible right now with version 1.4.0.

**Android API version:** Any

**Material Library version:** 1.4.0

**Device:** Any

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/javatests/com/google/android/material/datepicker/MaterialDatePickerTestUtils.java, especially the linked selection helpers, and compare them with the MaterialDatePicker APIs available in version 1.4.0. Done means providing a reliable way to select the month and year in UI tests, either through supported test interaction or a documented working example.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.