My simple WPF application includes a check box. I am trying to test this application automatically with the Windwos Application Driver. After creating a session the check box is clicked. Afterwards I want to verify if the checkbox is checked. But the type of the check box object is WindowsElement so my code can not work.
In other words: How do I get access to these control types in a WinAppDriver test?
https://learn.microsoft.com/en-us/windows/win32/winauto/uiauto-controltypesoverview
<CheckBox AutomationProperties.AutomationId="CheckBox1"/>
[Test Method]
public void TestMethod1()
{
const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
const string SimpleWPFTestID = @"C:\Users\bla\source\repos\SimpleWPFApp\SimpleWPFApp\bin\Debug\SimpleWPFApp.exe";
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", SimpleWPFTestID);
var session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
WindowsElement CheckBox1 = session.FindElementByAccessibilityId("CheckBox1");
CheckBox1.Click();
Assert.IsTrue(CheckBox1.IsChecked); // this line does not work :-(
}
Thank you very much, PixelPlex! That is the answer. I also had a look at this answer. Now it works :-)
Assert.IsTrue(CheckBox1.Selected);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With