Be happy with Java

          今天寫了個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????????//輸入登錄地址的頁面地址,驗證該頁面是否被正常訪問
          38????????public?void?testValidPage()?throws?Exception{
          39????????????????assertNotNull("Summary在網絡上不存在!",response);
          40????????}

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

          47????????//輸入非法用戶名、密碼,驗證登錄失敗
          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沒有備案!",response.getText().indexOf("出錯信息")!=-1);
          55????????}

          56????????//輸入合法用戶名、密碼、驗證登錄成功
          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@))*");//此處需要填寫真實密碼
          61????????????????request=form.getRequest();
          62????????????????response=brower.getResponse(request);
          63????????????????assertTrue("轉到Summary頁面失??!",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}

          一共四個方法,通過了兩個,testValidPage和testGoodLogin通過了,testInLoginPage和testBadLogin沒過。

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


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 彭阳县| 峨眉山市| 竹山县| 克拉玛依市| 衡东县| 石城县| 盈江县| 台中县| 任丘市| 九江市| 唐河县| 博罗县| 新蔡县| 石棉县| 剑阁县| 信阳市| 五河县| 盘锦市| 无锡市| 中西区| 桂林市| 资源县| 拜泉县| 高碑店市| 泽库县| 弋阳县| 元朗区| 仁化县| 拜泉县| 获嘉县| 凉山| 齐河县| 进贤县| 正安县| 淮安市| 德安县| 株洲市| 江门市| 竹溪县| 赤壁市| 安仁县|