开发者

using a remote Selenium server from Selenium test cases written in groovy

开发者 https://www.devze.com 2023-01-09 09:38 出处:网络
I\'ve used Selenium ide to record test cases, export them to Groovy source, modify as necessary and run them. The default code exp开发者_如何转开发ects a server on localhost, I\'d like to use a server

I've used Selenium ide to record test cases, export them to Groovy source, modify as necessary and run them. The default code exp开发者_如何转开发ects a server on localhost, I'd like to use a server on a remote machine. How can I do this? When looking at the doc for GroovySeleneseTestCase it does not appear there is a setUp() method that allows you to use a remote server. The only option I can think of is setting a server host and port through the default selenium object in my setUp() method but am not sure how to do this.


In Java:

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

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

just replace localhost and 3300 by the server's address and the correct port. I don't know Groovy, but it shouldn't be much different. Of course, the server has to be started first and the firewall configured.


In order to get this to work I had to create a custom instance of GroovySelenium, assign it to the test class, and not call the super.setUp method. Code example follows.

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)
}

Assuming you have this setup method in a class called MyTest, want to test google.com using a selenium server with host name myserver, port 5555, and using internet explorer as the browser the following code would work.

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

精彩评论

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

关注公众号