Be happy with Java

          今天寫了個(gè)http-unit

          LoginTest.java
          ?1package?com.asmiling.test.login;
          ?2
          ?3/**
          ?4?*?<p>Title:?</p>
          ?5?*
          ?6?*?<p>Description:?</p>
          ?7?*
          ?8?*?<p>Copyright:?Copyright?(c)?2006</p>
          ?9?*
          10?*?<p>Company:?</p>
          11?*
          12?*?@author?sybil
          13?*?@version?1.0
          14?*/

          15import?java.net.URL;
          16import?junit.framework.TestCase;
          17import?junit.framework.TestSuite;
          18import?junit.textui.TestRunner;
          19
          20import?com.meterware.httpunit.WebConversation;
          21import?com.meterware.httpunit.WebRequest;
          22import?com.meterware.httpunit.WebResponse;
          23import?com.meterware.httpunit.WebForm;
          24import?com.meterware.httpunit.GetMethodWebRequest;
          25
          26import?com.asmiling.test.util.LoginTestInf;
          27public?class?LoginTest?extends?TestCase?implements?LoginTestInf{
          28????????private?WebConversation?brower;
          29????????private?WebRequest?request;
          30????????private?WebResponse?response;
          31????????private?String?urlBlogdriver="http://192.168.22.75:8080/sms2401";
          32????????public?void?setUp()?throws?Exception{
          33????????????????brower=new?WebConversation();
          34????????????????request=new?GetMethodWebRequest(urlBlogdriver);
          35????????????????response=brower.getResponse(request);
          36????????}

          37????????//輸入登錄地址的頁(yè)面地址,驗(yàn)證該頁(yè)面是否被正常訪問(wèn)
          38????????public?void?testValidPage()?throws?Exception{
          39????????????????assertNotNull("Summary在網(wǎng)絡(luò)上不存在!",response);
          40????????}

          41????????//驗(yàn)證被訪問(wèn)的頁(yè)面是否是登錄頁(yè)面
          42????????public?void?testIsLoginPage()?throws?Exception{
          43????????????????URL?currentUrl=response.getURL();
          44????????????????String?currentUrlStr=currentUrl.getProtocol()+"://"+currentUrl.getHost()+currentUrl.getPath();
          45????????????????assertEquals("登錄頁(yè)面不是Summary首頁(yè)!",currentUrlStr,urlBlogdriver);
          46????????}

          47????????//輸入非法用戶名、密碼,驗(yàn)證登錄失敗
          48????????public?void?testBadLogin()?throws?Exception{
          49????????????????WebForm?form=response.getForms()[0];
          50????????????????form.setParameter("txtUserName","smsAdmin@test.cu.com");
          51????????????????form.setParameter("txtPassword","sms@))*");
          52????????????????request=form.getRequest();
          53????????????????response=brower.getResponse(request);
          54????????????????assertTrue("您的用戶名和密碼在IOSMS沒(méi)有備案!",response.getText().indexOf("出錯(cuò)信息")!=-1);
          55????????}

          56????????//輸入合法用戶名、密碼、驗(yàn)證登錄成功
          57????????public?void?testGoodLogin()?throws?Exception{
          58????????????????WebForm?form=response.getForms()[0];
          59????????????????form.setParameter("txtUserName","smsAdmin@test.cu.com");
          60????????????????form.setParameter("txtPassword","sms@))*");//此處需要填寫真實(shí)密碼
          61????????????????request=form.getRequest();
          62????????????????response=brower.getResponse(request);
          63????????????????assertTrue("轉(zhuǎn)到Summary頁(yè)面失敗!",response.getText().indexOf("Summary")!=-1);
          64????????}

          65
          66????????public?static?TestSuite?suite(){
          67????????????????return?new?TestSuite(LoginTest.class);
          68????????}

          69
          70????????public?static?void?main(String?args[]){
          71????????????????TestRunner.run(suite());
          72????????}

          73}

          LoginTestInf.java
          ?1package?com.asmiling.test.util;
          ?2
          ?3/**
          ?4?*?<p>Title:?</p>
          ?5?*
          ?6?*?<p>Description:?</p>
          ?7?*
          ?8?*?<p>Copyright:?Copyright?(c)?2006</p>
          ?9?*
          10?*?<p>Company:?</p>
          11?*
          12?*?@author?sybil
          13?*?@version?1.0
          14?*/

          15
          16public?interface?LoginTestInf{
          17????public?void?testValidPage()?throws?Exception;
          18????public?void?testIsLoginPage()?throws?Exception;
          19????public?void?testBadLogin()?throws?Exception;
          20????public?void?testGoodLogin()?throws?Exception;
          21}

          一共四個(gè)方法,通過(guò)了兩個(gè),testValidPage和testGoodLogin通過(guò)了,testInLoginPage和testBadLogin沒(méi)過(guò)。

          posted on 2006-12-13 18:26 SYBIL@BLOGJAVA 閱讀(255) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 边坝县| 萝北县| 广昌县| 西乡县| 巴楚县| 濮阳县| 舞钢市| 车致| 涞水县| 荥阳市| 阿瓦提县| 黄石市| 鱼台县| 通州区| 新源县| 藁城市| 屯门区| 石阡县| 阿坝县| 惠州市| 湖州市| 固安县| 特克斯县| 云南省| 尤溪县| 静乐县| 纳雍县| 漳浦县| 马龙县| 德惠市| 贵州省| 麻江县| 本溪| 枣庄市| 黔江区| 托里县| 通辽市| 大余县| 蓬溪县| 龙山县| 内黄县|