This library is a layer on top of Friendly, so you must learn that first. But it is very easy to learn.
https://github.com/Codeer-Software/Friendly
Install Friendly.Windows.Grasp from NuGet
PM> Install-Package Codeer.Friendly.Windows.Grasp
https://www.nuget.org/packages/Codeer.Friendly.Windows.Grasp/
The main purpose is to search for window.
To test, you first need to get the target Window.
And sub use case, Win32 level operation can be performed to window.
Use WindowControl.
The top level window can be got using the static method.
And the extension method of WindowsAppFriend is prepared, you can write like this.
varapp=newWindowsAppFriend(process);vartopwLevelWindows=WindowControl.GetTopLevelWindows(app);varmainWindow=WindowControl.WaitForIdentifyFromTypeFullName(app,"Target.MainWindow");//extension method.vartopwLevelWindows2=app.GetTopLevelWindows();varmainWindow2=app.WaitForIdentifyFromTypeFullName("Target.MainWindow");You can also search for child windows.
However, it is better to use field names for WinForms and Visual Tree or Logical Tree for Wpf.
It's a good idea to use this for Win32 windows.
Use Friendly.Windows.NativeStandardControls as the control driver.See here.
varmainWindow=app.WaitForIdentifyFromWindowText("Application Title");vartextBox=newNativeEdit(mainWindow.IdentifyFromDialogId(3));This is a basic feature of Friendly. See here.
Use Friendly.FormsStandardControls as the control driver.See here.
varmainWindow=app.WaitForIdentifyFromWindowText("Target.MainWindow");FormsTextBoxtextBox=mainWindow.Dynamic()._textBox;This is a feature of Friendly.WPF Standard Controls. See here.
varmainWindow=app.WaitForIdentifyFromTypeFullName("Target.MainWindow");//get by visual tree.WPFTextBoxtextBox=mainWindow.VisualTree().ByBinding("Name").Single().Dynamic();//Of course, if x:name is attached, it can also be obtained from the field.WPFTextBoxtextBox2=mainWindow.Dynamic()._textBox;The name of the search function is a combination of the following two patterns.
| Behavior | |
|---|---|
| Get | Get all windows that meet the specified conditions. |
| Identify | Get When Identify only one by the order condition. Else thrrow Exception. |
| WaitForIdentify | Wait for identify only one by the order condition. Useful for timing control. |
| Condition | |
|---|---|
| WindowText | Text that can be acquired by GetWindowText of Win32 Api. |
| TypeFullName | .Net type full name |
| WindowClass | Win32 WindowClass |
| ZIndex | ZZindex. Multiple can be specified when the parent and child hierarchy of Window is deep. |
| DialogId | DialogId. Multiple can be specified when the parent and child hierarchy of Window is deep. |
* I used From instead of By because my English wasn't good at that time. Don't worry about it.
- GetTopLevelWindows
- GetFromWindowText
- IdentifyFromWindowText
- WaitForIdentifyFromWindowText
- GetFromTypeFullName
- IdentifyFromTypeFullName
- WaitForIdentifyFromTypeFullName
- GetFromWindowClass
- IdentifyFromWindowClass
- WaitForIdentifyFromWindowClass
- IdentifyFromZIndex
- IdentifyFromDialogId
- IdentifyFromWindowText
- IdentifyFromTypeFullName
- IdentifyFromWindowClass
- GetFromWindowText
- GetFromTypeFullName
- GetFromWindowClass
- GetChildren
- IsWindow
- SetWindowText
- GetWindowText
- SetFocus
- SendMessage
- SequentialMessage
- PointToScreen
- Activate
- Close
- WaitForDestroy
- AppVar
- App
- Handle
- DialogId
- WindowClassName
- TypeFullName
- ParentWindow
- Size
- AutoRefresh
//Sample Win32 varprocess=Process.GetProcessesByName("NativeTarget")[0];using(varapp=newWindowsAppFriend(process)){//Wait for identify by window text.vartestDlg=app.WaitForIdentifyFromWindowText("Target Application");//using Friendly.Windows.NativeStandardControls.//Get from dialog id.//Buttonvarbutton=newNativeButton(testDlg.IdentifyFromDialogId(1004));button.EmulateClick();//Editvaredit=newNativeEdit(testDlg.IdentifyFromDialogId(1020));edit.EmulateChangeText("abc");//Treevartree=newNativeTree(testDlg.IdentifyFromDialogId(1041));tree.EmulateEdit(tree.Nodes[0],"new text");}//Sample WinFormsvarprocess=Process.GetProcessesByName("FormsTarget")[0];using(varapp=newWindowsAppFriend(process)){//Wait for identify by type full name.varmainForm=app.WaitForIdentifyFromTypeFullName("TargetApp.MainForm");//using Friendly.FormsStandardControls.//use filed.//ButtonFormsButtonbutton=mainForm.Dynamic()._button;button.EmulateClick();//TextBoxFormsTextBoxtextBox=mainForm.Dynamic()._textBox;textBox.EmulateChangeText("abc");//TreeFormsTreeViewtree=mainForm.Dynamic()._tree;tree.GetItem("item1","item2").EmulateSelect();}