How to identify a winforms button control that has no AutomationId? - c#

I've been tasked to find out how to implement UI automation for desktop apps with appium-dotnet-driver. I've successfully managed to use the windows calculator app for UI unit testing.
That being said, having a lot of trouble with my company's winforms app because some elements either don't have an AutomationId or it changes every time something is clicked on the program.
Is there an easy way to define the AutomationId for a control type (i.e. Button)?

Solved by setting the Name property of relevant controls. AutomationId is automatically inferred from Name or Text properties. Hope it helps someone.

Related

Is it possible to read data from Pane control type?

I've started using FlaUI for Automating my thick client .net application. The application is Windows Form based. The start was good and Login Form was identified and I could Login, but after that came the dead end and I found that almost everything in the application is developed as Pane control type.
So, there is grid, table etc. but they all just appear as Pane type when I see the object hierarchy using Inspect.exe or FLAUInspect tools. And nothing really appears in thier property, so it seems that nothing could be read. But before giving up I just wanted to check with experienced audience on this forum if there is really any way to get the data from Pane objects.
Please suggest if there is any way, even that means using other libraries like UIAutomation, TestStack.White, etc.
UPDATE: I now understand little more about this. So, the objects that are there in the pane are developed in syncfusion and devexpress. Is it possible to identify objects developed in syncfusion and devexpress using FlaUI or UIAutomation or TestStack.White, etc ?
I don't know if you have already tried the following steps. Have you add automationId's to your objects in xaml code with:
AutomationProperties.AutomationId="AnyID"
In the testcode, first initialize the main window of the application.
MainWindow = fApplication.GetMainWindow(fAutomation, null)?.AsWindow()
After that you can find your objects by the automationId's, like:
MainWindow .FindFirstDescendant(cf => cf.ByAutomationId(AnyID))
I did it this way, and don't have to know the hierarchy of my application. Maybe this will work?
Most UI Frameworks nowadays fully support UI Automation. So first make sure that you have a recent version of your framework (syncfusion, devexpress). In addition, some frameworks provide settings to enable UI Automation. Like for devexpress, you need to set
ClearAutomationEventsHelper.IsEnabled = false;
at the start of your application to test so it exposes way more things (like tabs) to FlaUI.

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

No information about DevExpress controls in automation app

i'm writing because I have some hard times trying to get any automation-useful information about DevExpress controls. I do not have ability to see source code of application I'm testing, but UISpy and all other UI verifiers out there don't provide any information, including name, automationID and so on. The only thing that is available is info such as runtimeID, dynamically-assigned automationID and control type. Is there any chance to recognize these controls to get their unique properties? I know it must be some way since Visual Studio does that..
White is a wrapper for Microsoft's UI Automation Framework. As such, it uses Conditions on AutomationElemements' properties in order to find the appropriate element. UISpy is basically a visual reflection of what the UIA 'sees'. There are no other 'low level' properties.
Unfortunately, many developers and control vendors don't pay attention to setting a unique and indicative value for the AutomationID or Name properties, and thus make it hard to get the element you need.
The best solution I could give you is to create a helper method that works directly with UIA rather than with White, which gives you more flexibility in searching for your control. For example, if you have a DevExpress GridView, you could get all its child elements and query every single one of them for their relative position on the screen.
You could try with UI Automation Verify (UIA Verify). It will help you obtain the automationID.

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

Categories