批量賬號的login測試功能實現(xiàn)
更新時間:2012年11月23日 12:00:58 作者:
用WaitiN寫了個簡單的login自動化測試,能夠使用少量的代碼實現(xiàn)批量賬號的login測試,需要的朋友可以參考下
用WaitiN寫了個簡單的login自動化測試,能夠使用少量的代碼實現(xiàn)批量賬號的login測試
很簡單的,代碼如下:
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 Report 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("用戶名: {0}, 密碼: {1}, 期望能否登錄: {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);
}
}
}
}
源代碼下載
很簡單的,代碼如下:
復(fù)制代碼 代碼如下:
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 Report 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("用戶名: {0}, 密碼: {1}, 期望能否登錄: {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);
}
}
}
}
源代碼下載
相關(guān)文章
.Net中的弱引用字典WeakDictionary和ConditionalWeakTable介紹
這篇文章介紹了.Net中的弱引用字典WeakDictionary和ConditionalWeakTable,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06Entity?Framework?Core實現(xiàn)Like查詢詳解
本文詳細(xì)講解了Entity?Framework?Core實現(xiàn)Like查詢的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-02-02ASP.NET實現(xiàn)根據(jù)IP獲取省市地址的方法
這篇文章主要介紹了ASP.NET實現(xiàn)根據(jù)IP獲取省市地址的方法,主要基于QQwry.dat純真IP數(shù)據(jù)庫來實現(xiàn)這一功能,非常實用,需要的朋友可以參考下2014-10-10.NET中利用js讓子窗體向父頁面?zhèn)髦档膶崿F(xiàn)方法
.NET中利用js讓子窗體向父頁面?zhèn)髦档膶崿F(xiàn)方法,需要的朋友可以參考一下2013-02-02深入Lumisoft.NET實現(xiàn)郵件發(fā)送功能的方法詳解
本篇文章對使用Lumisoft.NET實現(xiàn)郵件發(fā)送功能的方法機型了詳細(xì)的分析介紹。需要的朋友參考下2013-05-05.NetCore使用過濾器實現(xiàn)登錄權(quán)限認(rèn)證的方法小結(jié)
這篇文章主要介紹了.NetCore使用過濾器實現(xiàn)登錄權(quán)限認(rèn)證幾種方式總結(jié),主要包括自定義行為過濾器在OnActionExecuting中實現(xiàn),自定義身份驗證過濾器,本文通過實例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2022-06-06使用SNK密鑰文件保護(hù)你的DLL和代碼不被反編譯教程
這篇文章主要介紹了使用SNK密鑰文件保護(hù)你的DLL和代碼不被反編譯教程, SNK,作為程序后綴的時候,是.net中的強密匙加密文件,需要的朋友可以參考下2014-09-09