csj 发表于 2011-7-4 11:41:14

Selenium RC用Eclipse执行,总报Connection refused: connect

Exception in thread "main" java.lang.RuntimeException: Could not contact Selenium Server; have you started it on 'localhost:4445' ?
Read more at http://seleniumhq.org/projects/remote-control/not-started.html
Connection refused: connect
代码如下,求大侠支招
package SeScript;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class MainTest {
       
        /**
       * @param args
       */
        public static void main(String[] args) throws Throwable{
                // TODO Auto-generated method stub
               
                System.out.println("ok");
                GoogleTest googleTest1=new GoogleTest();
                googleTest1.setUp();
                googleTest1.testGoogle();
                googleTest1.tearDown();
        }
       
       

       

}

class GoogleTest {
        private Selenium selenium;

        public void setUp() throws Exception {
        String url = "http://www.google.com";
        selenium = new DefaultSelenium("localhost", 4444, "*firefox", url);//4444 is default server port
        selenium.stop();
       
        selenium.start();
        }

        protected void tearDown() throws Exception {
        selenium.stop();
        }

        public void testGoogle() throws Throwable {
        selenium.open("http://www.google.com/webhp?hl=en");
        selenium.click("btnG");
        selenium.waitForPageToLoad("5000");

        }

        }

ivwseeqg 发表于 2011-7-5 11:37:06

没有启动selenium-server

ivwseeqg 发表于 2011-7-5 11:41:02

首先下载selenium-server.jar或者selenium-rc,然后在DOS下输入java -jar 安装包路径,启动成功即可!

C:\Documents and Settings\Administrator\桌面\study\selenium>java -jar e:\rc\sele
nium-server\selenium-server.jar
11:32:34.227 INFO - Java: Sun Microsystems Inc. 10.0-b19
11:32:34.243 INFO - OS: Windows XP 5.1 x86
11:32:34.337 INFO - v2.0 , with Core v2.0
11:32:34.931 INFO - RemoteWebDriver instances should connect to: http://127.0.0.
1:4444/wd/hub
11:32:34.931 INFO - Version Jetty/5.1.x
11:32:34.962 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
11:32:34.962 INFO - Started HttpContext
11:32:34.962 INFO - Started HttpContext[/,/]
11:32:35.134 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@17182c
1
11:32:35.134 INFO - Started HttpContext
11:32:35.150 INFO - Started SocketListener on 0.0.0.0:4444
11:32:35.150 INFO - Started org.openqa.jetty.jetty.Server@1c184f4

freedom2k 发表于 2011-9-5 13:45:00

要先启动server,然后再去跑你的用例

wuhuawu09 发表于 2011-10-8 14:11:30

have you started it on 'localhost:4445' ?

先启动服务4445端口。
页: [1]
查看完整版本: Selenium RC用Eclipse执行,总报Connection refused: connect