Selenium IDE - fix current date

I would like to know that with selenium there is a way to capture the current date, month, year, because the application I use has separate date, month, year fields, which we need to enter manually. The problem I have here is a test case will take a date <= 31 days in the future and will not accept a date in the past. therefore, if I have a way that I can capture the current date, month, year (numerical values) that will be useful

eg

<tr> <td>type</td> <td>form1:txtCoverDateDay</td> <td>02</td> </tr> <tr> <td>type</td> <td>form1:txtCoverDateMonth</td> <td>11</td> </tr> <tr> <td>type</td> <td>form1:txtCoverDateYear</td> <td>2011</td> </tr> 
+7
source share
1 answer

use storeEval

Below is an example of a fully working selenium test that exactly matches your requirements, to run it by opening the IDE, click the Source tab in the main window and paste the code between the <tbody>

 <tr> <td>open</td> <td>http://www.plus2net.com/php_tutorial/date-selection.php</td> <td></td> </tr> <tr> <td>storeEval</td> <td>new Date().setDate( new Date().getDate() + 31);</td> <td>date</td> </tr> <tr> <td>echo</td> <td>${date}</td> <td></td> </tr> <tr> <td>storeEval</td> <td>d=new Date( new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 31); d=d.getFullYear()</td> <td>year</td> </tr> <tr> <td>type</td> <td>name=year</td> <td>${year}</td> </tr> <tr> <td>echo</td> <td>${year}</td> <td></td> </tr> <tr> <td>storeEval</td> <td>d=new Date( new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 31); d=d.getMonth() + 1</td> <td>month</td> </tr> <tr> <td>select</td> <td>name=month</td> <td>value=${month}</td> </tr> <tr> <td>echo</td> <td>${month}</td> <td></td> </tr> <tr> <td>storeEval</td> <td>d=new Date( new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 31).getDate(); d= d.toString().length == 1 ? &quot;0&quot; + d : d;</td> <td>day</td> </tr> <tr> <td>select</td> <td>name=dt</td> <td>label=${day}</td> </tr> <tr> <td>echo</td> <td>${day}</td> <td></td> </tr> 

I added in javascript to return a date of 31 days in the future.

You can also use a combination of runScript and storeEval to get almost any information from the page.
The question I asked demonstrates the idea

Download an external js file containing useful test functions in selenium

Any other questions will add a comment and I will be happy to help :)

See @ icc97 comment for adding zero padding to dates.

+9
source

All Articles