typeTodaysDatePlusX

I needed a user-extension that could calculate todays date, and add some predefined number of days (3, 30, 365) to that date, and write the calculcated new date to a field. Here is an example of the code for one of the values (Add 3 days to current date):

Selenium.prototype.doTypeTodaysDatePlus3 = function(locator){
var dates = new Date();
dates.setDate(dates.getDate() + 3);
var day = dates.getDate();
if (day < 10){
day = '0' + day;
}

month = dates.getMonth() + 1;
if (month < 10){
month = '0' + month;
}
var year = dates.getFullYear();
var prettyDay = year + '-' + month + '-' + day;
this.doType(locator, prettyDay);
}

To account for the other two predefined day modifiers, I simply copied the code above two more times and replaced the +3 with +30 and +365 respectively.

One could easily improve this code by parameterizing X for the number of days as another argument.

Hope this helps someone.

 

File: 

AttachmentSize
Plain text icon expireDate.js.txt1.14 KB

Type: 

User-Extension