androidxamarinuitest

Cannot Android Xamarin Forms UITest to click on DisplayAlert button


I'm using Xamarin UITest to perform UI unit tests. I cannot figure out how to get the UITest framework to click on the DisplayAlert(...) buttons.

// this query finds the YES button on the Alert
app.WaitForElement( c => c.Marked( "YES" ).Parent().Class( "AlertDialogLayout" ), "ERR", TimeSpan.FromSeconds( 1 ) );
// but tap with the same query doesn't click it
app.Tap( c => c.Marked( "YES" ).Parent().Class( "AlertDialogLayout" ) );

Solution

  • Surprisingly, at least to me, app.Tap() doesn't require nor accept a query to find either popup button that app.WaitForElement() does. The following works:

    // this query finds the YES button on the Alert
    app.WaitForElement( c => c.Marked( "YES" ).Parent().Class( "AlertDialogLayout" ), "ERR", TimeSpan.FromSeconds( 1 ) );
    // but tap with the same query doesn't click it
    // but "YES" does!
    app.Tap( "YES" );