Tuesday, 10 January 2012

User Extension with Selenium IDE


Steps

  1. write the extension code into a new .js file. You can place it anywhere on your drive.
  2. Open Options - Options... in the menu bar.
  3. Choose the saved file in "Selenium Core Extensions" field and click OK.
  4. Restart Selenium IDE by closing the window and opening it again.

Sample Example of User-Extensions.js


Selenium.prototype.doTypeTodaysDate = function(locator){
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.doType(locator, prettyDay);
}


Above code will enter current date in dd/mm/yyyy format in specified Locator(Passeed as argument)

Note: - After adding above User-Extensions.js with selenium IDE , you can see additional command “TypeTodaysDate” in selenium ide command list. 

steps to call this function from ide
1. write command "TypeTodaysDate" in selenium IDE
2. Enter Locator in Target ( Locator of webedit , where you want to enter current date)
3. Run selenium IDE

5 comments:

  1. Replies
    1. when I attached and, restarted IDE , after that IDE does not show "TypeTodaysDate" command on typing in command text box, and executing this gives error as "[error] Unknown command: 'TypeTodaysDate'"


      What could be the reson?

      Delete
    2. Hi Mahesh,

      Can you try by providing .js file path in 'Selenium core Extension' Field in place of 'Selenium IDE Extensions' field of Selenium IDE option window.

      Delete
  2. thanks for core it is working fine

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete