locked
Xamarin.Forms and Xamarin.UITest: how to manage ScrollUp? RRS feed

  • Question

  • User167645 posted

    I would like to implement some UI Tests in a Xamarin.Forms app, by using Xamarin.UITest.

    On my main page, I have a ScrollView that contains some informations in Labels, like a phone number, an address, an email, ...

    The XAML looks like this:

    <ScrollView x:Name="parallaxScrollView"
                HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand"
                AutomationId="ContentScrollView">
        <!-- ... -->
        <!-- Phone -->
        <yummy:PancakeView Style="{StaticResource YummyFrame}"
                            Padding="16">
            <Grid RowSpacing="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Label Grid.Row="0"
                        Style="{StaticResource HomePageHeaderLabelStyle}"
                        Text="{x:Static strings:Strings.HomePagePhoneNumberHeader}">
                <Label Grid.Row="1"
                        Style="{StaticResource HomePageLabelStyle}"
                        Text="{Binding PhoneNumber}" />
            </Grid>
        </yummy:PancakeView>
        <!-- ... -->
    </ScrollView>
    

    I would like to check that all expected informations are well displayed.

    The 2 first items are always visible, so I only have to do this in my UI test:

    AppResult[] results = app.WaitForElement(t => t.Marked("Phone number"));
    app.Screenshot("HomePage");
    Assert.IsTrue(results.Any());
    

    But for the following items, I have to scroll up before the other informations are visible. So I've tried to to use the ScrollUp() based on a Label or on the ScrollView, but nothing happens:

    app.ScrollUp(c => c.Marked("ContentScrollView"));
    AppResult[] results = app.WaitForElement(t => t.Marked("Email"));
    //AppResult[] results = app.WaitForElement(t => t.Marked("Phone number"));
    app.Screenshot("HomePage");
    Assert.IsTrue(results.Any());
    

    I also tried to use the ScrollUpTo() method but I get the same result.

    I didn't found a sample in a Xamarin.Forms project, so I'm not sure to well understand this... Could you help me?

    Friday, December 11, 2020 3:13 PM

All replies

  • User167645 posted

    I've managed to achieve this by applying the scroll using ScrollDown. I don't understand why, as the gesture is well a scroll from bottom to top...

    Saturday, December 12, 2020 10:29 AM