I need to get tomorrow date and need to store in selenium IDE.
Can anyone help this.
I need to get tomorrow date and need to store in selenium IDE.
Can anyone help this.
You can get tomorrows Date like this :
var d = new Date();
d.setDate(d.getDate() + 1)
console.log(d.toLocaleDateString();) //or d, depends on how you want that date
and for storing it in Selenium, maybe this could Help you
For the above issue, i have done bin solution on codebins. demo link for it as below:
Demo: http://codebins.com/bin/4ldqp9v
Please, let me know if this solution is helpful for you or not by adding your comment.
HTML:
<div id="panel">
<input type="text" size="15" id="txtdate" name="txtdate" />
<input type="button" id="btndate" name="btndate" value="Show Tommorrow Date" />
<div id="result">
</div>
</div>
Javascript:
var dateBtn = document.getElementById('btndate');
dateBtn.onclick = function() {
var strdate = document.getElementById('txtdate').value;
if (strdate != "" && strdate != null && typeof(strdate) != "undefined") {
if (isValidDate(strdate)) {
var userdate = new Date(strdate);
var newdate = new Date(userdate.getTime() + 1 * 24 * 60 * 60 * 1000);
document.getElementById("result").innerHTML = "Tomorrow date is: " + (newdate.getMonth() + 1) + "/" + newdate.getDate() + "/" + newdate.getFullYear() + " [MM/dd/YYYY]";
}
} else {
alert("Invalid date format value..!");
return false;
}
}
//Function for checking valid date format/value.
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YYYY
// Also separates date into month, day, and year variables
var datePat = /^(\d{2,2})(\/)(\d{2,2})\2(\d{4}|\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date must be in MM/DD/YYYY format")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31");
return false;
}
if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
alert("Month " + month + " doesn't have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day == 29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
}
}
return true; // date is valid
}
Selenium.prototype.doGenerateTomorrowDate = function( varName1, varName2 )
{
var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
var month = monthNames[month];
storedVars[ varName1 ] = day;
storedVars[ varName2 ] = month;
};
<tr>
<td>generateTomorrowDate</td>
<td>x</td>
<td>y</td>
</tr>
<tr>
<td>echo</td>
<td>${x}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${y}</td>
<td></td>
</tr>
This will return tomorrow day and month.
Using the selenium [html] scripting, you can use this. Simply put, get right now's date/time, and add 86400000 milliseconds to it (the number of ms in a day = 24h*60m*60s*1000ms)
<tr>
<td>storeEval</td>
<td>d=new Date(new Date().getTime()+86400000)</td>
<td>tomorrow</td>
</tr>
<tr>
<td>echo</td>
<td>${tomorrow}</td>
<td></td>
</tr>