用新方法扩展Selenium RC

时间:2010-11-18 13:12:17

标签: javascript selenium selenium-rc user-extensions.js

我正在使用user-extension.js扩展selenium RC。 它能够调用新方法函数,但抛出以下错误消息。

  

* 错误:命令执行失败。请在http://clearspace.openqa.org的论坛中搜索日志窗口中的错误详细信息。   错误消息是:对象不支持此属性或   方法 *

由于此程序在Google.com上执行,任何人都可以复制示例代码并在各自的PC上执行。

package package1;  

import static org.testng.AssertJUnit.*;  
import org.testng.annotations.*;  
import com.thoughtworks.selenium.*;  


public class Sample2  
{  
private static final String Timeout = "30000";  
private static final String BASE_URL = "http://google.com/";  
private static final String BASE_URL_1 = "/";  
private Selenium selenium;  
private HttpCommandProcessor proc;  

@BeforeClass  
protected void setUp()throws Exception  
{  
proc = new HttpCommandProcessor("localhost", 4444, "*iexplore", BASE_URL);  
selenium = new DefaultSelenium(proc);   
selenium.start();  
selenium.windowFocus();  
selenium.windowMaximize();  
selenium.windowFocus();  
}  

@AfterClass(alwaysRun=true)    
protected void tearDown() throws Exception    
{    
selenium.stop();    
}    

@Test(groups="search")  
public void test_GoogleSearch() throws Exception  
{  
selenium.open(BASE_URL_1);  
selenium.type("name=q", "Bharath Marrivada");  
//selenium.click("btnG");   
proc.doCommand("myMethod",new String[] {"btnG"}); //user extension  
Thread.sleep(5000);   
}  
}  

user-extension.js  
Selenium.prototype.doMyMethod = function(inputParams)   
{  
this.browserbot.click("btnG");  
return null;  
};  

.js和Selenium JAR位于同一文件夹中,并使用以下命令执行Selenium JAR。

java -jar selenium-server.jar -userExtensions user-extensions.js  

有关此问题的任何帮助?

2 个答案:

答案 0 :(得分:0)

这意味着用户扩展文件中的命令未找到该元素。尝试在IDE中运行它并检查它是否正常工作

答案 1 :(得分:0)

它对我有用。以下是修改后的user-extensions.js文件代码:

Selenium.prototype.doMyMethod = function(locator) {
    var element = this.page().findElement(locator);
    element.click();
};

休息所有保持不变。希望这会有所帮助!!!