Hi,
I found that user can place user-defined functions in user-extension.js which is in selenium-server.jar file. But I am not sure once I place my function in user-extension.js[after unzipping the file from selenium-server.jar ], how to get that function in my java test case file. Can some one explain me the steps involved here? I found few documents which do not give clear picture on this.
Thanks
Sudhindra
When you start your selenium RC server you need to tell it to look for your user-extension file. It's an option like %java -jar selenium-rc.jar -userExtensions user-extension.js. Basically you want to put custom JavaScript functions in this file. This file will be included on all of your pages during the selenium test run. To access them you'll need to do something like: selenium.getEval("myJavaScriptFunction('variable1','variable2')"). Make sense?
Joe
Hi Joe,
Thanks for the support. Between in my framework, the selenium server is started using seleniumServer = new SeleniumServer(4444, false, true); In this case how can I include user-extension.js?
Thanks
Sudhindra
Well without knowing which version of selenium you are using it's hard to say exactly, but I think the method you are looking for is addNewStaticContent. So in your example it would look something like this:
SeleniumServer seleniumServer = new SeleniumServer(4444, false, true);
seleniumServer.addNewStaticContent(new File("/path/to/user-extensions.js"));
I don't ever start the server this way, so I'm just guessing a little here. Hope that helps.
Joe
Hi,
I am also want to know about this user-extension.js.
If anybody knows help me and give me step by step
process of using user extension.js .
Thanks in advance
velavan.
Velavan, your question would be a lot more helpful if you explain what you've tried to do. On the selenium website there is information about using this file, http://selenium-rc.openqa.org/options.html, as well as in my previous post I gave pretty detailed instructions on what to do. Have you actually tried anything on your own yet?
Joe
Hi Joe,
I am using selenium version 1.0 beta. Here are the steps I am trying to make use of user-extnesion.js:
seleniumServer = new SeleniumServer(4444, false, true);
seleniumServer.start();
seleniumServer.addNewStaticContent(new File("C:/Automation/Selenium/SelNG/framework/lib/user-extensions.js"));
The I am calling:
selenium.getEval("SendKeys('pab','ENTER')");
This gives me an ERROR: Threw an exception: SendKeys is not defined
Thanks
Sudhindra
Can you post the contents of C:/Automation/Selenium/SelNG/framework/lib/user-extensions.js?
Remember JavaScript is case sensitive. "SendKeys" is kind of a weird function name for JS. Usually they start with a lower case letter.
Hi Joe,
Here is the user-extension.js content:
Selenium.prototype.doSendKeys = function(windowname, keys) {
try
{
var objShell = new ActiveXObject("wscript.shell");
objShell.AppActivate(windowname);
objShell.SendKeys(keys);
}
catch(w)
{
throw new Error( 'sendkey did something' + w );
}
objShell = null;
};
Thanks
Sudhindra
I think your function will be "sendKeys" not "SendKeys". From the selenium documentation:
All doFoo methods on the Selenium prototype are added as actions. For each action foo there is also an action fooAndWait registered.
Try that and see if it helps.
Hi
i have used this asserttextpresent js file.but i not sure how to use this js
i ran Selenium RC from CommandPromt
d:java -jar selenium-server.jar -multiwindow -userExtentions D:\path to .js -htmlsuite *iexplore http://localhost:9000/ D\TestSuite.html D://results.html
this command working fine but asserttest present .s not working..
the same time in testsuite working good
so i want to know about js file using flow
Selenium.prototype.assertTextPresentCount = function(Your, 1) {
var allText = this.page().bodyText();
var pattern = new RegExp(Your,"g");
LOG.debug("expect text =" + Your);
LOG.debug("expect count=" + 1);
LOG.debug("matchingText=" + allText.match(pattern));
if(allText == "") {
Assert.fail("Page text not found");
} else if(allText.indexOf(Your) == -1) {
if (1 != 0) {
Assert.fail("'" + Your + "' count doesn't match.");
}
} else if(allText.match(pattern).length != count) {
Assert.fail("'" + Your + "' count doesn't match.");
}
};
Hi Joe,
Let me try again with sendKeys method. BTW you referred selenium documentation regarding do commands. Where can I get that?
Hi Joe,
I re-tried using function in user-extension.js file as :
selenium.getEval("sendKeys('pab','')");
But it failed with error "ERROR: Threw an exception: sendKeys is not defined".
-Sudhindra
