With Waitin wrote a simple login automation test, can use a small number of code to achieve the bulk account login test
Quite simply, the code is as follows:
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using Watin.core;
Namespace ConsoleApplication1
{
Class Program
{
[STAThread]
static void Main (string[] args)
{
list<logintester.loginaccount> Accounts = new list<logintester.loginaccount> ();
Accounts.add (New Logintester.loginaccount () {UserName = "Your user account", Password = "AAAAA", shouldsuccess = false}) ;
Accounts.add (New Logintester.loginaccount () {UserName = "Your user account", Password = "", shouldsuccess = false});
Accounts.add (New Logintester.loginaccount () {UserName = "Your user account", Password = "Your Password", shouldsuccess = true});
Logintester tester = new Logintester ("Http://passport.cnblogs.com/login.aspx", "http://home.cnblogs.com", " Tbusername "," Tbpassword "," Btnlogin ");
Tester. Browservisible = true;
Accounts.foreach (T=>tester. Executetest (T.username, T.password, t.shouldsuccess));
Console.WriteLine ("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n");
Console.WriteLine ("************test the summary****************");
Console.WriteLine (tester. Reportsummary);
}
public class Logintester
{
public class Loginaccount
{
public string UserName {get; set;}
public string Password {get; set;}
public bool Shouldsuccess {get; set;}
}
private string loginurl = String. Empty;
private string Loginsuccessforwaredurl = String. Empty;
private string loginbuttonname = String. Empty;
private string usernamefieldname = String. Empty;
private string passwordfieldname = String. Empty;
public string Reportsummary {get; private set;}
public bool Browservisible {get; set;}
Public Logintester (String loginurl, String Loginsuccessforwaredurl, String usernamefieldname, String passwordfieldname , String loginbuttonname)
{
This.loginurl = loginurl;
This.loginsuccessforwaredurl = Loginsuccessforwaredurl;
This.usernamefieldname = Usernamefieldname;
This.passwordfieldname = Passwordfieldname;
This.loginbuttonname = Loginbuttonname;
}
public void Executetest (string userName, string password, bool loginsuccess)
{
String msg = string. Format ("Username: {0}, Password: {1}, expect to be able to log in: {2}", UserName, Password, loginsuccess);
using (ie browser = new IE (this.loginurl))
{
Browser. Visible = this. browservisible;
Browser. TextField (Find.byname (This.usernamefieldname)). TypeText (UserName);
Browser. TextField (Find.byname (This.passwordfieldname)). TypeText (password);
Browser. Button (Find.byname (This.loginbuttonname)). Click ();
BOOL loginissuccess = browser. Url.indexof (This.loginsuccessforwaredurl, stringcomparison.ordinalignorecase) >= 0;
msg = string. Format ("{0}\r\n {1}", msg, loginissuccess = = loginsuccess?) "Successful": "Failed");
Reportsummary + + msg+ "\ r \ n";
Console.WriteLine (msg);
}
}
}
}
Source code Download