blogjava's web log

          blogjava's web log
          ...

          Selenium測試 使用筆記

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

          ??? test.open("/");
          ???
          test.click("");
          ???
          test.type("");
          。。。。。
          。。。。。。。
          。。。。。
          ?我想在稍微大點的項目中 這樣寫測試代碼 可能也是個噩夢。。


          解決辦法

          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 選項.
            2. 點擊添加按鈕.
            3. (Name of the fommat )給新添的起個名字 testSelenium
            4. 粘貼下面JS代碼到文本恇
            5. 點擊確定
          4. 點擊工具 菜單 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=注冊||
          |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詳細申請理由(比如:技術(shù)專長,感興趣的技術(shù),在Blog中寫哪方面的內(nèi)容|
          |click|ctl00_cphMain_btnSend||


          把此錄制的腳本 保存為一個文件。

          再寫一個類專門來處理分析 這個腳本

          就不用 在Junit測試 寫 那么長的

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

          等特長的代碼了 。



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

          評論

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

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

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

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

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

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

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

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

          導(dǎo)航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態(tài)語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 石渠县| 崇文区| 贺州市| 丹寨县| 绵阳市| 广州市| 乐亭县| 原阳县| 栾城县| 嵊泗县| 潮州市| 师宗县| 原平市| 天台县| 威海市| 德清县| 海阳市| 永安市| 依安县| 长宁区| 金山区| 邯郸县| 霍邱县| 龙泉市| 依安县| 延川县| 玉环县| 伊通| 孟州市| 恭城| 湘潭市| 密云县| 邵阳县| 隆德县| 宁阳县| 九龙坡区| 渑池县| 巴青县| 称多县| 芮城县| 寿阳县|