Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_ok always fails against 2.42 #135

Closed
jamadam opened this issue Jun 12, 2014 · 12 comments
Closed

get_ok always fails against 2.42 #135

jamadam opened this issue Jun 12, 2014 · 12 comments
Assignees
Labels
Milestone

Comments

@jamadam
Copy link
Contributor

jamadam commented Jun 12, 2014

get_ok always fails in real world test case and the use case in t directory also fails.

$ perl -Ilib t/Test-Selenium-Remote-Driver-google.t
not ok 1 - get'http://www.google.com'
#   Failed test 'get'http://www.google.com''
#   at t/Test-Selenium-Remote-Driver-google.t line 15.
ok 2
ok 3
1..3
# Looks like you failed 1 test of 3.

The browser successfully shows the site and no error found in selenium server log.

Is this my environmental problem?

@jamadam
Copy link
Contributor Author

jamadam commented Jun 12, 2014

This is because the server returns content for get command with null value since selenium server version 2.42.
The server use to returns no content for get command so the final result of get method returns error message which happen to evaluated as true and get_ok passed.

I'm trying to fix some how but no idea for now :)

@gempesaw
Copy link
Collaborator

Yeah, looks like they changed the API return value for GETing /session/:sessionId/url in 2.42. Hm.

@gempesaw gempesaw self-assigned this Jun 12, 2014
@gempesaw gempesaw added this to the 0.2002 milestone Jun 12, 2014
@jamadam
Copy link
Contributor Author

jamadam commented Jun 12, 2014

Yes that's what I wanted to say :)
Here is a workaround for it but it's too evil to PR.

jamadam@8c48a8e

Wonder if *_ok methods can check $resp->{cmd_status} eq 'OK' some how.

@gempesaw gempesaw changed the title get_ok always fails get_ok always fails against 2.42 Jun 12, 2014
@gempesaw gempesaw added the 2.42 label Jun 12, 2014
@jamadam
Copy link
Contributor Author

jamadam commented Jun 12, 2014

hmm. It doesn't work. cmd_status always set to OK.

@ghost
Copy link

ghost commented Jun 25, 2014

Could we combine this with my proposal in issue #130 ?

@jamadam
Copy link
Contributor Author

jamadam commented Jun 25, 2014

Hi. olivierBlanc.

I'm not pretty sure for now your proposal has to do something with this but please take over it :)

By the way I've got another workaround for getting success out of _execute_command just in case wantarray solution is not acceptable.

jamadam@05dc1da

@gempesaw
Copy link
Collaborator

@peroumal1 Hey, do you have any input here? The ::DoesTesting role, now that the return values have changed for some methods as of 2.42.x, is apparently giving different behavior from before. I was hoping we could contain the changes to DoesTesting.pm, since the testing methods like get_ok probably shouldn't have any overlap to the underlying Driver.pm...

@peroumal1
Copy link
Collaborator

I will try to have a look as soon as I have some time ;)

On Wed, Jun 25, 2014 at 5:08 PM, Daniel Gempesaw notifications@github.com
wrote:

@peroumal Hey, do you have any input here? The ::DoesTesting role, now
that the return values have changed for some methods as of 2.42.x, is
apparently giving different behavior from before. I was hoping we could
contain the changes to DoesTesting.pm, since the testing methods like
get_ok probably shouldn't have any overlap to the underlying Driver.pm...


Reply to this email directly or view it on GitHub
#135 (comment)
.

Peroumalnaik Emmanuel

@peroumal1
Copy link
Collaborator

So...
2.42.2 response :

 0  HTTP::Response=HASH(0x4189670)
   '_content' => '{"status":0,"sessionId":"66884be3-8aae-4a1d-a8db-96e6e9daace1","value":null,"state":"success","class":"org.openqa.selenium.re
mote.Response","hCode":813457600}'
   '_headers' => HTTP::Headers=HASH(0x4189658)
      'cache-control' => ARRAY(0x41897d8)
         0  'no-cache'
         1  'no-cache'
      'client-date' => 'Wed, 25 Jun 2014 15:31:59 GMT'
      'client-peer' => '127.0.0.1:4444'
      'client-response-num' => 1
      'connection' => 'close'
      'content-length' => 158
      'content-type' => 'application/json; charset=utf-8'
      'date' => 'Wed, 25 Jun 2014 15:31:58 GMT'
      'expires' => ARRAY(0x4189778)
         0  'Thu, 01 Jan 1970 00:00:00 GMT'
         1  'Thu, 01 Jan 1970 00:00:00 GMT'
      'server' => 'Jetty/5.1.x (Linux/3.8.0-42-generic amd64 java/1.6.0_31'
   '_msg' => 'OK'
   '_protocol' => 'HTTP/1.1'
   '_rc' => 200
   '_request' => HTTP::Request=HASH(0x4184fc8)
      '_content' => '{"url":"http://.a.b"}'
      '_headers' => HTTP::Headers=HASH(0x4184ce0)
         'accept' => 'application/json'
         'content-type' => 'application/json; charset=utf-8'
         'user-agent' => 'libwww-perl/6.04'
      '_method' => 'POST'
      '_uri' => URI::http=SCALAR(0x413e908)
         -> 'http://localhost:4444/wd/hub/session/66884be3-8aae-4a1d-a8db-96e6e9daace1/url'
      '_uri_canonical' => URI::http=SCALAR(0x413e908)
         -> REUSED_ADDRESS

