Grid does not handle w3c capabilities correctly
Meta -
OS: Mac OS El Capitan 10.11.6
Selenium Version: 3.3.3
Browser: Firefox
Browser Version: 52.0.2 (64-bit)
Expected Behavior -
In python, the following should create a Remote driver:
from selenium import webdriver
cap = {'platform': 'ANY', 'browserName': 'firefox', 'version': '', 'marionette': True, 'javascriptEnabled': True} driver = webdriver.Remote(command_executor='http://<my_server_ip>:4444/wd/hub', desired_capabilities=cap)
(note: this works with selenium 2.53.6 with python2.7 when executed against the same server)
Actual Behavior -
Thows exception: KeyError: 'message'
When I pdb into this I see the following response from the server:
{'value': '{"status":13,"value":{"class":"java.lang.NullPointerException","stackTrace":[{"fileName":"HashMap.java","className":"java.util.HashMap","methodName":"putMapEntries","lineNumber":500},{"fileName":"HashMap.java","className":"java.util.HashMap","methodName":"putAll","lineNumber":784},{"fileName":"DesiredCapabilities.java","className":"org.openqa.selenium.remote.DesiredCapabilities","methodName":"\u003cinit\u003e","lineNumber":54},{"fileName":"RequestHandler.java","className":"org.openqa.grid.web.servlet.handler.RequestHandler","methodName":"process","lineNumber":104},{"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":"doPost","lineNumber":67},{"fileName":"HttpServlet.java","className":"javax.servlet.http.HttpServlet","methodName":"service","lineNumber":707},{"fileName":"HttpServlet.java","className":"javax.servlet.http.HttpServlet","methodName":"service","lineNumber":790},{"fileName":"ServletHolder.java","className":"org.seleniumhq.jetty9.servlet.ServletHolder","methodName":"handle","lineNumber":841},{"fileName":"ServletHandler.java","className":"org.seleniumhq.jetty9.servlet.ServletHandler","methodName":"doHandle","lineNumber":543},{"fileName":"ScopedHandler.java","className":"org.seleniumhq.jetty9.server.handler.ScopedHandler","methodName":"nextHandle","lineNumber":188},{"fileName":"SessionHandler.java","className":"org.seleniumhq.jetty9.server.session.SessionHandler","methodName":"doHandle","lineNumber":1584},{"fileName":"ScopedHandler.java","className":"org.seleniumhq.jetty9.server.handler.ScopedHandler","methodName":"nextHandle","lineNumber":188},{"fileName":"ContextHandler.java","className":"org.seleniumhq.jetty9.server.handler.ContextHandler","methodName":"doHandle","lineNumber":1228},{"fileName":"ScopedHandler.java","className":"org.seleniumhq.jetty9.server.handler.ScopedHandler","methodName":"nextScope","lineNumber":168},{"fileName":"ServletHandler.java","className":"org.seleniumhq.jetty9.servlet.ServletHandler","methodName":"doScope","lineNumber":481},{"fileName":"SessionHandler.java","className":"org.seleniumhq.jetty9.server.session.SessionHandler","methodName":"doScope","lineNumber":1553},{"fileName":"ScopedHandler.java","className":"org.seleniumhq.jetty9.server.handler.ScopedHandler","methodName":"nextScope","lineNumber":166},{"fileName":"ContextHandler.java","className":"org.seleniumhq.jetty9.server.handler.ContextHandler","methodName":"doScope","lineNumber":1130},{"fileName":"ScopedHandler.java","className":"org.seleniumhq.jetty9.server.handler.ScopedHandler","methodName":"handle","lineNumber":141},{"fileName":"HandlerWrapper.java","className":"org.seleniumhq.jetty9.server.handler.HandlerWrapper","methodName":"handle","lineNumber":132},{"fileName":"Server.java","className":"org.seleniumhq.jetty9.server.Server","methodName":"handle","lineNumber":564},{"fileName":"HttpChannel.java","className":"org.seleniumhq.jetty9.server.HttpChannel","methodName":"handle","lineNumber":320},{"fileName":"HttpConnection.java","className":"org.seleniumhq.jetty9.server.HttpConnection","methodName":"onFillable","lineNumber":251},{"fileName":"AbstractConnection.java","className":"org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback","methodName":"succeeded","lineNumber":279},{"fileName":"FillInterest.java","className":"org.seleniumhq.jetty9.io.FillInterest","methodName":"fillable","lineNumber":112},{"fileName":"ChannelEndPoint.java","className":"org.seleniumhq.jetty9.io.ChannelEndPoint$2","methodName":"run","lineNumber":124},{"fileName":"QueuedThreadPool.java","className":"org.seleniumhq.jetty9.util.thread.QueuedThreadPool","methodName":"runJob","lineNumber":672},{"fileName":"QueuedThreadPool.java","className":"org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2","methodName":"run","lineNumber":590},{"fileName":"Thread.java","className":"java.lang.Thread","methodName":"run","lineNumber":745}]}}', 'status': 500}
Steps to reproduce -
Execute the above steps in python using selenium 3.3.3, firefox 52.0.2, geckodriver 0.15.0. The server is using selenium-server-standalone-3.3.1.jar on ubuntu 16.10. I'm happy to provide the ip of the server privately if it'll help.
Also, testing with curl seems to work fine:
curl -v -X POST http://<my_server_ip>:4444/wd/hub/session -d '{"desiredCapabilities":{"browserName":"firefox", "marionette": "true", "javascriptEnabled": "true"}}'
curl -v 'http://<my_server_ip>:4444/wd/hub/session/SESSION_ID'
Ok, looks it actually works if I change the port to 5555.
I'm guessing that's connecting directly to a node rather than the hub? Why would port 4444 work with selenium 2.5 but not 3.3.3?
I met the same issue. and Using the same command on selenium 3.3.0 working fine. Now I'm downgrade to 3.3.0.
In [1]: from selenium.webdriver import *
In [2]: dri = Remote('http://my_sever_ip:4444/wd/hub', DesiredCapabilities.HTMLUNIT)
KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py in init(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector) 96 warnings.warn("Please use FirefoxOptions to set browser profile", 97 DeprecationWarning) ---> 98 self.start_session(desired_capabilities, browser_profile) 99 self._switch_to = SwitchTo(self) 100 self._mobile = Mobile(self)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py in start_session(self, capabilities, browser_profile) 183 parameters = {"capabilities": w3c_caps, 184 "desiredCapabilities": capabilities} --> 185 response = self.execute(Command.NEW_SESSION, parameters) 186 if 'sessionId' not in response: 187 response = response['value']
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params) 247 response = self.command_executor.execute(driver_command, params) 248 if response: --> 249 self.error_handler.check_response(response) 250 response['value'] = self._unwrap_value( 251 response.get('value', None))
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response) 108 value = message 109 try: --> 110 message = message['message'] 111 except TypeError: 112 message = None
KeyError: 'message'
In [3]: exit
I have the same issue with Selenium python client 3.3.2 or 3.3.3 against a Selenium server 3.3.1. It works with Selenium python client 3.3.1.
The problem has been introduced with commit https://github.com/SeleniumHQ/selenium/commit/abe1f45be59d1064d4ca353cb7278d455990c398. It uses the new W3C start session (send "capabilities" instead of "requiredCapabilities"), but it seems that Selenium 3.3.1 server still needs "requiredCapabilities".
I have downgraded selenium, selenium standalone server and it works fine.
I can create Remote driver if run server locally as
java -jar selenium-server-standalone-3.3.1.jar
But it fails for a local grid started as:
java -jar selenium-server-standalone-3.3.1.jar -role hub
java -jar selenium-server-standalone-3.3.1.jar -role node
I found that this grid works only with "selenium-server-standalone-2.53.1.jar", but do not even with the first 3.x one "selenium-server-standalone-3.0.0.jar"
I use python 3.6, selenium 3.3.3, and command
wd = webdriver.Remote("http://192.168.50.30:4444/wd/hub",desired_capabilities=DesiredCapabilities.CHROME)
Here is a full stacktrace using the python bindings 3.4.0 with selenium server (in grid hub/node mode) : https://gist.github.com/smccarthy/6778f2af97b99e301767438de01c62fb
I tried with chromedriver 2.28 and 2.29 , but I seem to get the same issue with DesiredCapabilities.FIREFOX
This appears to be a grid issue, it does not like 'capabilities' being in the parameters for new session
Or rather that it expects desiredCapabilities to be inside capabilities
https://github.com/SeleniumHQ/selenium/blob/02a0df9d72273415c02bc8da6f517585e7fb8123/java/server/src/org/openqa/grid/web/servlet/handler/WebDriverRequest.java#L69
@shs96c you'd probably be best at handling the fix for this
Is there any update on this? I am still stuck on 3.0.1 because of this bug.
I'm having the same issue using the .Net bindings on the client side.
OS: Windows 10 Selenium Version: 3.4 Browser: Chrome Browser Version: 57 Grid Version (Hub & Node): 3.4
I was testing this setup with a locally running hub and node on my dev laptop before upgrading our actual grid. Anytime I request a browser directly from the hub, I get an error. This is not a problem using 3.3 nor is it a problem using 3.4 when I bypass the grid and use a local browser.
@bjharo see @jimevans's explanation here https://github.com/SeleniumHQ/selenium/issues/3929#issuecomment-298186607
And the reason it's showing up now is that 3.4 is the first release to consistently attempt to send the W3C spec-compliant payload for a new session command (containing a capabilities property) across the wire. This is where the bug is in the hub code.
Do we have any work around of it?
I also am seeing this problem. My workaround in Python has been to force an earlier version of selenium when installing. I.e., pip3 uninstall selenium && pip3 install selenium==3.3.1
As a workaround this is what worked for me....go into the selenium webdriver client
I am using python client
go into the remote/webdriver.py
you will see this within the start_session(some args) method
parameters = {"capabilities": w3c_caps,
"desiredCapabilities": capabilities}
remove the "capabilities": w3c_caps
so you end up with:
parameters = { "desiredCapabilities": capabilities}
I am sure that this is very similar to the other client bindings. Just a temporary workaround until this can be fixed.
I just tried to compile the webdriver (.NET for me) according to the remark of @Grimlek and it works but the capabilities used doesn't respect the json mentioned in that page https://github.com/w3c/webdriver/pull/327 I tried to compile the selenium-server-standalone and remove the desiredCapabilities according to the remark of @lmtierney . That works too with the .NET webdriver. I saw the code behind the .NET webdriver and python webdriver and it seems that the object capabilities is not filled the same way just for this 2 drivers.
For .NET
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("desiredCapabilities", this.GetLegacyCapabilitiesDictionary(desiredCapabilities));
Dictionary<string, object> firstMatchCapabilities = this.GetCapabilitiesDictionary(desiredCapabilities);
List<object> firstMatchCapabilitiesList = new List<object>();
firstMatchCapabilitiesList.Add(firstMatchCapabilities);
Dictionary<string, object> specCompliantCapabilities = new Dictionary<string, object>();
specCompliantCapabilities["firstMatch"] = firstMatchCapabilitiesList;
parameters.Add("capabilities", specCompliantCapabilities);
Response response = this.Execute(DriverCommand.NewSession, parameters);
desiredCapabilities and capabilities are filled but desiredCapabilities is no more used if capabilities is set in the function extractDesiredCapability. Maybe some code must be removed over here.
But when you look at the python version, the content is not the same
w3c_caps = {"firstMatch": [], "alwaysMatch": {}}
...
w3c_caps["alwaysMatch"].update(capabilities)
parameters = {"capabilities": w3c_caps,
"desiredCapabilities": capabilities}
For the python version, firstMatch is never set but alwaysMatch is set.
For the moment i'm glad that the selenium-server-standalone is working again on my server but the code i saw is really odd and i don't know what must be done
I'm getting the following Exception when I try to do what @Grimlek suggested. Note: I have already downgraded to Selenium Standalone Server version 3.3.0. What am I doing wrong?
selenium.common.exceptions.WebDriverException: Message: Error forwarding the new session cannot find : Capabilities [{marionette=true, acceptInsecureCerts=true, browserName=firefox, version=8.1, platform=WINDOWS}]
Stacktrace:
at org.openqa.grid.web.servlet.handler.RequestHandler.process (RequestHandler.java:112)
at org.openqa.grid.web.servlet.DriverServlet.process (DriverServlet.java:83)
at org.openqa.grid.web.servlet.DriverServlet.doPost (DriverServlet.java:67)
at javax.servlet.http.HttpServlet.service (HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service (HttpServlet.java:790)
at org.seleniumhq.jetty9.servlet.ServletHolder.handle (ServletHolder.java:841)
at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle (ServletHandler.java:543)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:188)
at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle (SessionHandler.java:1584)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle (ScopedHandler.java:188)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle (ContextHandler.java:1228)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope (ScopedHandler.java:168)
at org.seleniumhq.jetty9.servlet.ServletHandler.doScope (ServletHandler.java:481)
at org.seleniumhq.jetty9.server.session.SessionHandler.doScope (SessionHandler.java:1553)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope (ScopedHandler.java:166)
at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope (ContextHandler.java:1130)
at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle (ScopedHandler.java:141)
at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle (HandlerWrapper.java:132)
at org.seleniumhq.jetty9.server.Server.handle (Server.java:564)
at org.seleniumhq.jetty9.server.HttpChannel.handle (HttpChannel.java:320)
at org.seleniumhq.jetty9.server.HttpConnection.onFillable (HttpConnection.java:251)
at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded (AbstractConnection.java:279)
at org.seleniumhq.jetty9.io.FillInterest.fillable (FillInterest.java:112)
at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run (ChannelEndPoint.java:124)
at org.seleniumhq.jetty9.util.thread.Invocable.invokePreferred (Invocable.java:122)
at org.seleniumhq.jetty9.util.thread.strategy.ExecutingExecutionStrategy.invoke (ExecutingExecutionStrategy.java:58)
at org.seleniumhq.jetty9.util.thread.strategy.ExecuteProduceConsume.produceConsume (ExecuteProduceConsume.java:201)
at org.seleniumhq.jetty9.util.thread.strategy.ExecuteProduceConsume.run (ExecuteProduceConsume.java:133)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:672)
at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run (QueuedThreadPool.java:590)
at java.lang.Thread.run (
Process finished with exit code 1
@shs96c Apologize for asking, but is there a timeline for this to be resolved? We are trying to embrace the latest selenium-java releases, but this issue (plus inability to set proxy) prevents use from using Selenium v3.4, GeckoDriver v0.16.1 or even using legacy (via FirefoxOptions.setLegacy(true)) as a workaround, since we cannot match on browserVersion=47.0.1