My question is pretty simple. How do I perform any selections on a DatePickerDialog in Jetpack compose's UI Tests?
Jetpack Compose UI Test with Material3 DatePickerDialog
537 views Asked by Karim Omar At
2
There are 2 answers
0
James Jordan Taylor
On
For any Jetpack Compose widget that you're unfamiliar with you can print the node structure to logcat with the following command:
composeTestRule.onRoot().printToLog("ARBITRARY_LOG_TAG")
From that you should get something like this in logcat after running the test:
| Text = '[Tuesday, January 16, 2024]'
| Role = 'Button'
| Focused = 'false'
| Selected = 'false'
| Actions = [OnClick, RequestFocus]
| MergeDescendants = 'true'
|-Node #142 at (l=411.0, t=841.0, r=537.0, b=967.0)px
| Text = '[Today, Wednesday, January 17, 2024]'
| Role = 'Button'
| Focused = 'false'
| Selected = 'false'
| Actions = [OnClick, RequestFocus]
| MergeDescendants = 'true'
|-Node #145 at (l=537.0, t=841.0, r=663.0, b=967.0)px
| Text = '[Thursday, January 18, 2024]'
| Role = 'Button'
| Focused = 'false'
| Selected = 'false'
| Actions = [OnClick, RequestFocus]
| MergeDescendants = 'true'
|-Node #148 at (l=663.0, t=841.0, r=789.0, b=967.0)px
You can then interact with those DatePicker elements by clicking on them, i.e.
composeTestRule.onNodeWithText("Tuesday, January 16, 2024").performClick()
Related Questions in ANDROID-JETPACK-COMPOSE
- android-pdf-viewer Received status code 401 from server: Unauthorized
- Inject a class into a composable function using hilt
- preventing duplicate text
- Jetpack compose - how I can hookup LiveData property from ViewModel with TextField in activity?
- MarkerInfoWindow doesn't hold the clicked marker position after list refresh in Compose Map
- How do you import functions from one page to another in Jetpack Compose?
- Jetpack compose ViewModels - should I have one ViewModel for different api calls?
- Change background color of clicked sentence in Text
- How to add and retrive pdf file on firebase in jetpack compose
- Made a widget with glance API in Jetpack Compose. Button filling the whole widget
- Jetpack Compose how to reverse edge-to-edge when leaving composition
- Can Anyone help me to load pdf file from firebase to user app by URL in jetpack compose?
- PullRefreshIndicator circle always displaying on jetpack compose
- Android Studio Using recently added resources in compose preview in multi-module project
- Android compose animations crashing in release builds
Related Questions in ANDROID-DATEPICKER
- Material date picker not showing
- Android date picker to select a single day or a range of dates
- There is an issue with the MaterialDatePicker text color when manually entering the date in Android
- Jetpack Compose DatePicker is taking empty space even if title and headline are empty
- Calendar View not showing in android DatePicker
- Android MaterialDatePicker open on year selector
- Enable Specific Dates in Material Date Picker
- Android studio making only list of dates selectable in date picker
- How to replace Arabic numbers in DatePickerDialog itself with English numbers while still using Arabic strings in Android?
- DatePicker in MAUI appears full screen and aligned to the left-top corner in Android
- Jetpack Compose UI Test with Material3 DatePickerDialog
- Android Studio DatePickerDialog doesn't display the calendar
- Date Picker implementation for Android Jetpack Compose
- how can i use correct context in date picker in fragment
- Highlight previous selected dates in Material Date Picker Android
Related Questions in DATEPICKERDIALOG
- Change font of DatePickerDialog Calendar
- Android how increase the font size of Month Selector of DatePickerDialog
- How to change the values of days in DatePickerDialog
- How to replace Arabic numbers in DatePickerDialog itself with English numbers while still using Arabic strings in Android?
- Jetpack Compose UI Test with Material3 DatePickerDialog
- DatePickerDialog and TimePickerDialog do not use black overlay
- How can i disable specific and multiple date calendars in Android Kotlin
- Two issues with DatePickerDialog (Android/Kotlin)
- Is there a less verbose way to get a DatePickerDialog's value?
- How can detect click cancel of DatePickerDialog?
- Setformatter(new NumericMonthFormatter()) & SetDisplayValues(null) are not working in Android version 5.1.1
- Showing current date onwards in DatePickerDialog (Xamarin Android C#)
- SetFormatter method implementation for convert Number to string in Xamarin Android
- How to show Material Calendar with all disabled dates in Android datePickerDialog
- how to find the difference between datepicker in kotlin
Related Questions in GUI-TESTING
- How to programatically set appID for Maestro tests based on platform
- MaterialButtonToggleGroup Toggles Not Visible During Android Espresso Tests
- Possible to set up Android Compose UI testing without passing the composeTestRule around?
- Is there any way to run UITests with out launching iOS Simulator
- Cannot interact with GUI element with WinAppDriver in Azure pipeline
- Is it possible to write ui tests/preview with Glance Compose?
- Patrol: Allow Modify System Settings in Android
- Karate: How to run Karate UI tests with Github Actions?
- Can not drag widget while I am writing UI test for Android widget with UIAutomator
- Robo test question: How to get the app to open a deeplink first before start testing actions defined in robo script?
- How can you do end-to-end UI testing for Telegram bots?
- Given component holder class androidx.activity.ComponentActivity does not implement interface dagger.hilt.internal.GeneratedComponent
- I am not able to test android composable UI getting "FINGERPRINT must not be null" Error
- How to add test ids to Stream Chat React Native
- How to take a screenshot of a loading spinner in playwright(ts / js)?
Related Questions in ANDROID-JETPACK-COMPOSE-MATERIAL3
- Change background color of clicked sentence in Text
- I want to design this type of image slider with jetpack compose Android
- Problem using HorizontalPager in Jetpack Compose
- OutlinedTextField placeholder, not changing color in Jetpack Compose
- Material 3 Bottom App Bar - Centered FloatingActionButton moved icon to the left instead of right
- Google Font does not apply on android 8 in compose
- Paging 3 Library with Jetpack Compose Not calling the load method after initial load
- How do I create a list where I can track states and still not create a new one each time? (jetpaŅk compose)
- After adding splashscreen to my app, app has a white border when screen is rotated
- Scrollbar within a TextField Composable
- Specification for the 'top level' Material 3 transition
- How to get a datepicker like in the official Contacts app?
- Compose BOM 2024.02.00 breaks dynamic theme on physical devices
- Jetpack Compose Material 3 SearchBar in Scaffold Scrolling Issue
- Mutable state of empty List
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
The M3
DatePickerDialogis built using compose unlike the M2DatePickerDialog, so in order to test it, you need to know what the nodes look like. While theDatePickerDialogis active, you'll have multiple roots, so in order to get the node tree for theDatePickerDialog, you'll want to usecomposeTestRule.onAllNodes(isRoot()).get(1).printToLog("T:")to print out your node tree and examine how theDatePickerDialogworks.The dates within the date picker can be selected using
onNodeWithText, though the actual text to match isn't just the day of the month as it appears in the dialog. Instead, you'll need to match dates written out such as'Wednesday, November 15, 2023'. This is easy enough to do usingDateTimeFormatterusing the patternEEEE, MMMM d, yyyy, but be aware that the current date is also prefixed with 'Today' (Today, Thursday, November 16, 2023)Other controls within the
DatePickerDialogalso respond toonNodeWithTextsuch as the OK/Cancel buttons, oronNodeWithContentDescription, such as navigating the months or setting a year.