How to detect window content change in WPF? - c#

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://learn.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.

Related

How to create a window within a UWP app to enter in detail/properties information

So I'm sure there's an easy way to do this but I don't know the exact terminology for what I'm wanting.
Essentially in my C# xaml uwp app I have a couple objects that need to have details added to them, kind of like file properties. I have a button that I would like to open up another window (still part of the app), just to enter in the properties. I just don't know the terminology to look up what this window would be called or find documentation for it. So the exact same as when you're in a file browser and you open the properties of a file; it opens in a little extra window that you can drag around.
I don't want to be able to use the main window while the properties window is open, and of course they need to be able to transfer data between one another.
In my previous apps I've simply made a grid that appears over everything else in the middle of the app and shaded the outer area. A workaround as I didn't know how to do this.
Can anyone help me out?
Maybe you can use Dialog refer to https://learn.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/dialogs-and-flyouts/dialogs.
Dialog controls are modal UI overlays that provide contextual app information. They block interactions with the app window until being explicitly dismissed. They often request some kind of action from the user.

UI test builder is not tracking UI objects

I am working on UI automation using VS coded UI test builder, is there a way to track control ids from UI? I am getting co-ordinates for input capture windows for controls which is not useful while rerunning test. eg. Mouse.Click(passwordReset, new Point(408, 398)); I did some research on msdn http://msdn.microsoft.com/en-us/library/dd286671.aspx and tried to but nothing seemed to map UI controls without co-ordinates. Please advise.
This should help out a bit. You really want to use SearchProperties which uses the AutomationId (WPF) or Name (WinForms: Name is equivalent of SearchProperty Id and Text is equivalent to SearchProperty Name if my memory serves me right, doesn't make a whole lot of sense). I'm not exactly sure how you do this but we had to go back into our WPF views and add AutomationId's to every control so my coworker could select them when he was setting up automated testing.

Developing wizard UI - WPF

All in WPF:
Developing a wizard application, user has to answer a number of simple questions before brought to the main app. The main app is then prefilled with the information obtained from the wizard.
I started with a Window which I then planned to add usercontrols to. The main window would have the user control in the first row, then Next and Previous buttons to control moving between the controls in the second row. This way I could easily control the logic to switch between screens like:
WizardControl1.IsVisible = false;
WizardControl2.IsVisible = true;
But for some reason, user controls do not have setter for IsVisible. Hurray.
So then I thought I would just use seperate windows for each section of the wizard. The problem with this approach is that now when stepping between, the window opens in random positions, and by steppign through the wizard with next, the next window pops up randomly which is really distracting and frustrating.
So how can I develop a wizard properly? I don't get why this is so hard...not exactly rocket science... replacing text and controls and storing input after pressing next/previous!
Thanks
Check this link:
http://www.codeproject.com/KB/WPF/InternationalizedWizard.aspx
This is the article about building wizard in WPF by Josh Smith, it's seems to be nice pattern.
I found it's helpful for me, hope you'll too.
There is also an open source Avalon Wizard control on codeplex.
I'd probably aproach this using data binding and template selectors. Have the wizard form bind to a "WizardData" class, which exposes a list of "WizardPage" base classes.
The WizardData class can expose properties defining the correct info on the forms, and display a control for the main page that uses a template selector to determine the proper control to display based on the actual type of the particular wizard page.
It sounds like more work than it is, really. It also gives you the benefit of good separation between code and UI (all "work" is done by the WizardData and WizardPage classes), and the ability to test logic independent of the UI.
It's also a very WPF/MVVM way of approaching the problem.
I recognize this does not directly address your question, but I thought I'd mention it as a possible alternative. I've used Actipro's Wizard control with pretty good results, and when I have needed support, they have been very responsive. I am not affiliated with them in any way; I just like not having to write the plumbing to manage a wizard.
The property is called "Visibility".
I find that I do better when I dynamically add and removing controls rather than hide them.
I was looking for a Wizard solution too. I have the need to stick with stock WPF components so I implemented the wizard using a standard form and a tab control.
I only hide the tabs at runtime so there available in the IDE. At runtime just use Back, Next, Finish... to navigate thru the tab items
works good

How do read/interact with an old ActiveX SSUltraGrid using UIAutomation

I am investigating automated testing of an old Win32 application that used ActiveX controls. I am spiking use White (from Thougthworks) that uses Microsoft UIAutomation. I can find the AutomationElement related to the control, but how do I interact with it?
Spy++ sees the grid control as a single window, so I can't talk to rows, columns, or cells directly. How do I talk to the SSUltraGrid control from my test code?
Cheers
Nigel
The basic problem with some ActiveX and other custom controls like SSUltraGrid is what you mentioned, they're presented as just one window. So unless they've provided an API that makes them "friendly" to your GUI automation tool, you'll always face this challenge. Of course many companies offer newer versions of their products that are friendlier to UI Automation than before... perhaps upgrading the control is worthwhile...
Failing that... what the test engineers at my job have told me is that when they encounter that situation, if there are well known keystrokes to invoke the activity they desire, they send keystrokes to the control window. If they're lucky enough to have things in a fixed location, they might even be able to get away with sending mouse events. However, that's dicey at best.

Non intrusive 'live' help system

I'm searching a C# component or code snipped that does something like that:
I want to inform new users about the most important program functions if he opens a new window for example.
It should be a box showing text (formated if possible) that is of course not modal and has some mechanism to 'go out of the way' if the user enters the textbox area. So that he can access what's underneath it. Alternativly the window could also stick to the border of the window, but there needs to be a way that this also works if the window is maximized.
So I want to present him with a short introduction of what he can do in every corner of my app most painlessly.
Thank you!
I use a "bar" at the top of every window to display some information about the current window/dialog.
Use tooltips. They can be programmatically controlled, and you can have them appear at will. You'll need to add the functionality to your app to keep track of what tooltips have been shown to the user already.
You can add a "balloon" style by setting the IsBalloon property to true.
You can also replace them with smaller descriptions for when the user wants to hover over the control and have them displayed again.
I'm already using tooltips heavily. However, they aren't very practical when displaying bigger amounts of data and they are bound to specific user actions.
Have you considered having a contextual menu for each form / page which contains links to Adobe Captivate style presentations for each available task? That way the user can investigate an example of how to achieve a task relating to what they are trying to achieve from within the application / site.
This approach would require a good deal of maintenance and management if your code changes regularly but coordinating it with a training department can provide rich help features in your application.
See http://www.adobe.com/products/captivate/ for more information.

Categories