Previously, I wrote an article on C # using spy for simulated operations. A friend of mine mentioned UIA in his message, today, we also use UIA to implement a new control test on the VNC form.
Goals
Enter 192.168.2.200 in the server box.
Automatically click the Options button.
Tool Introduction
Uispy, use this tool to find the form. You can download uispy from my csdn.
In uispy, find the window to be operated and click each line. The window is automatically displayed in the red border box.
Code Writing
The execution result is as follows.
// Find the form var desktop = automationelement named VNC Viewer: connection details. rootelement; // obtain the desktop // create a search condition, which indicates that the name attribute is used and the value is the name of the form we need to find. VaR condition = new propertycondition (automationelement. nameproperty, "VNC Viewer: connection details"); // find the first form that meets the conditions. vaR window = desktop. findfirst (treasure. children, condition); // find the Options button on the required form and click var btncondition = new andcondition (New propertycondition (automationelement. controltypeproperty, controltype. button), new propertycondition (automationelement. nameproperty, "options... "); // find the button var buttonoption = Window. findfirst (treasure. children, btncondition); // get button operation event var clickpattern = (invokepattern) buttonoption. getcurrentpattern (invokepattern. pattern); // execute the event clickpattern. invoke (); // good, the above code is executed smoothly, next we will continue to implement the input result to the text box // use the same method first find the text box var txtcondition = new propertycondition (automationelement. controltypeproperty, controltype. edit); // descendants note that the text box is not a child of the window, so children cannot be used directly. vaR txtbox = Window. findfirst (treasure. descendants, txtcondition); var editpatten = (valuepattern) txtbox. getcurrentpattern (valuepattern. pattern); editpatten. setvalue ("192.168.2.200 ");
References
Http://www.cnblogs.com/coderzh/archive/2009/11/14/1603109.html
Http://www.cnblogs.com/stbchina/archive/2010/01/28/Tech-Trend-of-Microsoft-UI-Automation-Testing-Part-Two.html
C # Use UIA to simulate click operations