我有一个 WPF 应用程序,我正在尝试自动化 UI 测试。我正在使用FlaUI
这个。我也NUnit
用作测试框架。我的应用程序使用DevExpress
控件,目前我面临一个问题,即我无法Visibility of my progress bar
从我的单元测试应用程序中检查。使用FlaUI
我能够launch
应用程序并获取Window
句柄,但应用程序需要一些时间来设置visibility
. UI elements
由于 UI 加载需要时间并且它由进度条控制,我正在寻找一种机制,我的测试项目可以在其中检查进度条的可见性changed
,然后继续执行测试用例。这是XAML
来自 WPF 项目的控件
<ProgressBar AutomationProperties.AutomationId="showProgress"
Grid.Row="1"
Height="4"
Margin="0"
BorderThickness="0"
IsIndeterminate="True"
IsTabStop="False"
ToolTip="Contacting Server, Please Wait..."
Visibility="{Binding IsServerActive, Converter={StaticResource MwBoolToVisibilityConverterReverse}}" />
<views1:VoyageEditorControl Grid.Row="2" Grid.Column="0" />
下面是我的Nunit
框架中的代码
[TestFixture(AutomationType.UIA3)]
public class UnitTest1 : FlaUITestBase
{
public AutomationType AutomationType { get; }
protected override ApplicationStartMode ApplicationStartMode => ApplicationStartMode.OncePerFixture;
public UnitTest1(AutomationType automationType)
{
AutomationType = automationType;
}
protected override AutomationBase GetAutomation()
{
return UtilityMethods.GetAutomation(AutomationType);
}
protected override Application StartApplication()
{
string executableLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string projectPath = executableLocation.Replace("BP.GIS.Synergy.ShipTracker.UITests", "BP.GIS.Synergy.ShipTracker");
string exeLocation = Path.Combine(projectPath, "BP.GIS.Synergy.ShipTracker.exe");
var app= Application.Launch(exeLocation);
app.WaitWhileMainHandleIsMissing();
return app;
}
#region Test cases
[Test]
public void getAppHandleFirst()
{
// Thread.Sleep(10000);
var mainWindow = Application.GetMainWindow(Automation);
var elementName = mainWindow.FindFirstDescendant(cf => cf.ByAutomationId("AvailableViews")).AsComboBox();
Assert.That(elementName.IsEnabled, Is.True);
Action action = () => elementName.Click();
RetryResults retryResult = Retry.While(action, TimeSpan.FromSeconds(1));
bool isCompletedSuccessfully = retryResult.IsCompletedSuccessfully;
}
[Test]
public void checkAppLoadProgress()
{
var mainWindow = Application.GetMainWindow(Automation);
var elementName = mainWindow.FindFirstDescendant(cf => cf.ByAutomationId("showProgress")).AsProgressBar();
}
简而言之,该方法getAppHandleFirst()
和其他方法应该只在进度条从屏幕上消失后才开始执行。