Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

51 Commits

Repository files navigation

Friendly.Windows.Grasp

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

Getting Started

Install Friendly.Windows.Grasp from NuGet

PM> Install-Package Codeer.Friendly.Windows.Grasp

https://www.nuget.org/packages/Codeer.Friendly.Windows.Grasp/


Features ...

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.

Search for 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.

Win32

Use Friendly.Windows.NativeStandardControls as the control driver.See here.

varmainWindow=app.WaitForIdentifyFromWindowText("Application Title");vartextBox=newNativeEdit(mainWindow.IdentifyFromDialogId(3));

WinForms

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;

WPF

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
GetGet all windows that meet the specified conditions.
IdentifyGet When Identify only one by the order condition. Else thrrow Exception.
WaitForIdentifyWait for identify only one by the order condition. Useful for timing control.

Condition
WindowTextText that can be acquired by GetWindowText of Win32 Api.
TypeFullName.Net type full name
WindowClassWin32 WindowClass
ZIndexZZindex. Multiple can be specified when the parent and child hierarchy of Window is deep.
DialogIdDialogId. 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.

Search top level windows.

  • GetTopLevelWindows
  • GetFromWindowText
  • IdentifyFromWindowText
  • WaitForIdentifyFromWindowText
  • GetFromTypeFullName
  • IdentifyFromTypeFullName
  • WaitForIdentifyFromTypeFullName
  • GetFromWindowClass
  • IdentifyFromWindowClass
  • WaitForIdentifyFromWindowClass

Search child windows.

  • IdentifyFromZIndex
  • IdentifyFromDialogId
  • IdentifyFromWindowText
  • IdentifyFromTypeFullName
  • IdentifyFromWindowClass
  • GetFromWindowText
  • GetFromTypeFullName
  • GetFromWindowClass
  • GetChildren

manuplate window.

  • IsWindow
  • SetWindowText
  • GetWindowText
  • SetFocus
  • SendMessage
  • SequentialMessage
  • PointToScreen
  • Activate
  • Close
  • WaitForDestroy

properties.

  • 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();}

About

No description, website, or topics provided.

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages