c# - 等待应用程序启动而不使用 Thread.Sleep() 使用 FLAUI
问题描述
我是使用 FLAUI 和自动化测试的新手,想用它来测试我的系统。目前我正在使用 Thread.Sleep() 等待应用程序启动,然后找到登录文本框。有没有比使用 Thread.Sleep() 更有效的方法来做到这一点?
目前我启动应用程序并使用 Thread.sleep(10000) 等到应用程序完全启动并且在单击控件输入密码进入应用程序之前可以找到登录文本框。但是我知道 Thread.Sleep 是告诉系统等待的最糟糕的方法,尤其是在自动化测试中。谁能提供我可以测试的任何其他东西?
解决方案
最好使用重试机制并等到主窗口加载并且控件可见。例如,在调用 Application.Launch 后,您最多可以重试 30 秒以找到主窗口,并在其中输入 txtLogin:
Retry.WhileException(() =>
{
using (var automation = new UIA3Automation())
{
Window mainWindow = Application.GetMainWindow(automation, TimeSpan.FromSeconds(60));
Assert.IsNotNull(Mainwindow, "Main window is not found");
TextBox loginTextBox = mainWindow.FindFirstDescendant(x => x.ByAutomationId("txtLogin")).AsTextBox();
Assert.IsNotNull(loginTextBox, "txtLogin is not found");
}
}, TimeSpan.FromSeconds(30), null, true);
推荐阅读
- regex - 使用 REGEX 按逗号关键字选择逗号
- gremlin - 在遍历中访问和比较存储边的属性
- c# - .net 核心中未经授权用户的 AccessDenied 页面,returnUrl 不正确
- javascript - 为什么我不能在 populateViewHolder 中显示 FirebaseRecyclerAdapter?
- mysql - 从 Laravel 中的 Excel 文件导入数据时检查字段是否为空?
- excel - 如何防止excel将日期显示为数字
- sql-server - SSMS 能否在 Azure Synapse 中显示实际的执行计划?
- reactjs - 我正在使用导航来导航我的反应本机应用程序,但我无法通过此问题付款。我按照文档做了,但对我没有用
- react-native - 如何添加全局事件监听器
- javascript - Vue JS - 如何绑定按钮的值然后单击将值保存到本地存储