<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    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 閱讀(254) 評論(0)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 一级毛片高清免费播放| 国产美女a做受大片免费| 一级毛片免费在线| 亚洲一区欧洲一区| 亚洲高清视频在线观看| 亚洲AV伊人久久青青草原| 韩国免费一级成人毛片| 国产一区二区免费视频| 国产97视频人人做人人爱免费| avtt天堂网手机版亚洲| 337p日本欧洲亚洲大胆精品555588| 亚洲免费日韩无码系列| 日韩伦理片电影在线免费观看| 国产成人精品免费视频网页大全 | 久久国产精品2020免费m3u8| 免费看一级毛片在线观看精品视频| 亚洲国产精品久久网午夜| 亚洲伦理一区二区| 国产AV无码专区亚洲Av| 国产国拍精品亚洲AV片| 亚洲国产黄在线观看| 免费一级毛片不卡在线播放| 日本无吗免费一二区| 爽爽日本在线视频免费| 午夜免费福利网站| 午夜私人影院免费体验区| 拨牐拨牐x8免费| 四虎影院免费在线播放| 日本一道综合久久aⅴ免费| 在线观看免费为成年视频| 免费理论片51人人看电影| 卡一卡二卡三在线入口免费| 最新免费jlzzjlzz在线播放| 成人毛片免费在线观看| 免费黄色毛片视频| 国产免费久久精品| 亚洲第一福利网站在线观看| 亚洲国产aⅴ综合网| 亚洲人成电影网站国产精品 | 2020久久精品亚洲热综合一本| 亚洲另类春色校园小说|