The more I use watin, the more I think it is a good test tool...
However, several examples found on the Internet have problems, and I have not talked about how to test the alert pop-up window. I studied it myself. Finally solved the problem. Make a note in case you forget it.
You must enter a unique email address on the registration page. If an address exists, an alert window is displayed. The test procedure is as follows.
(The unit test tool I used is nunit. Using nunit and watin together has a configuration value problem. Refer to another article.Article)
For simplicity, I put an email input text box on the page.
After you enter the email address, use ajax to verify whether the email address already exists on the server. If yes, the pop-up window prompts that the email exists! Below is the testCode
Public Void Testemail ()
{
Watin. Core. dialoghandlers. alertdialoghandler DH = New Watin. Core. dialoghandlers. alertdialoghandler ();
IE = New IE ( " Http: // localhost/reisterandlogin/registeruser. aspx " );
Ie. adddialoghandler (DH ); // Add a control handle
Ie. textfield (find. byname ( " Txtemail " ). Typetext ( " 5a6j@sohu.com " );
Ie. Button (find. byname ( " Btnregister " ). Clicknowait ();
DH. waituntilexists ();
String mess = DH. message;
DH. okbutton. Click (); // Click OK in the window.
Ie. waitforcomplete ();
Ie. removedialoghandler (DH );
Ie. Close ();
Assert. areequal ( " The email address already exists. " , Mess );
}
In particular, there are some tutorials
// DH. waituntilexists (3 );
However, errors always occur. Later, the tutorial on the official website should use DH. waituntilexists (); method.
Now, after running nunit, You can automatically test this code. Convenient and worry-free