2.41 response :

0  HTTP::Response=HASH(0x29b8e80)
   '_content' => ''
   '_headers' => HTTP::Headers=HASH(0x29b8da8)
      'cache-control' => 'no-cache'
      'client-date' => 'Wed, 25 Jun 2014 15:39:47 GMT'
      'client-peer' => '127.0.0.1:4444'
      'client-response-num' => 1
      'connection' => 'close'
      'date' => 'Wed, 25 Jun 2014 15:39:47 GMT'
      'expires' => 'Thu, 01 Jan 1970 00:00:00 GMT'
      'server' => 'Jetty/5.1.x (Linux/3.8.0-42-generic amd64 java/1.6.0_31'
   '_msg' => 'No Content'
   '_protocol' => 'HTTP/1.1'
   '_rc' => 204
   '_request' => HTTP::Request=HASH(0x29b4848)
      '_content' => '{"url":"http://.a.b"}'
      '_headers' => HTTP::Headers=HASH(0x29b43b0)
         'accept' => 'application/json'
         'content-type' => 'application/json; charset=utf-8'
         'user-agent' => 'libwww-perl/6.04'
      '_method' => 'POST'
      '_uri' => URI::http=SCALAR(0x296ded8)
         -> 'http://localhost:4444/wd/hub/session/2ac50f3d-125e-40de-b450-405e61474096/url'
      '_uri_canonical' => URI::http=SCALAR(0x296ded8)
         -> REUSED_ADDRESS

So the main change is that they used to return '204 No Content' on older versions, which was caught correctly by our code (_process_response in Selenium::Remote::Connection).
Now they are returning '200' with a json encoded hash on 2.42.X. We try to make sense of that hash by getting 'value' from that hash, which is null. Then stuff happens.
One possible fix would be that, on line 135 of Selenium::Remote::RemoteConnection, we could replace the line with :

  $data->{'cmd_return'} = $decoded_json->{'value'} // 'No Content';

That's for the quick and dirty solution, but it should work.
We should be careful though if there are people relying on cmd_return for anything, it could break their stuff, hence generating other bugs.

@peroumal1
Copy link
Collaborator

@gempesaw I just noticed that I actually did not answer precisely enough.
In our case here, there is no workaround possible in DoesTesting, since the problem is more on how we process the responses from Selenium Server : from 2.41 to 2.42, on the same request, we use two different paths in _process_response sub, so my correction to patch the new path to make it behave as before seems wiser. What do you think ?

@gempesaw
Copy link
Collaborator

This seems plenty reasonable, and it should keep the behavior consistent for <2.42 versions with that //, I believe. Thanks a bunch.

gempesaw added a commit that referenced this issue Jun 27, 2014
Fix #135 : catch the new responses from Selenium 2.42
@gempesaw
Copy link
Collaborator

@peroumal1 Thanks so much for the investigation and the insightful PR, _process_response does seem to be exactly the place we want to be handling this issue. But, I was thinking that we could stick to the current method of handling successful 'no content' responses with that string and the response code as the return value:

53c971f

            if (defined $decoded_json && $decoded_json->{'value'}) {
                $data->{'cmd_return'} = $decoded_json->{'value'};
            }

This also would fit nicely #136 since the return value for those subs is set based off of that response code string.

gempesaw added a commit that referenced this issue Jul 3, 2014
        [BUG FIXES]
        - #135, #136, #142: Fix compatability issues with JSONWireProtocol changes in 2.42.2

        [NEW FEATURES]
        - Add an optional base_url parameter for automatic concatenation in get/get_ok
gempesaw added a commit that referenced this issue Jul 14, 2014
This reverts f22f548 and 5d11c36. As discussed in #145, this solution
does not work as it interferes with some endpoints that expect to be
able to return false by indicating "" as their return value.

These fixes would catch that "" and return a non-empty string, which
would in turn evaluate to true.

Conflicts:
        lib/Selenium/Remote/RemoteConnection.pm
gempesaw added a commit that referenced this issue Jul 15, 2014
This reverts f22f548 and 5d11c36. As discussed in #145, this solution
does not work as it interferes with some endpoints that expect to be
able to return false by indicating "" as their return value.

These fixes would catch that "" and return a non-empty string, which
would in turn evaluate to true.

Conflicts:
        lib/Selenium/Remote/RemoteConnection.pm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants