C# 在进度条完成加载后,从单元测试项目访问WPF项目的UI控件
我有一个WPF应用程序,我正在尝试自动化UI测试。我正在为此使用C# 在进度条完成加载后,从单元测试项目访问WPF项目的UI控件,c#,wpf,nunit,devexpress-wpf,flaui,C#,Wpf,Nunit,Devexpress Wpf,Flaui,我有一个WPF应用程序,我正在尝试自动化UI测试。我正在为此使用FlaUI。我还使用NUnit作为测试框架。 我的应用程序使用DevExpress控件,目前我面临一个问题,无法从我的单元测试应用程序中检查进度条的可见性。 使用FlaUI我可以启动应用程序并获得窗口句柄,但应用程序需要一些时间来设置UI元素的可见性。 由于UI加载需要时间,并且由进度条控制,因此我正在寻找一种机制,在这种机制中,我的测试项目可以检查进度条的可见性是否已更改,然后继续执行测试用例。 下面是来自WPF项目的控件的XAM
FlaUI
。我还使用NUnit
作为测试框架。
我的应用程序使用DevExpress
控件,目前我面临一个问题,无法从我的单元测试应用程序中检查进度条的可见性。
使用FlaUI
我可以启动
应用程序并获得窗口
句柄,但应用程序需要一些时间来设置UI元素的可见性
。
由于UI加载需要时间,并且由进度条控制,因此我正在寻找一种机制,在这种机制中,我的测试项目可以检查进度条的可见性是否已更改,然后继续执行测试用例。
下面是来自WPF项目的控件的XAML
<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" />
简言之,只有当进度条从屏幕上消失后,才能开始执行方法getAppHandleFirst()
和其他方法
[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();
}