User-Extensions js file with Selenium RC

1 –  Create user extensions file and place your user-extension.js file in the same directory where Selenium Server.
Run selenium server using below command.
java -jar selenium-server.jar -userExtensions user-extensions.js
Note: User extension file name must be same as user-extensions.js file 
2. Create an HttpCommandProcessor object with in class scope (outside the Test method)
selenium = new Def HttpCommandProcessor proc;


3. Instantiate that HttpCommandProcessor object as you would the DefaultSelenium object. This can be done in the Test setup method as created below.

proc = new HttpCommandProcessor("localhost", 4444, "*chrome", "applicationURL");

4. Instantiate the DefaultSelenium object using the HttpCommandProcessor object as created below.

selenium = new DefaultSelenium(proc);

5. Within test code, execute user-extension by calling it with the DoCommand() method of HttpCommandProcessor. This method takes two arguments: a string to identify the user-extension method you want to use and string array to pass arguments.
String[] inputParams = {"10000"};
      proc.doCommand("waitForAjaxRequest", inputParams);

Note: First letter of your function is lower case, regardless of the capitalization in your user-extension file.
  
User-Extension files code:


Selenium.prototype.doWatchAjaxRequests = function() {
  selenium.browserbot.getCurrentWindow().Ajax.Responders.register({
    onComplete: function() {Selenium.AjaxRequestFinished = true}
  });
}

Selenium.prototype.doWaitForAjaxRequest = function(timeout) {
  return Selenium.decorateFunctionWithTimeout(function() {
    if (Selenium.AjaxRequestFinished) {
      Selenium.AjaxRequestFinished = false;
      return true;
    }
    return false;
  }, timeout);
}
Selenium.AjaxRequestFinished = false;

No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution