Some time ago, a small web automation test tool was developed with C # combined with the Watin component, due to testing needs.
Watin is a very simple and flexible test framework that simulates most of the user's operations in the client browser, and the API is relatively simple.
The implementation of URL calls and control of Web controls is simple, refer to the following code:
for (int i = 0; i < txturls.length; i++)
{
Try
{
WatiN.Core.DialogHandlers.AlertDialogHandler dh = new WatiN.Core.DialogHandlers.AlertDialogHandler ();
using (ie ie = new ie (txturls[i]))//calling Url,txturls[i] is the URL address
{
Ie. Adddialoghandler (DH);//Add a control handle to
ie. CheckBox ("Cblsets_6"). Checked = false;
ie. CheckBox ("Cblsets_8"). Checked = true;
ie. Button ("Btnsave"). Clicknowait (); Execute save
ie. Removedialoghandler (DH);
ie. Close ();
}
catch (Exception e)
{
Sb. Append ("Execute Err:"). Append (Txturls[i]). Append (";");
}
}
Second, the watin commonly used in the class
WatiN.Core.Find
The most commonly used class is the Find class, it is a factory class, mainly using its static method to implement some query conditions. For example, in the example above, this statement "ie. Button (Find.byname ("btng")). Click (); " Call the Find static method byname to query an HTML element with a name property of the specified value, and then call the IE object's button method to convert the element to a button object.
WatiN.Core.IE
This should be the most critical class. His common approach is to attribute the
Property
Htmldialogs returns the mode window that the current object opens with JavaScript (which is also included in the modeless window in the Help document, but found that the window opened with window.open is not) in the trial
Frames returns all Frames in the current elephant.
Method
static method Attachtoie is associated with an IE that has been found.
Button,textfield,image,div a series of methods. Use with the Find object to return specific buttons in IE, input boxes, and other HTML elements.