Accessing the UI controls of a WPF project from Unit Test project once the progress bar has finished loading
I have a WPF application and I am trying to Automate the UI testing. I am using FlaUI
for this. I am also using NUnit
as the testing framework.
My application uses DevExpress
controls and currently I am facing an issue wherein I am not able to check the Visibility of my progress bar
from my Unit Test application.
Using FlaUI
I am able to launch
the application and get the Window
handle but the application takes some time to set the visibility
of the UI elements
.
As the UI loading is taking time and it is governed by a progress bar, I Am looking for a mechanism wherein my Test Project could check if the progress bar's visibility is changed
and then go ahead and execute the test cases.
Here is the control's XAML
from the WPF project
<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" />
Here below is the code from my Nunit
framework
[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();
}
In short, the method getAppHandleFirst()
and others should only start executing once the progress bar is gone from the screen.