Imagine that in the previous example you wanted to have the extension method verify the text on the screen instead of having a separate step to do the verification or assertion. This can make tests a lot more compact and possibly easier to read.
We can see this in the next example:
Open your favorite text editor and the user extensions file that you created earlier.
Create a new function called
doFireDateAndVerifyText
with the following snippet:Selenium.prototype.doFireDateAndVerifyText = function(locator,value){ var dates = new Date(); 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 = day + '/' + month + '/' + year; this.browserbot.getUserWindow().checkDate(prettyDay); var lastResult = new CommandResult(); try{ var realValue = this.getText(locator); if (realValue...