0

Basically, I would like to account for leap years in a calendar test. If it is a Leap year, then monthDays[1] would be overwritten with the number 29. The difficulty is assigning a single element in the array and using IF statements in Selenium IDE.

Any help would be appreciated.

<!--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
    What is your exact requirement?? Do you want to check whether feb month has 29 days or not?? – Saritha G Aug 04 '15 at 04:03
  • To update the monthDays array for February correctly if it is a leap year. So the value in the monthDays[1] would be 29 if it is a leap year or 28 if it is not. – felicia888 Aug 04 '15 at 19:23
  • Why do you need to know this? Is it because you need the last day of the month? I believe there are utilities that would accomplish this by manipulating the Date object. See http://stackoverflow.com/questions/8175521/javascript-to-find-leap-year – DMart Aug 06 '15 at 20:20

1 Answers1

0

This seems to work using a ternary operator. The hard part was finding the "runScript" command as IDE's native javascript doesn't allow array member assignment.

<!--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>