qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問 http://qaseven.github.io/

          Selenium IDE 擴(kuò)展函數(shù): 日期計(jì)算與表現(xiàn)

           用Selenium IDE做網(wǎng)頁(yè)的功能測(cè)試經(jīng)常會(huì)碰到與日期有關(guān)的驗(yàn)證,本人結(jié)合實(shí)際工作中遇到的應(yīng)用,寫了一個(gè)擴(kuò)展,代碼如下:
          Selenium.prototype.doStoreDateByFormat = function(format,args){
          // format of args: month,day,year
          if(args.trim().length < 3)
          throw new SeleniumError("arguments must contain ""Month"",""Date"",""Year"" variables!");
          var formats = format.split(",");
          var days = parseInt(formats[3]);
          var sysDate = getSysDate(); //get the sysdate
          var specDate = dateAfterDays(sysDate,parseFloat(days),1); //get specified date
          var arrArgs = args.split(",");
          var month = specDate.getMonth()+1;
          var date = specDate.getDate();
          var year = specDate.getFullYear();
          // get Month string
          switch(formats[0].toUpperCase()){
          case "MM": // return 2 digits of month number, such as: 01
          month = (month+"").length==1?"0"+month:month;
          break;
          case "MMM": //return the first 3 chars of the month word, such as: Jan
          month = this.getMonthShortName(month);
          break;
          case "MMMM": //return the full word of the month word, such as: January
          month = this.getMonthFullName(month);
          break;
          case "M":
          default:
          // return 1 digit when month is lower than 10.
          // do nothing
          }
          //get Date string
          switch(formats[1].toUpperCase()){
          case "DD": //always return 2 digits of the month number, such as: 05
          date = (date+"").length==1?"0"+date:date;
          break;
          case "D":
          default:
          // return 1 digit when Date is lower than 10.
          // do nothing
          }
          //get Year string
          switch(formats[2].toUpperCase()){
          case "YY": // return last 2 digits of the year number, such as: 08 (2008)
          year = (year+"").substr(2);
          break;
          case "YYYY":
          default:
          //return full year number, such: 2008.
          }
          storedVars[arrArgs[0]] = month;
          storedVars[arrArgs[1]] = date;
          storedVars[arrArgs[2]] = year;
          }
          Selenium.prototype.getMonthFullName = function(month){
          var monthArr = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
          if(month == null){
          throw new SeleniumError("you didn't specify a Month");
          }
          try{
          month = parseInt(month);
          }catch (e){
          throw new SeleniumError("""Month"" is not a Integer!");
          }
          return monthArr[month-1];
          }
          /* return the date N days(N*24 hours) before/after some day.
          * args   :   num - positive/negative integer/float number,default is "1";
          *            type - 0 (second) or 1 (day), default is second.
          * return :   Date
          */
          function dateAfterDays(date, num, type){
          date = (date == null?new Date():date);
          num = (num == null?1:num);
          if(typeof(num)!="number")
          throw new SeleniumError("dateAfterDays(date, num, type),""num"" argument must be Number type.");
          if(typeof(date)!="object")
          throw new SeleniumError("dateAfterDays(date, num, type),""date"" argument must be Date type.");
          var iType = (type == null?0:type);
          var arr = [1000,86400000];
          var dd = date.valueOf();
          dd += num * arr[iType];
          var d=new Date(dd);
          return d;
          }
          function getSysDate(){
          return new Date();
          }
            使用方法如下,詳見以上代碼

          01
          01

          posted on 2013-10-08 11:35 順其自然EVO 閱讀(265) 評(píng)論(0)  編輯  收藏 所屬分類: selenium and watir webdrivers 自動(dòng)化測(cè)試學(xué)習(xí)

          <2013年10月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 西乡县| 宁远县| 沂水县| 郁南县| 永清县| 宜州市| 汉寿县| 得荣县| 顺义区| 沂南县| 龙泉市| 大竹县| 交城县| 兴安县| 宜宾市| 白银市| 元朗区| 务川| 喀什市| 锦州市| 中阳县| 泽州县| 墨脱县| 贵港市| 兴宁市| 平潭县| 尖扎县| 洞口县| 集安市| 宜君县| 江山市| 兴城市| 灵丘县| 桂阳县| 永仁县| 天峨县| 定州市| 巩义市| 福泉市| 泗阳县| 林口县|