用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);
                }
            }
        }
    }

}

源代码下载

转载于:https://www.cnblogs.com/aarond/archive/2012/11/21/WaitiN.html

通用Login功能自动化测试相关推荐

  1. 从0到1搭建移动App功能自动化测试平台(2):操作iOS应用的控件

    转载:http://debugtalk.com/post/build-app-automated-test-platform-from-0-to-1-Appium-interrogate-iOS-UI ...

  2. AutoRunner4.5结合真实项目crm客户管理系统进行界面功能自动化测试教学资料(登录)

    在win10系统上进行界面功能自动化测试,已经困扰了我们很久.就在前不久我们发布了最新版的功能自动化测试工具AR4.5.0.6版本的工具.在这个版本下优化了谷歌浏览器上对象的识别方式,工具自身打开.录 ...

  3. 功能自动化测试的策略有哪些?

    目录 前言 为什么要功能自动化测试? 功能自动化测试的投资回报率 功能自动化测试流程 利用多元化的专业知识建立质量检查团队 自动化测试策略 测试模块化 测试库架构 关键字驱动 数据驱动 录制/播放测试 ...

  4. 嵌入式linux驱动自动化测试,通用的嵌入式自动化测试框架 - 心心草的个人空间 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...

    目前通用的嵌入式自动化测试框架,四层结构: 解释几个术语: 1.测试包(test suite):只要点一个按钮就可以完成一次测试必须用到的东西. 2.数据驱动(Data driven):测试数据与测试 ...

  5. asp.net mysql 读写分离_.NET Core实现分表分库、读写分离的通用 Repository功能

    首先声明这篇文章不是标题党,我说的这个类库是 FreeSql.Repository,它作为扩展库现实了通用仓储层功能,接口规范参考 abp vnext 定义,实现了基础的仓储层(CURD). 安装 d ...

  6. php主控,IcePHP框架中的快速后台中的通用CRUD功能框架(五) SCrud 主控类

    /** * CRUD主控类 * @author bluehire */ class SCrud { const PATH_VIEW='crud'; //视图路径名 /** * 当前列表操作配置 * @ ...

  7. 智能座舱域控制器功能自动化测试方案

    1. 背景 智能座舱是当前汽车行业开发设计和差异化竞争的焦点,当前智能座舱控制器多为整合了传统IPK.HMI.HUD.DMS等若干控制器之后的"一机多屏"的复杂系统.在软件架构上, ...

  8. RobotFramework功能自动化测试框架基础篇

    目录 概念 特性 RF环境安装 RF的使用 1.新建项目 2.创建测试套件 3.创建测试用例 4.创建资源文件 5.页面操作介绍 RF的常用类库 1.标准库: 2.扩展库: 准备UI自动化测试的环境 ...

  9. 通用列表功能使用方法和API

    通用列表功能使用方法和API 通用列表功能使用方法 分组 功能同Excel的分类汇总功能:根据选择的列进行分类:并且可以结合∑功能实现分类汇总功能. ∑功能 功能同Excel的∑功能:如求最大值.最小 ...

最新文章

  1. 剑指offer 算法 (综合)
  2. 管与c++中容量的重新分配问题
  3. Python:目录和文件的操作模块os.path和OS常用方法
  4. SpringTest2
  5. nginx针对某个url限制ip访问,常用于后台访问限制
  6. python 面试宝典--集各家之所长,乱七八糟于一体
  7. 条件锁pthread_cond_t 的应用
  8. php智能代码,php智能分页类代码原创
  9. Spring 在xml文件中配置Bean
  10. 焓湿图软件 android,焓湿图查询计算软件
  11. 基于linux嵌入式课程设计报告,嵌入式linux课程设计报告.doc
  12. -[UIKBBlurredKeyView candidateList]:手写输入法APP闪退
  13. 程序小白天天打卡(函数模板)
  14. Python 自动化办公 —— PyPDF2 库的基本使用
  15. 使用Seaborn和Pandas进行相关性分析和可视化
  16. 解决Keystore was tampered with, or password was incorrect
  17. AMR NB格式解析
  18. 血泪总结:如何从微信小程序的坑跳进支付宝小程序的大坑
  19. java复习之tomcat配置详解
  20. java around_java - 使用Spring AOP时,在单个连接点上具有参数绑定的多个Around建议会导致错误 - 堆栈内存溢出...

热门文章

  1. 脚印:关于错误编码的管理的一些思考
  2. .NET中如何通过文本框中按回车键进行的提交数据
  3. 学术部活动具体落实计划
  4. how to become a very good candidate at the investment bank?
  5. 今天突然想到一个问题:地球在转动吗,由东西向西跳与由西向东跳哪个更远...
  6. 驼峰设计 PPT设计网站
  7. 一个时代的终结:为什么是时候放弃ITOM四大巨头了?这对IT领导者来说意味着什么?...
  8. Docker安装及配置
  9. flume spooldir bug修复
  10. 【133】常见问题解答