Selenium RC error unknown protocol: localhost
I just begin to start use Selenium with Ruby on Rails 3, I have my code as
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
But when I'm trying to run them, I got
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.&l开发者_开发知识库t;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
I didn't understand how come localhost become an unknown protocol, and I didn't find much help by my own searching.
Can someone help me please, thanks in advance
Localhost is becoming an unknown protocol because you're not specifying any protocol before it, you should change :url => "localhost:3000"
to :url => "http://localhost:3000"
to include the protocol (http).
Also, (at least on Selenium on Java) one usually uses relative paths when doing the equivalent of page.open
.
精彩评论