开发者

Extending Selenium RC with new methods

I am extending the selenium RC by using user-extension.js. It is able to call the new method function, but throwing following error message.

*ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: Object doesn't support this property or method*

As this program is executed on Google.com, any one can copy the sample code and execute on their respective PCs.

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 and Selenium JAR are in the same folder and executing the Selenium JAR using following command.

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

Any help on this issue?


It means that your command in user-extension file is not locating the element. Try running that in the IDE and check if it works fine


It works for me. Here is the modified user-extensions.js file code:

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

Rest all remains the same. Hope this helps!!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