批量账号的login测试功能实现

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了批量账号的login测试功能实现脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
用WaitiN写了个简单的login自动化测试,能够使用少量的代码实现批量账号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);
}
}
}
}

源代码下载

脚本宝典总结

以上是脚本宝典为你收集整理的批量账号的login测试功能实现全部内容,希望文章能够帮你解决批量账号的login测试功能实现所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: