2010-07-26 45 views
1

我已经使用Selenium ide记录测试用例,将它们导出到Groovy源代码,根据需要进行修改并运行它们。默认代码需要localhost上的服务器,我想在远程机器上使用服务器。我怎样才能做到这一点?在查看GroovySeleneseTestCase的文档时,不会出现允许您使用远程服务器的setUp()方法。我能想到的唯一选择是通过setUp()方法中的默认硒对象设置服务器主机和端口,但不知道如何执行此操作。使用来自Selenium的远程Selenium服务器编写的Groovy测试用例

回答

0

在Java:

HttpCommandProcessor processor = new HttpCommandProcessor("localhost", 3300, browserName, appBaseURL); 

selenium = new CustomSelenium(processor, browserName, waitToLoadTimeout, waitForConditionTimeout); 
selenium.start(); 

只是通过服务器的地址和正确的端口替换本地主机和3300。我不知道Groovy,但它应该没有太大的不同。当然,服务器必须先启动并配置防火墙。

0

为了得到这个工作,我不得不创建一个GroovySelenium的自定义实例,将其分配给测试类,而不是调用super.setUp方法。代码示例如下。

void setUp(String selServer, int selPort, String browser, String basePath) throws Exception { 
def tempSel=new DefaultSelenium(selServer, selPort, browser, basePath) 
selenium= new GroovySelenium(tempSel) 
selenium.start() 
setDefaultTimeout(30000) 
setCaptureScreenshotOnFailure(false) 
} 

假设你有一个名为MyTest的类此设置方法,要测试google.com使用硒服务器的主机名MYSERVER,端口5555,并使用Internet Explorer作为浏览器下面的代码会工作。

test=New MyTest() 
test.setUp("myserver",5555,"*iexplore","http://www.google.com") 
test.testMyTest() 
相关问题