user extensions in Selenium RC using java..

677 views
Skip to first unread message

dineshra

unread,
Jun 25, 2008, 6:21:11 AM6/25/08
to selenium-users...@googlegroups.com
Hello All,
I'm trying to use user-extensions functionality in selenium RC. I have read through the posts \\ but could not find reasonable solution to implement it. most of them talk what is already there in the \\ selenium site but do not provide clear solution.
here is the code from user-extension sample file
// All do* methods on the Selenium prototype are added as actions.\\ // Eg add a typeRepeated action to Selenium, which types the text twice into a text box.\\ // The typeTwiceAndWait command will be available automatically\\ Selenium.prototype.doTypeRepeated = function(locator, text) {\\ // All locator-strategies are automatically handled by "findElement"\\ var element = this.page().findElement(locator);
// Create the text to type\\ var valueToType = text + text;
// Replace the element text with the new text\\ this.page().replaceText(element, valueToType);\\ };
\\ from the above example what I can understand is we can add your own command to selenium simply by placing the above\\ code in user-extensions.js file and running selenium server like this
>java -jar selenium-server.jar -userExtensions <file> ( which is your .js file).
after this step , I assume doTypecommand will be avialable automatically , but above code says "typeTwiceAndWait" \\ will be availble automatically , I'm confused here.
Then what next , write your automated script using java?. this part is not available anywhere in the forum. how to call this command\\ can some body please help , probably using an example .. I would really appricate for your help..
Thanks\\ Dinesh

Bob

unread,
Jun 25, 2008, 1:21:39 PM6/25/08
to selenium-users...@googlegroups.com
Hey Dinesh,

I've been having the same woes as I've been trying to add a simple looping functionality to my test programs and have thus far been unable to get Selenium Remote Control to accept the extension I want. I've tried adding the code into the script file user-extensions.js and calling the suites like:

java -jar selenium-server.jar -htmlSuite *firefox <startURL> <suiteFile> <resultFile> -userExtensions user-extensions.js

This starts the test runner, however it does not bring up any page to be tested... I can get this javascript file to run as an extension in Sele IDE but would be very interested to find out how to get this to work in Remote Control.

asha

unread,
Jun 25, 2008, 11:29:00 PM6/25/08
to selenium-users...@googlegroups.com
Hi,

If you can rebuild selenium-server.jar with the your new user-extensions.js, it will recognize your custom functions.
I did this using Winzip. The steps followed are:

1) Downloaded the selenium-server.jar
2) Opened it using winzip and extracted the "user-extensions" file alone in it to my C drive. So now I have the user-extansions.js in my C:\core\scripts folder.
3) Edited user-extensions.js by adding some custom methods that I needed.
4) Now using Winzip again, added this modified user-extensions.js to the selenium-server.jar. For this,
-- Open selenium-server.jar using Winzip.
-- Use the "Add" button on the top bar of Winzip
-- In the "Add" window, browse to C:\core\scripts\user-extensions.js file
-- Make sure that the "Actions" choosen is "Add (and replace) Files" and "Save full path info" is checked in the "Folders" option.
-- This will replace the user-extensions.js in the selenium-server.jar with our modified user-extensions.js with same path information.
-- Close Winzip
5 ) Now the new selenium-server.jar is ready with your own user-extensions.
6) You can execute with usual RC syntax:

path/to/java -jar name-of-selenium-rc-jar -htmlSuite <browser> <startURL> <suiteFile> <resultFile>

I could do this successfully in my test environment and the version of Winzip I am using is Winzip 8.1

Regards,
Asha.

dineshra

unread,
Jun 27, 2008, 7:08:31 AM6/27/08
to selenium-users...@googlegroups.com
Hi asha,

Thanks for this information. I have tried to do thte sme way you explained , but I'm getting read/write permission error from winzip ,
what do I do ? I chekced the permission of the selenium server.jar , it seems I have given full control on this. pleas help..

asha

unread,
Jun 27, 2008, 9:15:58 AM6/27/08
to selenium-users...@googlegroups.com
When are you getting the error, while uploading the modfied user-extensions.js? Do you have read/write/Read & Execute/Modify/Full Control privileges on both selenium-server.jar and the core\scripts\user-extensions.js file ?

