如何为日历闰年编写Selenium IDE脚本?

时间:2015-08-04 01:52:35

标签: date selenium calendar selenium-ide leap-year

基本上,我想在日历测试中考虑闰年。 如果是闰年,那么monthDays [1]将被数字29覆盖。 难点是在数组中分配单个元素并在Selenium IDE中使用IF语句。

任何帮助都将不胜感激。

<!--Initialize Days in Each Month-->
<tr>
    <td>storeEval</td>
    <td>new Array(31,28,31,30,31,30,31,31,30,31,30,31)</td>
    <td>monthDays</td>
</tr>
<tr>
    <td>echo</td>
    <td>${monthDays}</td>
    <td></td>
</tr>
<!--Correct for Leap year-->
<!--Testing for Year 2000 by substacting 15 from 2015 below -->
<tr>
    <td>storeEval</td>
    <td>new Date().getFullYear()-15;</td>
    <td>checkYear</td>
</tr>
<!--Syntax Error below-->
<tr>
    <td>storeEval</td>
    <td>javascript{if([storedVars['checkYear']]%400==0   
            {[storedVars['monthDays'][1]] = 29}}</td>
    <td>monthDays[1]</td>
</tr>
<!--*** Else If %100, then NOT Leap year ***-->
<!--*** Else If %4, then Leap year ***-->

1 个答案:

答案 0 :(得分:0)

这似乎使用三元运算符。困难的部分是找到“runScript”命令,因为IDE的本机javascript不允许数组成员分配。

<!--Initialize Days in Each Month-->
<tr>
    <td>storeEval</td>
    <td>new Array(31,28,31,30,31,30,31,31,30,31,30,31)</td>
    <td>monthDays</td>
</tr>
<!--Initialize Name of each Month-->
<tr>
    <td>storeEval</td>
    <td>new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')</td>
    <td>months</td>
</tr>
<!--Initialize Name of each Weekday-->
<tr>
    <td>storeEval</td>
    <td>new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')</td>
    <td>weekdays</td>
</tr>
<!--Correct for Leap year-->
<tr>
    <td>storeEval</td>
    <td>new Date().getFullYear()</td>
    <td>checkYear</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>((([storedVars['checkYear']]%4===0) &amp;([storedVars['checkYear']]%100!=0) ) || ([storedVars['checkYear']]%400==0 ))&nbsp;&nbsp;&nbsp;?&nbsp;&nbsp;29 : 28</td>
    <td>daysInFeb</td>
</tr>
<!--Note: Use runScript for array assignment. IDE cannot do array assignment !-->
<tr>
    <td>runScript</td>
    <td>javascript{storedVars['monthDays'][1]=storedVars['daysInFeb']}</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${monthDays}</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>javascript{storedVars['monthDays'][1]}</td>
    <td></td>
</tr>