appium/ruby_lib

Ruby client is eating query params and breaking Appium session creation

abdullahawara opened this issue · 5 comments

This is a

  • Bug report

Summary

Creating an Appium session and allocating a (real) device for the session might take a long time. To avoid having a long running HTTP requests that could last for 15 minutes or more for example, a redirect response (HTTP code 3xx) is returned to the client after some time (e.g. 60 seconds).

This Ruby Appium client library doesn't respects 3xx codes and considers the session as failed if a non 2xx response is received.

Other Appium client libraries like Java and Python already support HTTP redirects during session creation .. and the Appium session creation succeeds even if there was redirects.

Environment

  • Appium version (or git revision): 1.17.1 (it doesn't matter)
  • ruby_lib version: 10.6.0
  • Mobile platform/version/device under test: All

Actual behaviour and steps to reproduce

The following steps are Sauce Labs specific, but you can probably reproduce the same issue in other ways like a unit test or something else as long as you're getting a 3xx response from
POST /wd/hub/session/:id?ref=:another-temp-id.

  • Run a test against Sauce Labs RDC on a device that is in use so the session needs to wait for the device.
  • See the session creation failure after ~45 seconds when a 3xx HTTP response is returned from Sauce Labs RDC.

Expected behaviour

Redirects from Appium proxy are respected and not causing the session creation to fail.
It is ok to have a limit for redirects .. e.g. the java client has a limit of 20 redirects.

Link to Appium/Ruby logs

https://gist.github.com/abdullahawara/b92bedb8b1d53bf27659618947027a34

It looks the error was raised by
https://github.com/SeleniumHQ/selenium/blob/selenium-3.141.59/rb/lib/selenium/webdriver/remote/response.rb#L68-L73

Could you get the debug log?
(e.g. Appium::Logger.level = ::Logger::DEBUG)


About redirect.
https://github.com/SeleniumHQ/selenium/blob/selenium-3.141.59/rb/lib/selenium/webdriver/remote/http/default.rb#L100-L105 handles redirect if the response was Net::HTTPRedirection (3xx response as net/https).
So, I wondered if the logic worked.

btw, you called Selenium::WebDriver.for in the log.
It seems completely selenium client. Asking it in selenium repository may be a proper place.

       driver = Selenium::WebDriver.for :remote,
                                         url: "https://" + "username" + ":" + "accessKey" + "@ondemand.us-west-1.saucelabs.com/wd/hub",
                                         desired_capabilities: caps

@abdullahawara can you set this, rerun it and send me (privately since there can be sensitive info: titus@saucelabs.com) the entire output?
Selenium::WebDriver.logger.level = :info

It does look like it might be a Sauce+Selenium issue and not an Appium issue.

Thanks, @titusfortner !
@abdullahawara Please contact him :)

Thanks @KazuCocoa and @titusfortner . I contacted Titus and sent him the logs, but just wanted to mention here that I think the issue is that we don't get our query param back in the ruby bindings.

Example logs - java client (test is passing):

Sending redirect /wd/hub/session/1ae04a13-10c9-487a-8a80-0c01d4ed76df?ref=20589160-b354-463b-b07a-08e358b1e824 because the session is still pending.
Received request GET /wd/hub/session/1ae04a13-10c9-487a-8a80-0c01d4ed76df?ref=20589160-b354-463b-b07a-08e358b1e824 from Appium client

you can see that the ref query param is sent and received.

But Ruby is eating the query param (test is failing):

Sending redirect /wd/hub/session/07a36be0-cad5-47d7-9ec1-1d15aaa6fac4?ref=6fe5f2d6-0c39-4aca-82d5-a8b6d29607bf because the session is still pending.
Received request GET /wd/hub/session/07a36be0-cad5-47d7-9ec1-1d15aaa6fac4 from Appium client