Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Selenium RC中使用user-extension.js_Selenium - Fatal编程技术网

在Selenium RC中使用user-extension.js

在Selenium RC中使用user-extension.js,selenium,Selenium,我在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="

我在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在执行命令后无法获得控件

有什么想法吗?

试试

selenium.displayAlert('testing', 'test');

但是,如果将
do
放在函数名前面,您会告诉api这是一个“动作”,这意味着其他一些事情,请参阅文档。

我认为您的问题可以通过研究这个来解决。请注意,我不是硒方面的专家,只是在寻找问题的解决方案时无意中发现了此文档

希望这有帮助

谢谢!

试试看:

proc.doCommand("displayAlert", args); //whatever args you want to use

是否已使用Selenium RCs用户扩展参数加载扩展?