【问题标题】:Selenium RC error unknown protocol: localhostSelenium RC 错误未知协议:localhost
【发布时间】:2011-03-17 17:11:22
【问题描述】:

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

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 是怎么变成未知协议的,自己搜索也没找到多大帮助。

谁能帮帮我,在此先感谢

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-06-21
      • 1970-01-01
      • 2016-01-11
      • 2016-04-22
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 2019-03-12
      • 2014-11-24
      相关资源
      最近更新 更多