Selenium RC错误未知协议:localhost

时间:2011-03-17 17:11:23

标签: ruby-on-rails-3 selenium rspec

我刚开始使用Selenium和Ruby on Rails 3,我的代码为

before(:all) do
  @verification_errors = []
  @selenium_driver = Selenium::Client::Driver.new \
    :host => "localhost",
    :port => 2195,
    :browser => "*firefox C:/Program Files (x86)/Mozilla Firefox/firefox.exe",
    :url => "localhost:3000",
    :timeout_in_second => 60

  @selenium_driver.start_new_browser_session
end

after(:all) do
  @selenium_driver.close_current_browser_session
  @verification_errors.should == []
end

it "should open the create new user page" do
  page.open "http://localhost:3000/"
  !page.is_text_present("translation missing").should be_false
  page.click "link=Register"
  page.wait_for_page_to_load "30000"
  !page.is_text_present("translation missing").should be_false
  page.is_text_present("New Account").should be_true
end

但是当我试图运行它们时,我得到了

11:02:29.118 INFO - Command request: getNewBrowserSession[*firefox C:/Program Files (x86)/Mozilla Firefox/firefox.exe, localhost:3000, , ] on session null
11:02:29.118 INFO - creating new remote session
11:02:29.119 INFO - Allocated session 5cbd2c60271b490ea90eccb193cb1d84 for localhost:3000, launching...
11:02:29.119 ERROR - Failed to start new browser session, shutdown browser and clear all session data
java.lang.RuntimeException: java.net.MalformedURLException: unknown protocol: localhost
    at org.openqa.selenium.net.Urls.toProtocolHostAndPort(Urls.java:32)
    at org.openqa.selenium.browserlaunchers.LauncherUtils.getDefaultRemoteSessionUrl(LauncherUtils.java:121)
    at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launchRemoteSession(FirefoxChromeLauncher.java:413)
    at org.openqa.selenium.server.browserlaunchers.FirefoxLauncher.launchRemoteSession(FirefoxLauncher.java:110)
    at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSession(BrowserSessionFactory.java:373)
    at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:125)
    at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:87)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowserSession(SeleniumDriverResourceHandler.java:786)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(SeleniumDriverResourceHandler.java:423)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest(SeleniumDriverResourceHandler.java:394)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:147)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
    at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
    at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
    at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
    at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
    at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
    at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
    at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: java.net.MalformedURLException: unknown protocol: localhost
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at org.openqa.selenium.net.Urls.toProtocolHostAndPort(Urls.java:24)
    ... 19 more
11:02:29.121 INFO - Got result: Failed to start new browser session: Error while launching browser on session null

我不明白localhost如何成为一个未知的协议,我自己的搜索没有找到太多帮助。

有人可以帮助我,提前谢谢

1 个答案:

答案 0 :(得分:3)

Localhost正在成为未知协议,因为您之前没有指定任何协议,您应该将:url => "localhost:3000"更改为:url => "http://localhost:3000"以包含协议(http)。

此外,(至少在Java上的Selenium上),当执行相当于page.open的操作时,通常会使用相对路径。