51Testing软件测试论坛

标题: 用java代码启动selenium server报错 [打印本页]

作者: fengzhulin    时间: 2012-2-28 11:20
标题: 用java代码启动selenium server报错
代码如下:
package login;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.thoughtworks.selenium.*;
import com.beust.testng.*;
import java.util.regex.Pattern;
import  sun.io.*;
import sun.nio.cs.ext.*;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import java.io.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;

public class Firefox extends SeleneseTestNgHelper {
    @BeforeClass
    public void setUp() throws Exception {
        RemoteControlConfiguration cfg = new RemoteControlConfiguration();
        File filefoxProfile=new File("D:\firefox-profile");
        cfg.setPort(4444);
        cfg.setReuseBrowserSessions(true);
        cfg.setBrowserSideLogEnabled(true);
        cfg.setSingleWindow(true);
        cfg.setFirefoxProfileTemplate(filefoxProfile);
        SeleniumServer server = new SeleniumServer(cfg);
        server.start();
        selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.yihaodian.com/");
        selenium.start();
    }
    //@Parameters({"username","password"})   
   
    @Test
    public void test222() throws Exception {
        selenium.open("https://passport.yihaodian.com/passport/login_input.do");
        Thread.sleep(3000);
        selenium.type("id=un", "aaa@163.com");//input  username
        selenium.type("id=pwd", "pwd");//input password
        selenium.click("link=请登录");
           Thread.sleep(3000);
      //selenium.open("http://www.yihaodian.com/product/1017_1");//buy a product which id=1017 and warehouseID=1
      
      
        }
     
    }

用以上代码运行后,还是报错如下

com.thoughtworks.selenium.SeleniumException: Connection refused: connect
    at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:111)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:90)
    at com.thoughtworks.selenium.DefaultSelenium.captureScreenshot(DefaultSelenium.java:719)
    at com.thoughtworks.selenium.ScreenshotListener.onTestFailure(ScreenshotListener.java:27)
    at com.thoughtworks.selenium.ScreenshotListener.onConfigurationFailure(ScreenshotListener.java:41)
    at org.testng.internal.Invoker.runConfigurationListeners(Invoker.java:1842)
    at org.testng.internal.Invoker.handleConfigurationFailure(Invoker.java:333)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:236)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.TestRunner.beforeRun(TestRunner.java:637)
    at org.testng.TestRunner.run(TestRunner.java:605)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1142)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1067)
    at org.testng.TestNG.run(TestNG.java:979)

不知为何,求教。我用的testng,导入的包有selenium-server-standalone-2.19.0.jar和selenium-java-2.20.0.jar这2个包
作者: 遇上鱼子    时间: 2012-3-16 16:37
你的selenium服务起了没有?




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2