繁体   English   中英

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

[英]using a remote Selenium server from Selenium test cases written in groovy

我已经使用Selenium ide来记录测试用例,将其导出到Groovy源,根据需要进行修改并运行它们。 默认代码需要在本地主机上的服务器,我想在远程计算机上使用服务器。 我怎样才能做到这一点? 在查看GroovySeleneseTestCase的文档时,它没有出现,但是有一个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的硒服务器并使用Internet Explorer作为浏览器来测试google.com,则以下代码将起作用。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM