blogjava's web log

          blogjava's web log
          ...

          Selenium測(cè)試 使用筆記

          看了江南白衣 Selenium--透明反復(fù)推介的集成測(cè)試工具(Pragmatic系列)
          確實(shí)不錯(cuò)。值得推薦使用。但是有的時(shí)候確實(shí)也挺麻煩。
          比如說,我一個(gè)頁面可能有上百個(gè)文本框。等很多動(dòng)作。
          那在Junit 里可能要 寫 一段很長的代碼了。

          ??? test.open("/");
          ???
          test.click("");
          ???
          test.type("");
          。。。。。
          。。。。。。。
          。。。。。
          ?我想在稍微大點(diǎn)的項(xiàng)目中 這樣寫測(cè)試代碼 可能也是個(gè)噩夢(mèng)。。


          解決辦法

          1.如果沒有安裝firefox 下載fireFox ?

          2.Selenium IDE

          1. 下載? Selenium IDE https://addons.mozilla.org/firefox/2079/
          2. Firefox > Tools > Selenium IDE
          3. Selenium IDE > Options > Options...
            1. 選擇 Format 選項(xiàng).
            2. 點(diǎn)擊添加按鈕.
            3. (Name of the fommat )給新添的起個(gè)名字 testSelenium
            4. 粘貼下面JS代碼到文本恇
            5. 點(diǎn)擊確定
          4. 點(diǎn)擊工具 菜單 Selenium IDE > Options > Format > testSelenium
          5. 可以錄腳本了

          testSelenium.js

          var? SEPARATORS?=?{
          ??pipe:?
          "|",
          ??comma:?
          ",",
          ??tab:?
          "\t"
          };

          function?formatCommands(commands)?{
          ??
          var?result?=?'';
          ??
          var?sep?=?SEPARATORS[options.separator];
          ??
          var?prefix?=?options.wrap?==?'true'???sep?:?"";
          ??
          var?postfix?=?prefix;
          ??
          for?(var?i?=?0;?i?<?commands.length;?i++)?{
          ????
          var?command?=?commands[i];
          ????
          if?(command.type?==?'command')?{
          ??????result?
          +=?prefix?+?command.command?+?sep?+?command.target?+?sep?+?command.value?+?postfix?+?"\n";
          ????}
          ??}
          ??
          return?result;
          }

          function?parse(testCase,?source)?{
          ??
          var?doc?=?source;
          ??
          var?commands?=?[];
          ??
          var?sep?=?SEPARATORS[options.separator];
          ??
          var?base?=?options.wrap?==?'true'???1?:?0;
          ??
          while?(doc.length?>?0)?{
          ????
          var?line?=?/(.*)(\r\n|[\r\n])?/.exec(doc);
          ????
          var?array?=?line[1].split(sep);
          ????
          if?(array.length?>=?(base+3))?{
          ??????
          var?command?=?new?Command();
          ??????command.command?
          =?array[base+0];
          ??????command.target?
          =?array[base+1];
          ??????command.value?
          =?array[base+2];
          ??????commands.push(command);
          ????}
          ????doc?
          =?doc.substr(line[0].length);
          ??}
          ??testCase.setCommands(commands);
          }

          function?format(testCase,?name)?{
          ??
          return?formatCommands(testCase.commands);
          }

          options?
          =?{
          ????separator:?'pipe',
          ????wrap:?'
          true'
          };

          configForm?
          =?
          ????'
          <description>Separator</description>'?+?
          ????'
          <menulist?id="options_separator">'?+
          ????'
          <menupopup>'?+
          ????'
          <menuitem?label="Pipe"?value="pipe"/>'?+
          ????'
          <menuitem?label="Comma"?value="comma"/>'?+
          ????'
          <menuitem?label="Tab"?value="tab"/>'?+
          ????'
          </menupopup>'?+
          ????'
          </menulist>'?+
          ????'
          <checkbox?id="options_wrap"?label="Wrap?command?with?separator"/>';


          最后 錄制的 腳本 如下

          base?url?http://www.cnblogs.com/

          |open|/||
          |clickAndWait|link=注冊(cè)||
          |type|ctl00_cphMain_tbApplicant|junmy|
          |type|ctl00_cphMain_tbEmail|wunjunlove(At)gmial.com|
          |type|ctl00_cphMain_tbCompany|msSonft|
          |type|ctl00_cphMain_tbCity|shenzhen|
          |type|ctl00_cphMain_tbApplyText|teeee詳細(xì)申請(qǐng)理由(比如:技術(shù)專長,感興趣的技術(shù),在Blog中寫哪方面的內(nèi)容|
          |click|ctl00_cphMain_btnSend||


          把此錄制的腳本 保存為一個(gè)文件。

          再寫一個(gè)類專門來處理分析 這個(gè)腳本

          就不用 在Junit測(cè)試 寫 那么長的

          ??? test.open(
          "/");
          ???
          test.click("");
          ???
          user.type("");

          等特長的代碼了 。



          posted on 2006-10-29 12:09 record java and net 閱讀(3977) 評(píng)論(4)  編輯  收藏 所屬分類: Springjava

          評(píng)論

          # re: Selenium測(cè)試 使用筆記 2006-10-30 09:56 inlife.cn

          沒聽過。  回復(fù)  更多評(píng)論   

          # re: Selenium測(cè)試 使用筆記 2006-10-30 21:28 Tin

          先后和nemo、limo、raimudox、nicholas討論:
          selenium的Remote Control比較適合在需求階段就撰寫,作為驗(yàn)收的測(cè)試。好處是RC對(duì)重構(gòu)支持相對(duì)好一些,而且你可以換Agent,也可以做瀏覽器兼容測(cè)試。(但是由于RC的限制,兼容側(cè)試兼容性并不好:)
          按照raimudox所說RC是更加Pragmatic的實(shí)踐,更能體現(xiàn)敏捷軟件開發(fā)的測(cè)試先行的特性。功能測(cè)試可以說是溝通用戶與開發(fā)者的最佳契約。
          Selenium IDE適合作為基線保留,作為某次重構(gòu)之前的樣本。或者說,如果覺得手寫測(cè)試腳本太麻煩,而喜歡本末倒置(沒有貶義,純技術(shù)上)的人設(shè)計(jì)的。更現(xiàn)實(shí)的說,這很有用,比如一個(gè)項(xiàng)目從一半開始敏捷改造,引入功能測(cè)試、單元測(cè)試,對(duì)以后的迭代進(jìn)行基線的衡量,給新引入的CI(持續(xù)集成)一個(gè)更有實(shí)際意義的測(cè)試保障,用Selenium IDE幫助生成一下Script,然后再使用RC或者直接用Core執(zhí)行一下都是不錯(cuò)的實(shí)踐。
          還有,據(jù)Nicholas同學(xué)實(shí)踐,Selenium IDE所錄制的script在IDE中執(zhí)行比RC方式兼容性要好,尤其對(duì)于跨域的情況,RC很有可能是無法工作的。還有一個(gè)問題,就是Selenium實(shí)際上是ThoughtWorks和BEA牽頭的項(xiàng)目,TW負(fù)責(zé)Core,目前Core的代碼發(fā)展的必較快,而RC由BEA負(fù)責(zé),發(fā)展比較緩慢,所以,有些時(shí)候選擇也就成為無奈了。  回復(fù)  更多評(píng)論   

          # re: Selenium測(cè)試 使用筆記 2006-11-19 13:09 苗春利

          仿宋  回復(fù)  更多評(píng)論   

          # re: Selenium測(cè)試 使用筆記 2007-07-05 10:43 Jackei

          對(duì)于有開發(fā)經(jīng)驗(yàn)的人來說,RC 模式的確更合適一些,特別是 RC 模式對(duì)于腳本的可擴(kuò)展性和可維護(hù)性會(huì)好很多。而且腳本可以通過抽象和封裝來提高可重用性。 Core 模式下幾乎就無法實(shí)現(xiàn)這些特性了。  回復(fù)  更多評(píng)論   

          導(dǎo)航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動(dòng)態(tài)語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評(píng)論

          主站蜘蛛池模板: 公安县| 大理市| 元阳县| 双柏县| 南漳县| 庄河市| 东港市| 湘潭县| 武冈市| 凭祥市| 永德县| 新宁县| 惠州市| 龙南县| 安平县| 建昌县| 兰州市| 建宁县| 思茅市| 桦甸市| 治县。| 杭锦后旗| 隆回县| 图片| 鄂托克旗| 龙州县| 西和县| 屯门区| 通辽市| 德化县| 垦利县| 澄迈县| 天峨县| 施甸县| 乌鲁木齐县| 郎溪县| 宁国市| 新巴尔虎左旗| 梁山县| 龙川县| 磐安县|