我在Selenium RC中使用extensions.js时遇到了困难。
我的Java代码是,
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('testing','test');");
selenium.type("userName", "admin");
selenium.type("password", "admin");
Result=selenium.isElementPresent("//input[@type='image']");
selenium.click("//input[@type='image']");
selenium.waitForPageToLoad(Timeout);
}
}
我的user-extensions.js是
Selenium.prototype.doDisplayAlert = function(value, varName)
{
alert(value);
};
当我使用getEval()方法运行时,抛出了此错误,
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)
如果我使用runScript(),则对象预期错误在浏览器中作为JS错误抛出。在这两种情况下,警报都显示在RC窗口中。我认为,执行命令后,selenium无法获得控制权。
任何想法?
答案 0 :(得分:1)
答案 1 :(得分:1)
尝试:
proc.doCommand("displayAlert", args); //whatever args you want to use
答案 2 :(得分:-1)
...试
selenium.displayAlert('testing', 'test');
但是将do
放在函数名称的前面,告诉api它是一个“动作”,暗示了其他一些东西,请参阅文档。