Page 1 of 1

Is there a way to simulate button presses / mouse clicks for testing purposes?

Posted: 15 Aug 2022, 20:52
by samc
Hello-

I'm wondering if anyone has found out a good way to simulate button clicks or just generally input into Noesis Engine for automated testing purposes. Anyone have suggestions / pointers?

thanks,
sam

Re: Is there a way to simulate button presses / mouse clicks for testing purposes?

Posted: 15 Aug 2022, 22:45
by jsantos
Yes, NoesisView exposes the following methods to manually inject input:
  • KeyDown
  • KeyUp
  • Char
  • MouseMove
  • MouseButtonDown
  • MouseButtonUp
  • MouseDoubleClick
  • MouseWheel
  • TouchMove
  • TouchDown
  • TouchUp

Re: Is there a way to simulate button presses / mouse clicks for testing purposes?

Posted: 18 Aug 2022, 12:23
by maherne
To add to Jesús answer. A pattern I have used in the past, to make finding and interacting with particular elements in the current view, is to create an attached property which registers the element in a static map using the element's Name as a key. You can then access this static map from your automation scripts, allowing you to find out if the element exists, and get it's position to interact with (e.g. using View::MouseButtonDown), or to assert that it's dependency properties are in the correct state.

In XAML the attached property would look something like this:
<Button x:Name="helpButton" local:ViewDebug.Register="true" />
The attached property changed callback would add/remove the element from a static map.
And the ViewDebug class would have a static API, something like:
ViewDebug::HasElement("helpButton");
const FrameworkElement* = ViewDebug::GetElement("helpButton");
This setup only allows for one element per name, but you can bind a dynamic value to the element's name, such as adding a index to the end of a Name for items in a list.

If you want more information on this, please let me know.