ysbaddaden / selenium-webdriver-crystal

Selenium Webdriver client for the Crystal programming language
Other
57 stars 16 forks source link

Missing key "status" on a json failure #40

Open jwoertink opened 4 years ago

jwoertink commented 4 years ago

I have this failure, but not sure where it's coming from exactly...

Missing hash key: "status" (KeyError)
         from /Users/jeremywoertink/.asdf/installs/crystal/0.31.1/src/hash.cr:0:9 in '[]'
         from /Users/jeremywoertink/.asdf/installs/crystal/0.31.1/src/json/any.cr:102:7 in '[]'
         from lib/selenium/src/webdriver.cr:88:18 in 'failure'
         from lib/selenium/src/webdriver.cr:65:9 in 'post'
         from lib/selenium/src/webdriver/session.cr:181:18 in 'post'
         from lib/selenium/src/webdriver/session.cr:66:7 in 'url='
         from lib/selenium/src/webdriver/session.cr:37:9 in 'initialize'
         from lib/selenium/src/webdriver/session.cr:26:5 in 'initialize'

On this line I inspected my body, and this it was it returned which doesn't contain a "status" key.

{"value" => {"error" => "invalid session id", "message" => "invalid session id", "stacktrace" => "0   chromedriver                        0x0000000107b19e99 chromedriver + 3747481\n1   chromedriver                        0x0000000107aae4d3 chromedriver + 3306707\n2   chromedriver                        0x000000010783de42 chromedriver + 749122\n3   chromedriver                        0x00000001077a139c chromedriver + 107420\n4   chromedriver                        0x00000001077c725c chromedriver + 262748\n5   chromedriver                        0x00000001077c55db chromedriver + 255451\n6   chromedriver                        0x00000001077c4e17 chromedriver + 253463\n7   chromedriver                        0x000000010778caf9 chromedriver + 23289\n8   chromedriver                        0x0000000107adcf7f chromedriver + 3497855\n9   chromedriver                        0x0000000107ae9b7d chromedriver + 3550077\n10  chromedriver                        0x0000000107ae9908 chromedriver + 3549448\n11  chromedriver                        0x0000000107abc029 chromedriver + 3362857\n12  chromedriver                        0x0000000107aea3d8 chromedriver + 3552216\n13  chromedriver                        0x0000000107ad0a37 chromedriver + 3447351\n14  chromedriver                        0x000000010778a360 chromedriver + 13152\n15  libdyld.dylib                       0x00007fff694752e5 start + 1\n16  ???                                 0x0000000000000003 0x0 + 3\n"}} (Exception)

Found some docs on that errors object:

https://w3c.github.io/webdriver/#errors

ysbaddaden commented 4 years ago

The original JSON protocol reported a status code. They probably broke that in the WebDriver protocol.

ysbaddaden commented 4 years ago

C.f. https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#responses

jwoertink commented 4 years ago

Ah. ok. I'll have to see if there's a way to tell it to use the JsonWire

ysbaddaden commented 4 years ago

Probably not. TBH the JSON protocol was small and good. The WebDriver spec seems overly complex, with no benefit, but all direct implementations now use it :-(

jwoertink commented 4 years ago

Yeah, I looked in to it a little and it's seems way more complicated than it needs to be.

matthewmcgarvey commented 4 years ago

Just ran into this issue as well. Enabling debug logs helped me find the issue and it might help in fixing it here:

REQUEST: POST /session
{"desiredCapabilities" => {browserName: "chrome", platform: "ANY", javascriptEnabled: true, takesScreenshot: true, handlesAlerts: true, databaseEnabled: true, locationContextEnabled: true, applicationCacheEnabled: true, browserConnectionEnabled: true, cssSelectorsEnabled: true, webStorageEnabled: true, rotatable: true, acceptSslCerts: true, nativeEvents: true, chromeOptions: {args: ["no-sandbox", "headless", "disable-gpu"]}}, "requiredCapabilities" => {}}
REQUEST: POST /session
{"desiredCapabilities" => {browserName: "chrome", platform: "ANY", javascriptEnabled: true, takesScreenshot: true, handlesAlerts: true, databaseEnabled: true, locationContextEnabled: true, applicationCacheEnabled: true, browserConnectionEnabled: true, cssSelectorsEnabled: true, webStorageEnabled: true, rotatable: true, acceptSslCerts: true, nativeEvents: true, chromeOptions: {args: ["no-sandbox", "headless", "disable-gpu"]}}, "requiredCapabilities" => {}}
RESPONSE: 200
{"sessionId" => "65044075b66b567f5975a5dcbc3bd362", "status" => 33, "value" => {"message" => "session not created: This version of ChromeDriver only supports Chrome version 77\n  (Driver info: chromedriver=77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}),platform=Mac OS X 10.14.6 x86_64)"}}

REQUEST: POST /session/65044075b66b567f5975a5dcbc3bd362/url
{url: "about:blank"}
RESPONSE: 404
{"value" => {"error" => "invalid session id", "message" => "invalid session id", "stacktrace" => "0   chromedriver                        0x000000010bbe7f09 chromedriver + 3694345\n1   chromedriver                        0x000000010bb74fd3 chromedriver + 3223507\n2   chromedriver                        0x000000010b9143e2 chromedriver + 730082\n3   chromedriver                        0x000000010b87bacc chromedriver + 105164\n4   chromedriver                        0x000000010b8a0f7c chromedriver + 257916\n5   chromedriver                        0x000000010b89f30a chromedriver + 250634\n6   chromedriver                        0x000000010b89eb47 chromedriver + 248647\n7   chromedriver                        0x000000010b867099 chromedriver + 20633\n8   chromedriver                        0x000000010bba307f chromedriver + 3412095\n9   chromedriver                        0x000000010bbafced chromedriver + 3464429\n10  chromedriver                        0x000000010bbafa78 chromedriver + 3463800\n11  chromedriver                        0x000000010bb82959 chromedriver + 3279193\n12  chromedriver                        0x000000010bbb0548 chromedriver + 3466568\n13  chromedriver                        0x000000010bb971b7 chromedriver + 3363255\n14  chromedriver                        0x000000010b865390 chromedriver + 13200\n15  libdyld.dylib                       0x00007fff7045c3d5 start + 1\n"}}
ysbaddaden commented 4 years ago

A solution is to check whether status is defined to keep the existing, then implement the new error hash, and possibly merge the exceptions, to hide the protocol difference to users.