Or you may search google with the exact error message you are getting and I am sure you will get some helpful answers.

Regards,
Asha.

dineshra

unread,
Jun 27, 2008, 9:31:38 AM6/27/08
to selenium-users...@googlegroups.com
I have full permission on both selenium server and user-extensions.js file.

error: file not found or read and write permission or sharing prolem is the message i'm recieving when I try to add using winzip.
no luck yet from google search !http://clearspace.openqa.org/images/emoticons/cry.gif|border=0!

dineshra

unread,
Jun 27, 2008, 12:23:06 PM6/27/08
to selenium-users...@googlegroups.com
I could finaly add user-extensions.js to the selenium-server.jar , here are the steps ( if you guys are having probelms like me uisng win zip)

Say if you have selenium-server.jar in the following directory
c:/selenium-rc ,
create core/scripts directory under selenium-rc and place the modified user-extensions.js in here .

run this command a the prompt

C:/selenium-rc> jar uf selenium-server.jar core/scripts user-extensions.js this command will place user-extensions.js under core/scripts director of selenium-server.jar..

Now the hard bit ,, how to call the command doTypereapeated which I have placed in the user-extensions.js ????

I have used it as selenim.doTyperepeated("q" , "test"); in the following code , but getting java compile error. please could any one help me here ..


public void testGoogle() {\\ selenium.setSpeed("3000");\\ selenium.open("http://www.google.com/webhp?hl=en");\\ assertEquals("Google", selenium.getTitle());\\ selenium.type("q", "Selenium OpenQA");\\ *{font:color=#ff6600}selenium.dotypeRepeated("q" , "Google");{font}* //pause(30);\\ assertEquals("Selenium OpenQA", selenium.getValue("q"));\\ selenium.click("btnG");\\ selenium.waitForPageToLoad("5000");\\ assertEquals("Selenium OpenQA - Google Search", selenium.getTitle());\\ selenium.setContext("You are my lovely browser");\\ selenium.captureScreenshot("c:/Dinesh/screenshot.png");\\ //selenium.getEval ('javascript{}');\\ //selenium.msgAndWait();\\ }

dineshra

unread,
Jun 27, 2008, 7:02:55 PM6/27/08
to selenium-users...@googlegroups.com
I have tried this option before I add the user-extensions.js into the\\ selenium-server.jar. It didn't not work , so I'had to use this method,
Alos I'm not sure this method {font:color=#ff6600}java -jar selenium-server.jar -userExtensions user-extensions.js{font} will place user-extensions.js file into the core/scripts folder in server jar file. hence I placed the file directly there in the jar file

here under user extension section {font:color=#0000ff}http://release.openqa.org/selenium-core/0.8.0/reference.html \\ it says {font}
\\ By default, Selenium looks for a file called "user-extensions.js", and loads the javascript code found in that file. This file provides a convenient location for adding features to Selenium, without needing to modify the core Selenium sources.
In the standard distibution, this file does not exist. Users can create this file and {font:color=#ff9900}place their extension code in this common location{font}, removing the need to modify the Selenium sources, and hopefully assisting with the upgrade process

I'm using this code , so i'm sure it has no error as it is provided in the sample
Selenium.prototype.doTypeRepeated = function(locator, text) {\\ // All locator-strategies are automatically handled by "findElement"\\ var element = this.page().findElement(locator);\\ // Create the text to type\\ var valueToType = text + text;\\ // Replace the element text with the new text\\ this.page().replaceText(element, valueToType);\\ };
\\ so now , can you please tell me how to use this command in my java test script, ??
Any java people please help !!!


dineshra

unread,
Jul 1, 2008, 4:59:23 AM7/1/08
to selenium-users...@googlegroups.com
Haw-Bin,


It worked fine , thanks a lot ,

forseleni...@gmail.com

unread,
Jul 28, 2015, 10:51:43 PM7/28/15
to Selenium Users, selenium-users...@googlegroups.com, clear...@openqa.org, dine...@yahoo.com
Hi, I'm experiencing the same problem. How did you make it work? Thanks a lot.
Reply all
Reply to author
Forward
0 new messages