简体   繁体   中英

How to detect window content change in WPF?

I want to develop a tool for test automation. I have source code of the application under test, so I have the privilege to add some custom logic inside the app.

One part of the custom logic is to detect the content change, analyze the change and finally report the result outside to the test tool, such as: a message "the login window is ready" followed by locations of user_id and password control.

By using VisualTreeHelper and LogicalTreeHelper class, I can know the current status of the window, but I do not know WHEN to walk through the tree.

I found a similar question but this is for 3rd party window, I guess there may be better solution for app that I have access to source code.

In win32, I can hook WM_PAINT to detect window content change. Do you have any hint about how to do this in WPF?

By the way, although I would like to add custom logic to the app, I also want to change the app logic as little as possible.

I am new to WPF, sorry if anything totally wrong.

You might want to specify exactly what you want to achieve, like describing an examlpe of what you want to do.

Are you aware of the VisualTreeHelper class? https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.visualtreehelper

Based on what you said you wanted to achieve. I would probably subscribe to some "ready" or "loaded" event of a UI element. You should be able to get access to the UI element through the VisualTreeHelper.

You should also be able to interact with the UI elements through it, eg. click and enter information. And you could also run tests based on the state of the UI (I think).

I'm also sure there are plenty of Automated UI Testing frameworks for WPF, just Google: "automated UI Testing frameworks for WPF".

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM