blogjava's web log

          blogjava's web log
          ...

          Selenium測試 使用筆記

          看了江南白衣 Selenium--透明反復推介的集成測試工具(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詳細申請理由(比如:技術專長,感興趣的技術,在Blog中寫哪方面的內容|
          |click|ctl00_cphMain_btnSend||


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

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

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

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

          等特長的代碼了 。



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

          評論

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

          沒聽過。  回復  更多評論   

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

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

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

          仿宋  回復  更多評論   

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

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

          導航

          常用鏈接

          留言簿(44)

          新聞檔案

          2.動態語言

          3.工具箱

          9.文檔教程

          友情鏈接

          搜索

          最新評論

          主站蜘蛛池模板: 华亭县| 尉犁县| 绥滨县| 和平区| 墨脱县| 阜城县| 汝城县| 临洮县| 石首市| 永胜县| 旬邑县| 富民县| 富源县| 兴文县| 平乐县| 尼木县| 新丰县| 九江县| 聊城市| 寿光市| 丹阳市| 和平区| 通山县| 五寨县| 札达县| 莒南县| 兴仁县| 溧阳市| 绵阳市| 南昌县| 县级市| 佛学| 夏邑县| 宜兰县| 华容县| 丹巴县| 马尔康县| 礼泉县| 平凉市| 遵义县| 桐柏县|