【问题标题】:Cannot Android Xamarin Forms UITest to click on DisplayAlert buttonAndroid Xamarin Forms UITest 无法单击 DisplayAlert 按钮
【发布时间】:2020-03-28 15:44:40
【问题描述】:

我正在使用 Xamarin UITest 执行 UI 单元测试。我不知道如何让 UITest 框架点击 DisplayAlert(...) 按钮。

// 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" ) );

【问题讨论】:

  • 你可以参考这篇关于使用 Xamarin.UITest forums.xamarin.com/discussion/90847/…处理弹出窗口的帖子
  • @LeonLu-MSFT 我做到了,但我看不到如何在您的链接中单击弹出窗口上的 OK。我的问题专门针对找到“确定”按钮但不会点击或单击它的查询。

标签: android xamarin uitest


【解决方案1】:

令人惊讶的是,至少对我来说,app.Tap() 不需要也不接受查询来查找 app.WaitForElement() 所做的任何一个弹出按钮。以下作品:

// 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" ); 

【讨论】:

  • 我必须将 app.Repl(); 添加到我的测试中才能看到 DOM 树,这表明我的“是”按钮在此之前实际上被命名为“button1”。是的,我还使用DisplayAlert 来显示弹出问题。我猜我正在使用与此答案不同的实现DisplayAlert 的版本或包。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多