Wednesday, 20 February 2013

User Extension in selenium


Some time it is necessary to add some more functionality in selenium. This can be achieved by extending user-extensions.js file.



For Ex. You want to add a method in selenium which shows a alert box.

To do this follow steps :
  • Go to your server jar
  • Open in winrar
  • Goto core/scripts and edit user-extensions.js file
  • Add Selenium.prototype.doAlert =function()
  •   { 
  •     alert('hello');
  •   }
  • Save and close the file.
  • Start the server with -userExtensions switch
  • i.e java -jar selenium-server-standalone-2.24.1.jar -userExtensions user-extensions.js
Use following java code to execute user defined function :

 void fun()
{
HttpCommandProcessor http=new HttpCommandProcessor("localhost", 4444, "*iexplore", "http://www.google.com");
            sel=new DefaultSelenium(http);
           
            sel.start();
            sel.open("/");
            http.doCommand("alert", null); //This line executes alert method.
}

No comments:

Post a Comment