Friday, September 4, 2009

Using User-Extensions With Selenium RC

If you Google “Selenium RC user-extension” you will find different approaches to using this feature. Below, is the official Selenium suggested approach.
Example using C#
1. Place your user extension in the same directory as your Selenium Server.

2. If you are using client code generated by the Selenium-IDE you will need to make a couple small edits. First, you will need to create an HttpCommandProcessor object with class scope (outside the SetupTest method, just below private StringBuilder verificationErrors;) HttpCommandProcessor proc;

3.Next, instantiate that HttpCommandProcessor object as you would the DefaultSelenium object. This can be done in the test setup.proc = new HttpCommandProcessor("localhost", 4444, "*iexplore", "http://google.co.in/");

4. Instantiate the DefaultSelenium object using the HttpCommandProcessor object you created. selenium = new DefaultSelenium(proc);

5. Within your test code, execute your 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. Notice that the first letter of your function is lower case, regardless of the capitalization in your user-extension. Selenium automatically does this to keep common JavaScript naming conventions. Because JavaScript is case sensitive, your test will fail if you begin this command with a capital. inputParams is the array of arguments you want to pass to the JavaScript user-extension. In this case there is only one string in the array because there is only one parameter for our user extension, but a longer array will map each index to the corresponding user-extension parameter. Remember that user extensions designed for Selenium-IDE will only take two arguments.
string[] inputParams = {"Hello World"};
proc.DoCommand("alertWrapper", inputParams);

6. Start the test server using the -userExtensions argument and pass in your user-extensinos.js file. java -jar selenium-server.jar -userExtensions user-extensions.js

No comments:

Post a Comment