I'd like to select a created DrawingObject to highlight it and show the handles without the user needing to click it. I am using Halcon 13 and tried using SendMouseDoubleClickEvent() (Docu) but this only seems to be available for the new Halcon Smart Window, which is currently not an option for me as it interacts differently with the Halcon-Procedures. I also tried to use SelectObj() (Docu) but this seems to do something entirely different.
I have:
a reference to the HWindowControlWPF
the ID of the HWindowControlWPF
the ID of the DrawingObject
Any help or hint is appreciated!
I could not find a proper solution to this problem but I found a hack that achieves the same result:
First, detach all drawing objects apart from the one you want to show as selected via DetachDrawingObjectFromWindow. Then, reattach them via AtachDrawingObjectFromWindow.
This works because the Halcon Window automatically selects the last attached drawing object.
Related
I have a telerik control (Telerik.WinControls.UI.RadToggleSwitch) which is used to toggle between state 1 and state 2 with "Click and drag (left or right)" to make the toggle effect. I want to do a hand-coded UI test to select a state and proceed further. I need a class to call that control(i assumed it is WinClient).
I need the proper code to perform toggle action. Thanks in advance.
You may handcode your Coded UI Tests but handcoding your UIControls is really troublesome to do as you can never be sure that the Control you added is actually found and everything you did is correct.
A better alternative is to use the UIMap to manually add your controls via the Coded UI Test Builder. It also saves a lot of time.
When the Coded UI Test Builder is open you can hover with your mouse over a control and type "Control+I" to get info on that specific control. If you now click on the << on the infobox that opens you see your UIMap with the control you did "Control+I" over on the left added. But the control is not added yet permanently. From here you can add it permanently by clicking on the square with the green plus sign.
Add Button Icon
Alternatively the easy way is to hover over a control and push "Control+Shift+I".
See also: https://learn.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code
After adding the specific control to the UIMap you may use it by referecing to the UIMap. When coding in the *.cs file of the UIMaps you can reference to it by the "this" statement.
For example:
this.UIWindow.UITitleBar.UICloseButton;
When you want to use it outside of the files of the UIMap you have to create an object of the class of the UIMap and then can use it like above by repacing "this" with the object reference.
For example:
MyUIMapClass uIMapObject = new MyUIMapClass();
uIMapObject.UIWindow.UITitleBar.UICloseButton;
If the file you are coding in is not in the same namespace you have to add a using statement for the namespace of the UIMap (the namespace is defined at the begining of each file in the UIMap).
So for your control I think what you need is Mouse.StartDragging() and Mouse.StopDragging().
public static void StartDragging(UITestControl control);
public static void StopDragging(UITestControl control, int moveByX, int moveByY);
So a dragging towards left would be:
Mouse.StartDragging(UIYourControl)
Mouse.StopDragging(UIYourControl, -20, 0);
And toward right:
Mouse.StartDragging(UIYourControl)
Mouse.StopDragging(UIYourControl, 20, 0);
You should test a bit with the amount you need to drag in each direction for it to register as dragging but I think -20 and 20 should be fine.
I hope I helped a bit. :)
I need to automate 3rd party WPF application. I use
TestStack/White. This application has menu bar that is presented by images. After some actions menu is changing. There presents new images. When I want to click on new image:
Window mainWindow = application.GetWindow("Main window", InitializeOption.NoCache);
Image newTask = mainWindow.Get<Image>(SearchCriteria.ByControlType(ControlType.Image).AndIndex(2));
newTask.Click();
I get exception:
TestStack.White.AutomationException: Cannot perform action on Image.
AutomationId:, Name:, ControlType:image, FrameworkId:WPF, element is
offscreen.
I use Microsoft Inspect for research elements.
When I start tests, Inspect show me that image is offscreen. But if I do these actions manually, it works perfectly and in Inspect this image is not offscreen.
How can I refresh these elements or clear cache of window?
There are ReInitialize and ReloadIfCached methods on Window object. Try those to see if something changes.
Are you sure AndIndex(2) is correct element in that particular situation?
Try using GetMultiple and iterate the collection to see what images you actually have and which are not Offscreen.
WPF automation with White is pretty hard. Try Telerik Testing Framework and White could be supporting framework. It is much more easier that way.
It can be a problem with focus, try to use this before getting image:
mainWindow.Focus(DisplayState.Maximized);
Not an exact answer but the final solution I've got after all these TestStack.White not found elements, table rows, and so on. I started to move it to FlaUI. If something does not work or unstable with White then most likely I can get more stable and fast-executable FlaUI solution.
Fortunatly, such migration can be done with little steps. For example I already have TestStack.White.Application app, then I replace White portion of code with FlaUI like this:
var flApp = FlaUI.Core.Application.Attach(app.Process.Id);
using (var automation = new UIA3Automation())
{
// .. new UI element processing
}
I don’t think that caching is the problem here. You are getting the mainWindow with InitializeOption.NoCache. In Non-cache mode the controls are found on demand. So I presume that the cache is refreshed automatically. (https://github.com/TestStack/White/blob/master/src/TestStack.White/Factory/InitializeOption.cs)
Perhaps the index of the element you want to click is not 2.
Have you tried adding an explicit wait? It sounds like you have only tried adding an implicit wait.(https://github.com/TestStack/TestStack.docs/blob/master/_source/White/Advanced%20Topics/Waiting.md)
So I have a TreeView in C# and I'm loading icons for folders via P/Invoke. It's working, but on icons which are custom (so to speak), they change to some weird icon, as seen in the image below:
On "Regular" folders, i.e. ones without custom icons, this doesn't happen. Also on things like my HDD icons, it doesn't happen. This is the code I'm using to set the icon key
ImageKey = node.FileInfo.UniqueIcon;
SelectedImageKey = ImageKey;
As you can see, there's no way SelectedImageKey is different from ImageKey. However, the icon is still being set as the 0th index of the ImageList.I have confirmed via the debugger that the keys are staying the same, after the object is added.
So any ideas why this would be happening only for some icons?
Thanks.
Update
I found a workaround, but I'm not calling it a solution. If I add this to my code:
private void FolderTree_BeforeSelect(object sender, TreeViewCancelEventArgs e) {
e.Node.SelectedImageKey = e.Node.ImageKey;
}
I'm not calling it a solution, because that command only has to run once for it to work. I know that because if I put it on the AfterExpand event, then after it does it for one bad one, all the others work after that, even before they're expanded. So it's like something just isn't clicking until after, and resetting just one makes all others work.
Could some one explain what the SychronizedInputPattern does? I haven't been able to find any good examples of it being used.
Lets suppose you need to click something but before the click happens, the elements move (maybe due to resize …). In this case, some other element could get the mouse input.
To overcome this problem, SynchronizedInputPattern has been introduced.
buttonElement.GetCurrentPropertyValue(AutomationElement.IsSynchronizedInputPatternAvailableProperty);
Read more over here.. Example can be downloaded here.
How can I create a Delphi TSpeedButton or SpeedButton in C# 2.0?
Using a Button and setting the TabStop property to false only works when tapping through the form...
If you need (as I did) a button that does not get selected when clicking on it, there is only one way I have found to do it.
The way I did it, was to subclass the Button class and in the constructor calling the SetStyles and thereby setting Selectable to false, like so:
public class ButtonNoFocus : Button
{
public ButtonNoFocus()
: base()
{
base.SetStyle(ControlStyles.Selectable, false);
}
}
This worked out for me, and is perfect if you e.g. have a control-panel with buttons that perform actions to a selected object...
I'm wondering if you want to create a control like a TSpeedButton, or you just need same kind of end result ...
Programming one from scratch is certainly possible, but I'd only tackle that as a learning exercise.
Assuming you want to achieve a similar end result ...
Delphi's TSpeedButton had a differences from the standard TButton that developers found useful - it was flat, didn't take focus, and it consumed fewer resources than a regular button (because it didn't have an underlying Windows Handle).
Which of these are important to you?
If you just want a flat button that doesn't accept focus, use a regular Button with FlatStyle=Flat (or PopUp) and TabStop=false. You can configure a glyph by setting either the Image property, or a combination of ImageList and ImageIndex/ImageKey.
An alternative to this would be to look for an existing button component that comes close to your needs - one place to look might be the Krypton Toolkit (free to use, see http://www.componentfactory.com/toolkit_buttoncontrols.php).
If you're wanting to reduce the number of resources consumed by your application, it's likely you'll get a better return looking elsewhere.
Back in the days of Windows 3.1 (Delphi 1) and Windows 95 (Delphi 2), the number of available handles was strictly limited, with a maximum number available system wide. Today, with Windows XP and Vista, the number of available handles is far far higher, and the number is per process, not system wide. Unless you're creating thousands upon thousands of buttons, you're very unlikely to come anywhere close to running out.
Does this help? Looks like you would have to handle the OnPaint event, and not take focus...
The regular .net 2.0 button supports part of what a TSpeedbutton Does:
The Glyph: Image
Flat : FlatStyle
It does not handle:
Down
Group
These two are related, you could inherit from the button, and ownerdraw it, adding Down and Group features.
Codeproject has an example of ownerdraw buttons.