Marthin
Marthin

Reputation: 6543

JavaScript within selenium test

I need to add a date comparison test to my selenium tests. Are there any restrictions when it comes to adding JavaScript within the tests? In my case I have the date form like this "2011-01-01 15:30" and I need to break out the numbers to do a JavaScript date like this new Date(2011,1,1,15,30).

<tr>
<td>open</td>
<td>http://www.google.com/search?hl=en&amp;q=selenium+verifyEval</td>
<td></td>
</tr>
<tr>
<td>storeText</td>
<td>//p[@id='resultStats']/b[3]</td>
<td>resultCount</td>
</tr>
<tr>
<td>storeEval</td>
<td>//here I would put in the javascript to parse the two strings "2010-01-01 13:15", "2010-01-02 11:15" to a new Date(2010,1,1,13,15),new Date(2010,1,2,11,15) and return a bool if true or false</td>
<td>isDateEqual</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>${isDateEqual}</td>
<td>true</td>
</tr>

Upvotes: 0

Views: 337

Answers (1)

Ross Patterson
Ross Patterson

Reputation: 9570

Nope, that ought to work fine. Except, of course, that JavaScript's brain-damaged Date() thinks that months (and only months) run from 0 to 11.

Upvotes: 1

Related Questions