从groovy编写的Selenium测试用例中使用远程Selenium服务器

从groovy编写的Selenium测试用例中使用远程Selenium服务器,groovy,selenium,Groovy,Selenium,我使用SeleniumIDE记录测试用例,将它们导出到Groovy源代码,根据需要进行修改并运行它们。默认代码要求本地主机上有一台服务器,我希望使用远程机器上的服务器。我该怎么做?当查看GroovySelenceTestCase的文档时,似乎没有允许您使用远程服务器的setUp()方法。我能想到的唯一选项是通过我的setUp()方法中的默认selenium对象设置服务器主机和端口,但我不确定如何执行此操作。在Java中: HttpCommandProcessor processor = new

我使用SeleniumIDE记录测试用例,将它们导出到Groovy源代码,根据需要进行修改并运行它们。默认代码要求本地主机上有一台服务器,我希望使用远程机器上的服务器。我该怎么做?当查看GroovySelenceTestCase的文档时,似乎没有允许您使用远程服务器的setUp()方法。我能想到的唯一选项是通过我的setUp()方法中的默认selenium对象设置服务器主机和端口,但我不确定如何执行此操作。

在Java中:

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

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

只需将localhost和3300替换为服务器的地址和正确的端口即可。我不知道Groovy,但它应该没什么不同。当然,必须首先启动服务器并配置防火墙。

为了使其正常工作,我必须创建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的类中有这个安装方法,您想使用主机名为myserver、端口为5555的selenium服务器测试google.com,并使用internet explorer作为浏览器,下面的代码可以工作

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