第一步:
下载 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");
} } }