Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I verify the state of a WPF checkbox during a UI Automation Unit Test using the Windows Application Driver?

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 :-(
}
like image 285
Susan Arnold Avatar asked Oct 28 '22 10:10

Susan Arnold


1 Answers

Thank you very much, PixelPlex! That is the answer. I also had a look at this answer. Now it works :-)

Assert.IsTrue(CheckBox1.Selected);
like image 60
Susan Arnold Avatar answered Nov 15 '22 06:11

Susan Arnold