Using user-extension.js in Selenium RC
I am having difficulty in using the extensions.js in Selenium RC.
My Java Code is,
import com.thoughtworks.selenium.*;
import junit.framework.*;
import java.lang.String;
public class javaErrorCheck extends SeleneseTestCase
{
Boolean Result=false;
String S=null;
String Host="localhost";
String Timeout="30000";
public void setUp() throws Exception
{
setUp("http://"+Host+"/", "*iexplore");
}
public static Test suite()
{
return new TestSuite(javaErrorCheck.class);
}
public static void main(String args[])
{
junit.textui.TestRunner.run(suite());
}
public void test_Login() throws Exception
{
selenium.setTimeout(Timeout);
selenium.open("http://"+Host+"/LoginPage.do");
selenium.windowFocus();
selenium.windowMaximize();
selenium.windowFocus();
selenium.getEval("doDisplayAlert('tes开发者_如何学运维ting','test');");
selenium.type("userName", "admin");
selenium.type("password", "admin");
Result=selenium.isElementPresent("//input[@type='image']");
selenium.click("//input[@type='image']");
selenium.waitForPageToLoad(Timeout);
}
}
my user-extensions.js is
Selenium.prototype.doDisplayAlert = function(value, varName)
{
alert(value);
};
When I run this using getEval() method, this error was thrown,
1) test_Login(javaErrorCheck)*com.thoughtworks.selenium.SeleniumException:
ERROR: Threw an exception: Object expected*
at
com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at
com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
at
com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
at
com.thoughtworks.selenium.DefaultSelenium.getEval(DefaultSelenium.java:443)
at javaErrorCheck.test_Login(javaErrorCheck.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at
com.thoughtworks.selenium.SeleneseTestCase.runBare(SeleneseTestCase.java:212)
at javaErrorCheck.main(javaErrorCheck.java:23)
If I use runScript(), object expected error was thrown in the browser as a JS error. In both the cases, alert is shown in the RC window. I think, selenium couldn't get the control after executing the command.
Any Ideas?
Try:
proc.doCommand("displayAlert", args); //whatever args you want to use
I think your problem could be solved by looking into this link. Please note that I am not expert in Selenium, just that I have unintentionally found this document while I was searching for solution to my problem.
Hope this helps.
Thanks @!
Try...
selenium.displayAlert('testing', 'test');
But putting the do
in front of the function name you tell the api that it is an 'action' which implies some other things, see the docs.
精彩评论