Search code examples
xamarintestingpopupxamarin-test-cloud

How to check whether an UI element exists without failing Xamarin Test Cloud?


I am using Visual Studio C# with Xamarin to develop an iOS app. I have an UI automation which runs in Xamarin Test Cloud.

I want to check if a pop up window exists, and if it exists I want to dismiss it, othervise test should just continue. The code I am using in the test method is like below:

try
{
    app.WaitForElement(x => x.Text("Update available"));
    app.Tap(x => x.Marked("Ignore"));
}
catch (TimeoutException)
{
    // TODO: This catch doesn't work. Test in cloud still fails.
}

The problem is that the catch doesn't work. When the test runs in Xamarin Test Cloud, the test still fails with time out error finding the element.

Does anyone know how to do it without failing the test?


Solution

  • You can use the app.Query method to check if the element exist if you want to avoid using the WaitForElement

    The app.Query returns array of elements for the query