Using. NET to develop Web Automation test tools

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.