批量賬號(hào)的login測(cè)試功能實(shí)現(xiàn)
更新時(shí)間:2012年11月23日 12:00:58 作者:
用WaitiN寫(xiě)了個(gè)簡(jiǎn)單的login自動(dòng)化測(cè)試,能夠使用少量的代碼實(shí)現(xiàn)批量賬號(hào)的login測(cè)試,需要的朋友可以參考下
用WaitiN寫(xiě)了個(gè)簡(jiǎn)單的login自動(dòng)化測(cè)試,能夠使用少量的代碼實(shí)現(xiàn)批量賬號(hào)的login測(cè)試
很簡(jiǎn)單的,代碼如下:
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("用戶(hù)名: {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);
}
}
}
}
源代碼下載
很簡(jiǎn)單的,代碼如下:
復(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("用戶(hù)名: {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,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06

ASP.NET實(shí)現(xiàn)根據(jù)IP獲取省市地址的方法
這篇文章主要介紹了ASP.NET實(shí)現(xiàn)根據(jù)IP獲取省市地址的方法,主要基于QQwry.dat純真IP數(shù)據(jù)庫(kù)來(lái)實(shí)現(xiàn)這一功能,非常實(shí)用,需要的朋友可以參考下
2014-10-10 
.NET中利用js讓子窗體向父頁(yè)面?zhèn)髦档膶?shí)現(xiàn)方法
.NET中利用js讓子窗體向父頁(yè)面?zhèn)髦档膶?shí)現(xiàn)方法,需要的朋友可以參考一下
2013-02-02 
深入Lumisoft.NET實(shí)現(xiàn)郵件發(fā)送功能的方法詳解
本篇文章對(duì)使用Lumisoft.NET實(shí)現(xiàn)郵件發(fā)送功能的方法機(jī)型了詳細(xì)的分析介紹。需要的朋友參考下
2013-05-05 
.NetCore使用過(guò)濾器實(shí)現(xiàn)登錄權(quán)限認(rèn)證的方法小結(jié)
這篇文章主要介紹了.NetCore使用過(guò)濾器實(shí)現(xiàn)登錄權(quán)限認(rèn)證幾種方式總結(jié),主要包括自定義行為過(guò)濾器在OnActionExecuting中實(shí)現(xiàn),自定義身份驗(yàn)證過(guò)濾器,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
2022-06-06 
使用SNK密鑰文件保護(hù)你的DLL和代碼不被反編譯教程
這篇文章主要介紹了使用SNK密鑰文件保護(hù)你的DLL和代碼不被反編譯教程, SNK,作為程序后綴的時(shí)候,是.net中的強(qiáng)密匙加密文件,需要的朋友可以參考下
2014-09-09