Waiting for Scrollbars fade out

Hi,

I have a .NET MAUI App I test with Appium and UiAutomator2. In the test, I take a screenshot of my Views and compare them to references screenshots.

In the tests for Android on Android Emulator, I often have a problem with ScrollBars of my ScrollViews. The Scrollbars are often slowly fade out when I switch Views. I can’t figure out the right time to wait until I can take the screenshot of my current View and compare.

I tried to identify them with the Appium Inspector, but couldn’t find them.

Is there a way, how I can detect when the ScrollBars are fade out fully and not visible anymore.

You can try disable animation on phone.
This can be done on phone in developer menu or using capability appium:disableWindowAnimation

Hello Aleksei,

first of all, thank you very much for your response! I was happy to read about it and hoped to have the solution, now.

On my Android Emulator Pixel 5 - API 34 (Android 14.0 - API 34) I could not find a switch in the emulator settings that disabled it.

I liked the option to set it directly in my Appium options or settings in C# and tried like this:

var options = new AppiumOptions
{
    PlatformName = "Android",
    PlatformVersion = "14.0",
    DeviceName = "Pixel_5_API_34",
    AutomationName = "UiAutomator2"
};
...
options.AddAdditionalAppiumOption("disableWindowAnimation", true);
...

… and like this:

var options = new AppiumOptions
{
    PlatformName = "Android",
    PlatformVersion = "14.0",
    DeviceName = "Pixel_5_API_34",
    AutomationName = "UiAutomator2"
};
...
options.AddAdditionalAppiumOption("appium:disableWindowAnimation", true);
...

or

driver = new AndroidDriver(_appiumService.ServiceUrl, options);
driver.SetSetting("appium:disableWindowAnimation", true);

Unfortunately, none of them worked with [email protected] (automationName ‘UiAutomator2’).

And you can still see how the ScrollBars on the right of the screen and in the middle fade out slowly. This I wanted to disable in the test.

Am I missing something or doing something wrong?

Ok. While nothing left we have 2 options:

  • ask dev to disable it or to disable when you start app with some flag
  • add a bit sleep after you make scroll action in test

Good luck

Do you have a clue why this might not have been worked? When you mentioned this setting, I looked for it and found it in the Appium docu.

Is there anything I did wrong or is this something which is not supported by my emulator or UiAutator2 so that I should switch to a different one?

You mean that I should disable ScrollBars in my .NET MAUI ScrollViews in general or in the tests with some flag. I can also try this, but is scrolling then disabled or they are just not showing up? Is there a way to disable them system wide via Appium Settings on startup of the tests? Just a setting in the test would be the option that appears to be most useful. If this is possible system wide it would even be better. If not possible, I would try it in my App for all ScrollViews…

Just not all animation setting covered by animation settings available to user. Question to Android OS developer - Google.

Yes.

I deactivated the ScrollBars in general with a Flag transported as an Intent to my .NET MAUI App (in the Android Platform Section MainActivity.cs - OnCreate(...)-Method). The ScrollBars are deactivated via .NET MAUI ScrollViewHandler.

// Retrieve the "isTestExecution" parameter provided by Appium to determine if the application is in test execution mode
bool isTestExecution = Intent?.GetBooleanExtra("isTestExecution", false) ?? false;

// Obtain the AppExecutionState service and update its IsTestExecution property
var appExecutionState = ServiceHelper.GetService<AppExecutionState>();
if (appExecutionState != null)
{
    appExecutionState.IsTestExecution = isTestExecution;
}

The ScrollViewHandler to remove the ScrollBars was added as follows also in the MainActivity.cs:

// Register Handler to set the ScrollBar visibility based on the IsTestExecution flag and don't show them in tests
var appExecutionState = ServiceHelper.GetService<AppExecutionState>();
if (appExecutionState?.IsTestExecution == true)
{
    Microsoft.Maui.Handlers.ScrollViewHandler.Mapper.AppendToMapping("ScrollBarVisibilityInTests", (handler, view) =>
    {
        handler.PlatformView.SetVerticalScrollBarVisibility(ScrollBarVisibility.Never);
        handler.PlatformView.SetHorizontalScrollBarVisibility(ScrollBarVisibility.Never);
    });
}

Unfortunately, I have a View which has a DevExpress DXCollectionView that comes with its ScrollBars. This is a Control, which is probably not developed in .NET MAUI, but some native/platform code. For this the ScrollBars are not deactivated.

I could detect it as a NestedScrollView in my Handler-Code. For this, I don’t see corresponding methods to set the ScrollBar visibility. It also did not work to enable/disable them. I also tried to set the Fade-out times and the time to wait until fade-out starts by setting them to 0. But, no chance so far that they disappear or don’t fade out so slowly.


In my Test, I also determined the corresponding element which according to the Appium Inspector would be:

var element = App.FindElement(By.Id("com.myapp.app:id/dx_vertical_scrollview"));

But, I do not know what could be a way to hide the ScrollBars from this element.

Do you know anything for such components and how I could get them to disappear?

Problem in my tests really often is that the Screenshots are taken when ScrollBars are still not fade out completely and unless wasting time and setting a wait time of 5 seconds each test, I don’t know if there could be a way to get rid of the ScrollBars?

Finally, I got it!

In case somebody else wants to know how I could achieve it. The Handler for the DevExpress DXScrollView needs to be extended like this so that it is possible to set the ScrollBars invisible. This could also be combined with the Flag described in my response with the Intent from the Test Code, so that the DXScrollViewHandler sets them only invisible when in Test Code:

// Register DXScrollView with ScrollViewHandler
handlers.AddHandler<DXScrollView, DXScrollViewHandler>();

// Extend the Mapping for the DXScrollViewHandler
DXScrollViewHandler.ViewMapper.AppendToMapping("DisableScrollBars", (handler, view) =>
{
#if ANDROID
    if (handler is DevExpress.Maui.CollectionView.Internal.DXCollectionViewHandler dxScrollView)
    {
        dxScrollView.PlatformView.ScrollBarVisible = false;
    }
#endif
});