开启Mac OS X 10.10
,Mozilla Firefox 38.3.0
和java version "1.7.0_79"
时,我启动了Selenium中心和节点:
java -jar selenium-2.47.1.jar -role hub
java -jar selenium-2.47.1.jar -role webdriver -hubHost 127.0.0.1
并运行此测试:
require "rspec"
require "capybara/rspec"
Capybara.app_host = "https://fb.*****.com/"
require "selenium/webdriver"
Capybara.register_driver :my_driver do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
desired_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox firefox_profile: profile
Capybara::Selenium::Driver.new(app,
desired_capabilities: desired_capabilities,
browser: :remote,
url: "http://#{ENV["HUB_ADDRESS"]}:4444/wd/hub",
)
end
Capybara.default_driver = :my_driver
feature "my feature" do
scenario "my scenario" do
visit ""
end
end
它适用于:
HUB_ADDRESS = 127.0.0.1 rspec test.rb
当我在CentOS release 6.7 (Final)
,Mozilla Firefox 38.3.0
和openjdk version "1.8.0_51"
上运行时:
java -jar selenium-2.47.1.jar -role hub
DISPLAY =:1 java -jar selenium-2.47.1.jar -role webdriver -hubHost 127.0.0.1
和Xvfb:
Xvfb:1 -ac -screen 0 1280x1024x24
它在测试日志中失败了:
1) my feature my scenario
Failure/Error: visit ""
Selenium::WebDriver::Error::UnknownError:
Bad request
Command duration or timeout: 199 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'vs01.*****.me', ip: '*****', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-042stab108.1', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.firefox.FirefoxDriver (org.openqa.selenium.UnsupportedCommandException)
# [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstructorAccessorImpl.java):-2:in `newInstance0'
# [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstructorAccessorImpl.java):62:in `newInstance'
# [remote server] sun.reflect.DelegatingConstructorAccessorImpl(DelegatingConstructorAccessorImpl.java):45:in `newInstance'
# [remote server] java.lang.reflect.Constructor(Constructor.java):422:in `newInstance'
# [remote server] org.openqa.selenium.remote.ErrorHandler(ErrorHandler.java):206:in `createThrowable'
# [remote server] org.openqa.selenium.remote.ErrorHandler(ErrorHandler.java):158:in `throwIfResponseFailed'
# [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):595:in `execute'
# [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):242:in `startSession'
# [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDriver.java):128:in `<init>'
# [remote server] org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java):223:in `<init>'
# [remote server] org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java):216:in `<init>'
# [remote server] org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java):134:in `<init>'
# [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstructorAccessorImpl.java):-2:in `newInstance0'
# [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstructorAccessorImpl.java):62:in `newInstance'
# [remote server] sun.reflect.DelegatingConstructorAccessorImpl(DelegatingConstructorAccessorImpl.java):45:in `newInstance'
# [remote server] java.lang.reflect.Constructor(Constructor.java):422:in `newInstance'
# [remote server] org.openqa.selenium.remote.server.DefaultDriverProvider(DefaultDriverProvider.java):103:in `callConstructor'
# [remote server] org.openqa.selenium.remote.server.DefaultDriverProvider(DefaultDriverProvider.java):97:in `newInstance'
# [remote server] org.openqa.selenium.remote.server.DefaultDriverFactory(DefaultDriverFactory.java):60:in `newInstance'
# [remote server] org.openqa.selenium.remote.server.DefaultSession$BrowserCreator(DefaultSession.java):222:in `call'
# [remote server] org.openqa.selenium.remote.server.DefaultSession$BrowserCreator(DefaultSession.java):1:in `call'
# [remote server] java.util.concurrent.FutureTask(FutureTask.java):266:in `run'
# [remote server] org.openqa.selenium.remote.server.DefaultSession$1(DefaultSession.java):176:in `run'
# [remote server] java.util.concurrent.ThreadPoolExecutor(ThreadPoolExecutor.java):1142:in `runWorker'
# [remote server] java.util.concurrent.ThreadPoolExecutor$Worker(ThreadPoolExecutor.java):617:in `run'
# [remote server] java.lang.Thread(Thread.java):745:in `run'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/response.rb:71:in `assert_ok'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/http/common.rb:78:in `new'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/http/common.rb:78:in `create_response'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/http/default.rb:90:in `request'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/bridge.rb:657:in `raw_execute'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/bridge.rb:122:in `create_session'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/remote/bridge.rb:87:in `initialize'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/common/driver.rb:52:in `new'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver/common/driver.rb:52:in `for'
# /Users/nakilon/.gem/ruby/2.0.0/gems/selenium-webdriver-2.47.1/lib/selenium/webdriver.rb:86:in `for'
# /Users/nakilon/.gem/ruby/2.0.0/gems/capybara-2.5.0/lib/capybara/selenium/driver.rb:13:in `browser'
# /Users/nakilon/.gem/ruby/2.0.0/gems/capybara-2.5.0/lib/capybara/selenium/driver.rb:45:in `visit'
# /Users/nakilon/.gem/ruby/2.0.0/gems/capybara-2.5.0/lib/capybara/session.rb:232:in `visit'
# /Users/nakilon/.gem/ruby/2.0.0/gems/capybara-2.5.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
# ./test_min.rb:6:in `block (2 levels) in <top (required)>'
中心日志:
18:20:59.994 INFO - Got a request to create a new session: Capabilities [{rotatable=false, nativeEvents=false, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, version=, platform=ANY, cssSelectorsEnabled=true, firefox_profile=UEsDBBQAAAAIAJ2SOEcGjvwlZwMAA...}]
18:20:59.994 INFO - Available nodes: [http://*****:5555]
18:20:59.995 INFO - Trying to create a new session on node http://*****:5555
18:20:59.995 INFO - Trying to create a new session on test slot {seleniumProtocol=WebDriver, browserName=firefox, maxInstances=5, platform=LINUX}
和节点日志:
18:21:00.008 INFO - Executing: [new session: Capabilities [{rotatable=false, nativeEvents=false, browserName=firefo
x, takesScreenshot=true, javascriptEnabled=true, version=, platform=ANY, cssSelectorsEnabled=true, firefox_profile=
UEsDBBQAAAAIAJ2SOEcGjvwlZwMAA...}]])
18:21:00.018 INFO - Creating a new session for Capabilities [{rotatable=false, nativeEvents=false, browserName=fire
fox, takesScreenshot=true, javascriptEnabled=true, version=, platform=ANY, cssSelectorsEnabled=true, firefox_profil
e=UEsDBBQAAAAIAJ2SOEcGjvwlZwMAA...}]
18:21:02.219 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'vs01.*****.me', ip: '*****', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-042stab108.1', java.version: '1.8.0_51'
Driver info: driver.version: unknown
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119)
at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:125)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:58)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:175)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:202)
at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:164)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
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:358)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'vs01.*****.me', ip: '*****', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-042stab108.1', java.version: '1.8.0_51'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:113)
at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:97)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:103)
... 9 more
Caused by: org.openqa.selenium.UnsupportedCommandException: Bad request
Command duration or timeout: 199 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'vs01.*****.me', ip: '*****', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-042stab108.1', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:223)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:134)
... 14 more
18:21:02.224 WARN - Exception: Bad request
Command duration or timeout: 199 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'vs01.*****.me', ip: '*****', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-042stab108.1', java.version: '1.8.0_51'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
我尝试使用从Mac OS测试运行日志记录中获取的json来模拟功能,但它没有帮助。
UPD:找到http://vs01.*****.me:4444/wd/hub/static/resource/hub.html
处的堆栈跟踪:
{
"status": 13,
"value": {
"message": "Session [(null externalkey)] not available and is not among the last 1000 terminated sessions.\nActive sessions are[]",
"class": "org.openqa.grid.common.exception.GridException",
"stackTrace": [
{
"fileName": "ActiveTestSessions.java",
"className": "org.openqa.grid.internal.ActiveTestSessions",
"methodName": "getExistingSession",
"lineNumber": 110
},
{
"fileName": "Registry.java",
"className": "org.openqa.grid.internal.Registry",
"methodName": "getExistingSession",
"lineNumber": 423
},
{
"fileName": "RequestHandler.java",
"className": "org.openqa.grid.web.servlet.handler.RequestHandler",
"methodName": "getSession",
"lineNumber": 238
},
{
"fileName": "RequestHandler.java",
"className": "org.openqa.grid.web.servlet.handler.RequestHandler",
"methodName": "process",
"lineNumber": 119
},
{
"fileName": "DriverServlet.java",
"className": "org.openqa.grid.web.servlet.DriverServlet",
"methodName": "process",
"lineNumber": 83
},
{
"fileName": "DriverServlet.java",
"className": "org.openqa.grid.web.servlet.DriverServlet",
"methodName": "doGet",
"lineNumber": 61
},
{
"fileName": "HttpServlet.java",
"className": "javax.servlet.http.HttpServlet",
"methodName": "service",
"lineNumber": 707
},
{
"fileName": "HttpServlet.java",
"className": "javax.servlet.http.HttpServlet",
"methodName": "service",
"lineNumber": 820
},
{
"fileName": "ServletHolder.java",
"className": "org.seleniumhq.jetty7.servlet.ServletHolder",
"methodName": "handle",
"lineNumber": 565
},
{
"fileName": "ServletHandler.java",
"className": "org.seleniumhq.jetty7.servlet.ServletHandler",
"methodName": "doHandle",
"lineNumber": 479
},
{
"fileName": "SessionHandler.java",
"className": "org.seleniumhq.jetty7.server.session.SessionHandler",
"methodName": "doHandle",
"lineNumber": 225
},
{
"fileName": "ContextHandler.java",
"className": "org.seleniumhq.jetty7.server.handler.ContextHandler",
"methodName": "doHandle",
"lineNumber": 1031
},
{
"fileName": "ServletHandler.java",
"className": "org.seleniumhq.jetty7.servlet.ServletHandler",
"methodName": "doScope",
"lineNumber": 406
},
{
"fileName": "SessionHandler.java",
"className": "org.seleniumhq.jetty7.server.session.SessionHandler",
"methodName": "doScope",
"lineNumber": 186
},
{
"fileName": "ContextHandler.java",
"className": "org.seleniumhq.jetty7.server.handler.ContextHandler",
"methodName": "doScope",
"lineNumber": 965
},
{
"fileName": "ScopedHandler.java",
"className": "org.seleniumhq.jetty7.server.handler.ScopedHandler",
"methodName": "handle",
"lineNumber": 117
},
{
"fileName": "HandlerWrapper.java",
"className": "org.seleniumhq.jetty7.server.handler.HandlerWrapper",
"methodName": "handle",
"lineNumber": 111
},
{
"fileName": "Server.java",
"className": "org.seleniumhq.jetty7.server.Server",
"methodName": "handle",
"lineNumber": 349
},
{
"fileName": "AbstractHttpConnection.java",
"className": "org.seleniumhq.jetty7.server.AbstractHttpConnection",
"methodName": "handleRequest",
"lineNumber": 452
},
{
"fileName": "BlockingHttpConnection.java",
"className": "org.seleniumhq.jetty7.server.BlockingHttpConnection",
"methodName": "handleRequest",
"lineNumber": 47
},
{
"fileName": "AbstractHttpConnection.java",
"className": "org.seleniumhq.jetty7.server.AbstractHttpConnection",
"methodName": "headerComplete",
"lineNumber": 884
},
{
"fileName": "AbstractHttpConnection.java",
"className": "org.seleniumhq.jetty7.server.AbstractHttpConnection$RequestHandler",
"methodName": "headerComplete",
"lineNumber": 938
},
{
"fileName": "HttpParser.java",
"className": "org.seleniumhq.jetty7.http.HttpParser",
"methodName": "parseNext",
"lineNumber": 634
},
{
"fileName": "HttpParser.java",
"className": "org.seleniumhq.jetty7.http.HttpParser",
"methodName": "parseAvailable",
"lineNumber": 230
},
{
"fileName": "BlockingHttpConnection.java",
"className": "org.seleniumhq.jetty7.server.BlockingHttpConnection",
"methodName": "handle",
"lineNumber": 66
},
{
"fileName": "SocketConnector.java",
"className": "org.seleniumhq.jetty7.server.bio.SocketConnector$ConnectorEndPoint",
"methodName": "run",
"lineNumber": 254
},
{
"fileName": "QueuedThreadPool.java",
"className": "org.seleniumhq.jetty7.util.thread.QueuedThreadPool",
"methodName": "runJob",
"lineNumber": 599
},
{
"fileName": "QueuedThreadPool.java",
"className": "org.seleniumhq.jetty7.util.thread.QueuedThreadPool$3",
"methodName": "run",
"lineNumber": 534
},
{
"fileName": "Thread.java",
"className": "java.lang.Thread",
"methodName": "run",
"lineNumber": 745
}
]
}
}
UPD:尝试过selenium 2.47.0和2.46.0(使用gem 2.46.1) - 不能进一步降级,因为不知道如何在CentOS上降级Firefox。
UPD:添加了记录远程http请求并省略了自定义配置文件创建 - 在此之后仍然失败:
12:37:25.906 post {"desiredCapabilities":{"browserName":"firefox","version":"","platform":"ANY","javascriptEnabled":true,"cssSelectorsEnabled":true,"takesScreenshot":true,"nativeEvents":false,"rotatable":false}}
答案 0 :(得分:2)
我的问题在于/etc/hosts
中有:
127.0.0.1 localhost.localdomain localhost
而不是:
127.0.0.1 localhost localhost.localdomain
https://github.com/SeleniumHQ/selenium/issues/431#issuecomment-133793667
编辑后,您应重新启动集线器/节点。