How to Swipe CarouselView with Xamarin.UITest
CarouselView’s UI structure
If you show the UI tree of Xamarin.Forms CarouselView control with Repl() method, you will notice the class names are different in each platforms (iOS/Android).
- iOS : Xamarin_Forms_Platform_iOS_CarouselTemplatedCell
- Android : CarouselViewRenderer
Therefore, you need to query to specify the carousel view element in your app by using AppQuery.Class. This is the code snippet of IApp.SwipeRightToLeft method to swipe the carousel view.
Sample codes
By using Microsoft demo app, I wrote the sample codes that swipe CarouselView on GitHub.
In this sample code, the panel on the center of the screen will be swiped until the specific monkey name panel will be shown on the screen.
You can use IApp.WaitFor method to swipe the panel until the panel that you want will appear on the screen. When you use IApp.WaitFor method, you would have to change the query to check the monkey name.
In iOS app, the UILabel class, which is the descendant of the Xamarin_Forms_Platform_iOS_CarouselTemplatedCell class has the text of the monkey name.
In Android app, the monkey name is set in the text property of the LabelRenderer control.
Here is the sample codes where the Xamarin.Forms CarouselView control is swiped with Xamarin.UITest.