【问题标题】:Extending Selenium RC with new methods用新方法扩展 Selenium RC
【发布时间】:2011-05-12 00:49:27
【问题描述】:

我正在使用 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  

对这个问题有任何帮助吗?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      其余的一切都保持不变。希望这会有所帮助!!!

      【讨论】:

        猜你喜欢
        • 2011-05-04
        • 2011-11-12
        • 2018-08-18
        • 1970-01-01
        • 1970-01-01
        • 2013-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多