使用selenim作为项目测试框架,适用asp.net c# 网站测试
2008-06-19 14:30
971 查看
第一步:
下载 selenium-remote-control-1.0-beta-1,解压缩,
第二步:
做个批处理文件启动测试服务器,批处理文件内容:
java -jar E:/selenium/selenium-remote-control-1.0-beta-1-dist/selenium-remote-control-1.0-beta-1/selenium-server-1.0-beta-1/selenium-server.jar
以后,双击bat文件,直接启动测试服务器。
第三步:编写测试用例
使用c#控制台程序,建立测试框架平台
public class CaiHaoTest
{
private ISelenium selenium;
public void Start()
{
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.caihao.com");
selenium.Start();
}
public void stop()
{
selenium.Stop();
}
/// <summary>
/// 验证登录
/// </summary>
public void Login()
{
selenium.Open("http://www.caihao.com");
selenium.Type("tbUserName", "wuzhi");
selenium.Type("tbPassword", "11111111");
selenium.Click("btnLogin");
Thread.Sleep(1000);//等待页面加载完
Console.WriteLine("登录测试————"+(selenium.IsTextPresent("安全退出")?"通过":"未通过"));
}
/// <summary>
/// 验证个人会员功能
/// 注册,简历设计,
/// </summary>
public void ValidatePerson()
{
selenium.Open("http://www.caihao.com");
selenium.Click("xpath=//a[@href='http://www.caihao.com/Ps/Registration.aspx']");
selenium.WaitForPageToLoad("3000");
//selenium.Open("http://www.caihao.com/Ps/Registration.aspx");
DateTime now=DateTime.Now;
Thread.Sleep(1000);
string userName = "test" + now.Day+now.Hour+now.Second;
string nickName = "昵称" + now.Day + now.Hour + now.Second; ;
selenium.Type("txtUserName", userName);
selenium.Type("txtNick", nickName);
selenium.Type("txtPassword", "11111111");
selenium.Type("txtConfirmPassword", "11111111");
Thread.Sleep(10);
selenium.Click("btRegistration");
Thread.Sleep(1000);//等待页面加载完
selenium.Open("http://www.caihao.com/Ps/index.aspx");
Console.WriteLine("个人会员注册测试————" + (selenium.IsTextPresent(nickName) ? "通过" : "未通过"));
selenium.Click("xpath=//a[@href='http://www.caihao.com/ps/rsm/PersonalInfo.aspx']");
selenium.WaitForPageToLoad("3000");
//简历设计
selenium.Type("tbFullName", "张飞" + now.Day);
selenium.Check("rblGender_0");
selenium.Select("ddlDegree", "index=1");
selenium.Select("ddlSpecialType", "index=1");
selenium.Type("tbSpecialName", "电子科技专业名称"+now.Day);
selenium.Select("ddlGraduateYear", "index=20");
selenium.Select("ddlGraduateMonth", "index=10");
selenium.Select("ddlLinkType", "index=1");
selenium.Type("tbLink", "1389999911");
selenium.Click("btnSaveAndNext");
Console.WriteLine("个人会员简历信息设计测试通过");
selenium.WaitForPageToLoad("3000");
//教育背景 http://www.caihao.com/ps/rsm/EducationStory.aspx
selenium.Type("tbSchool", "毕业学校" + now.Day);
selenium.Select("ddlDegree","index=2");
selenium.Select("ddlBeginYear", "index=20");
selenium.Select("ddlBeginMonth", "index=1");
selenium.Select("ddlSpecialType", "index=1" );
selenium.Select("ddlEndYear", "index=5");
selenium.Select("ddlEndMonth", "index=10");
selenium.Type("tbSpecial", "专业名称"+now.Day);
selenium.Type("tbDescription", "专业描述"+now);
selenium.Click("btnSave");
Console.WriteLine("-----------------个人会员简历信息教育背景设计测试通过-----------------");
selenium.WaitForPageToLoad("3000");
//求职意向
if (selenium.IsTextPresent("您还需要填写求职意向"))
selenium.Click("xpath=//a[@href='http://www.caihao.com/ps/rsm/Intent.aspx']");
else
{
Console.WriteLine("-----------------个人会员简历信息教育背景设计测试没有通过!-----------------");
}
//selenium.Type("tbWorkYears", "10");
selenium.WaitForPopUp("Industry_panleIndustry","300");
//selenium.w("3000");
selenium.Select("ddlBeginMonth", "index=1");
selenium.Select("ddlSpecialType", "index=1");
selenium.Select("ddlEndYear", "index=5");
selenium.Select("ddlEndMonth", "index=10");
// selenium.WaitForPageToLoad("3000");
}
}
}
下载 selenium-remote-control-1.0-beta-1,解压缩,
第二步:
做个批处理文件启动测试服务器,批处理文件内容:
java -jar E:/selenium/selenium-remote-control-1.0-beta-1-dist/selenium-remote-control-1.0-beta-1/selenium-server-1.0-beta-1/selenium-server.jar
以后,双击bat文件,直接启动测试服务器。
第三步:编写测试用例
使用c#控制台程序,建立测试框架平台
public class CaiHaoTest
{
private ISelenium selenium;
public void Start()
{
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.caihao.com");
selenium.Start();
}
public void stop()
{
selenium.Stop();
}
/// <summary>
/// 验证登录
/// </summary>
public void Login()
{
selenium.Open("http://www.caihao.com");
selenium.Type("tbUserName", "wuzhi");
selenium.Type("tbPassword", "11111111");
selenium.Click("btnLogin");
Thread.Sleep(1000);//等待页面加载完
Console.WriteLine("登录测试————"+(selenium.IsTextPresent("安全退出")?"通过":"未通过"));
}
/// <summary>
/// 验证个人会员功能
/// 注册,简历设计,
/// </summary>
public void ValidatePerson()
{
selenium.Open("http://www.caihao.com");
selenium.Click("xpath=//a[@href='http://www.caihao.com/Ps/Registration.aspx']");
selenium.WaitForPageToLoad("3000");
//selenium.Open("http://www.caihao.com/Ps/Registration.aspx");
DateTime now=DateTime.Now;
Thread.Sleep(1000);
string userName = "test" + now.Day+now.Hour+now.Second;
string nickName = "昵称" + now.Day + now.Hour + now.Second; ;
selenium.Type("txtUserName", userName);
selenium.Type("txtNick", nickName);
selenium.Type("txtPassword", "11111111");
selenium.Type("txtConfirmPassword", "11111111");
Thread.Sleep(10);
selenium.Click("btRegistration");
Thread.Sleep(1000);//等待页面加载完
selenium.Open("http://www.caihao.com/Ps/index.aspx");
Console.WriteLine("个人会员注册测试————" + (selenium.IsTextPresent(nickName) ? "通过" : "未通过"));
selenium.Click("xpath=//a[@href='http://www.caihao.com/ps/rsm/PersonalInfo.aspx']");
selenium.WaitForPageToLoad("3000");
//简历设计
selenium.Type("tbFullName", "张飞" + now.Day);
selenium.Check("rblGender_0");
selenium.Select("ddlDegree", "index=1");
selenium.Select("ddlSpecialType", "index=1");
selenium.Type("tbSpecialName", "电子科技专业名称"+now.Day);
selenium.Select("ddlGraduateYear", "index=20");
selenium.Select("ddlGraduateMonth", "index=10");
selenium.Select("ddlLinkType", "index=1");
selenium.Type("tbLink", "1389999911");
selenium.Click("btnSaveAndNext");
Console.WriteLine("个人会员简历信息设计测试通过");
selenium.WaitForPageToLoad("3000");
//教育背景 http://www.caihao.com/ps/rsm/EducationStory.aspx
selenium.Type("tbSchool", "毕业学校" + now.Day);
selenium.Select("ddlDegree","index=2");
selenium.Select("ddlBeginYear", "index=20");
selenium.Select("ddlBeginMonth", "index=1");
selenium.Select("ddlSpecialType", "index=1" );
selenium.Select("ddlEndYear", "index=5");
selenium.Select("ddlEndMonth", "index=10");
selenium.Type("tbSpecial", "专业名称"+now.Day);
selenium.Type("tbDescription", "专业描述"+now);
selenium.Click("btnSave");
Console.WriteLine("-----------------个人会员简历信息教育背景设计测试通过-----------------");
selenium.WaitForPageToLoad("3000");
//求职意向
if (selenium.IsTextPresent("您还需要填写求职意向"))
selenium.Click("xpath=//a[@href='http://www.caihao.com/ps/rsm/Intent.aspx']");
else
{
Console.WriteLine("-----------------个人会员简历信息教育背景设计测试没有通过!-----------------");
}
//selenium.Type("tbWorkYears", "10");
selenium.WaitForPopUp("Industry_panleIndustry","300");
//selenium.w("3000");
selenium.Select("ddlBeginMonth", "index=1");
selenium.Select("ddlSpecialType", "index=1");
selenium.Select("ddlEndYear", "index=5");
selenium.Select("ddlEndMonth", "index=10");
// selenium.WaitForPageToLoad("3000");
}
}
}
相关文章推荐
- 如何在ASP.NET 网站项目中使用C# 6?
- SEO_ASP.net SEO优化(包含URL地址重写\viewState移动和压缩至服务器\SEO信息XML生成_根据URL地址重写文件)\web网站内容压缩 源码公开.本人授权可使用于商业项目。
- 如何使用 asp.net 4.0 新特性 路由功能 有助于seo优化 给一个 asp.net web项目(网站项目) 增加路由功能 ,继承,给根据路由生成的url的结尾,增加一个有利于seo优化的斜杠 /,跳转到一个路由生成的url页面
- 从零开始写C# MVC框架之--- 使用Areas分离ASP.NET MVC项目
- 把ASP.NET项目发布到IIS服务器上后,测试显示此问题,无法浏览网站的原因
- 使用ASP.NET MVC框架创建电子商务网站
- 【MVC整理】1.使用 StructureMap 作为 ASP.NET MVC 的 DI 框架
- 写了C# ASP.NET WebService的XML解析网站接口程序收了200元辛苦费【加入软件项目源码交易群的好处】
- IT咨询顾问:一次吐血的项目救火 java或判断优化小技巧 asp.net core Session的测试使用心得 【.NET架构】BIM软件架构02:Web管控平台后台架构 NetCore入门篇:(十一)NetCore项目读取配置文件appsettings.json 使用LINQ生成Where的SQL语句 js_jquery_创建cookie有效期问题_时区问题
- 写了C# ASP.NET WebService的XML解析网站接口程序收了200元辛苦费【加入软件项目源码交易群的好处】
- 使用ASP.NET.4.5.1+MVC5.0 搭建一个包含 Ninject框架 项目
- Asp.Net MVC项目通过Git同步到新开发设备上后无法作为网站启动
- 使用ASP.NET MVC框架创建电子商务网站
- [转]c# asp.net 新建项目与新建网站区别
- 【MVC整理】1.使用 StructureMap 作为 ASP.NET MVC 的 DI 框架
- 项目开发中的一些注意事项以及技巧总结 基于Repository模式设计项目架构—你可以参考的项目架构设计 Asp.Net Core中使用RSA加密 EF Core中的多对多映射如何实现? asp.net core下的如何给网站做安全设置 获取服务端https证书 Js异常捕获
- 【转载】使用Json比用string返回数据更友好,也更面向对象一些 |Asp.net MVC 2.0 + Unity 2.0(IoC) + EF4.0 实例:RoRoWoBlog 开源项目框架代码
- ASP.NET MVC 教程 - 使用实体框架创建模型类(C#)
- StructureMap 作为 ASP.NET MVC 的 DI 框架的使用实例
- asp.net c#.net项目中使用总结,遇到的各个问题的汇总