Skip to content

Ruby - Unable to upload file when w3c browser capability is set to true #7666

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

Closed
sriup opened this issue Oct 9, 2019 · 13 comments
Closed

Ruby - Unable to upload file when w3c browser capability is set to true #7666

sriup opened this issue Oct 9, 2019 · 13 comments
Labels
C-rb Ruby Bindings J-awaiting answer Question asked of user; a reply moves it to triage again

Comments

@sriup
Copy link
Contributor

sriup commented Oct 9, 2019

🐛 Bug Report

Script is failing to upload with "Selenium::WebDriver::Error::UnknownCommandError: unknown command: unknown command: session/xxxsession_idXXX/se/file" error message.

To Reproduce

Try uploading file to a file_feild in the below specified environment.

Expected behavior

File should be uploaded successfully. But we are getting the below error.

Selenium::WebDriver::Error::UnknownCommandError: unknown command: unknown command: session/xxxsession_idXXX/se/file
Backtrace:
       Ordinal0 [0x00FDEB13+1501971]
       Ordinal0 [0x00F5F6D1+980689]
        Ordinal0 [0x00EE765F+489055]
        Ordinal0 [0x00E9618E+156046]
        Ordinal0 [0x00E95FF4+155636]
        Ordinal0 [0x00E7220E+8718]
  Ordinal0 [0x00E72626+9766]
  Ordinal0 [0x00E72C10+11280]
 Ordinal0 [0x00F78F37+1085239]
       GetHandleVerifier [0x0107D7ED+503293]
       GetHandleVerifier [0x0107D580+502672]
       GetHandleVerifier [0x010846AC+531644]
       GetHandleVerifier [0x0107DFFA+505354]
       Ordinal0 [0x00F70606+1050118]
       Ordinal0 [0x00F7047F+1049727]
       Ordinal0 [0x00E7204B+8267]
  Ordinal0 [0x00E71D7C+7548]
  GetHandleVerifier [0x013CD83C+3976780]
      BaseThreadInitThunk [0x755738F4+36]
 RtlUnicodeStringToInteger [0x77375E13+595]
  RtlUnicodeStringToInteger [0x77375DDE+542]

Test script or set of commands reproducing this issue

@browser.file_field(xpath: "//*[contains(text(), 'Upload')]/input[@type='file']").set(@complete_path)

Environment

OS: Windows 10
Browser: Chrome
Browser version: 77
Browser Driver version: ChromeDriver 77
Language Bindings version: Ruby 3.142.6

Original code:
image

After removing /se/ from the below line, file upload is working as expected without error message.

image

Please let us know if there is any other way to handle this.

@sriup
Copy link
Contributor Author

sriup commented Oct 9, 2019

Tested the fix on chrome, firefox, ie, microsoft edge browsers. Let me know if you want me to submit a PR with this change.

@p0deje p0deje added the C-rb Ruby Bindings label Oct 9, 2019
@p0deje
Copy link
Member

p0deje commented Oct 9, 2019

Can you provide the full code how to reproduce the issue? In particular, I'm interested to see how you start the browser/driver and what options you use for starting.

@p0deje p0deje added the J-awaiting answer Question asked of user; a reply moves it to triage again label Oct 9, 2019
@sriup
Copy link
Contributor Author

sriup commented Oct 9, 2019

Here is the method that will get the capabilities based on the browser.

private_class_method def self.getCaps()
        ENV['DOWNLOAD_FOLDER'] = "#{Dir.home}/Downloads"
        if ENV['DOWNLOAD_FOLDER'].nil?
                        case ENV['BROWSER'].strip.downcase
                         when 'firefox'
                           profile = Selenium::WebDriver::Firefox::Profile.new
                           profile['browser.download.dir'] = ENV['DOWNLOAD_FOLDER']
                           profile['browser.download.folderList'] = 2
                           profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv,application/pdf,application/doc,application/docx,image/jpeg'
                           profile['browser.helperApps.alwaysAsk.force'] = false
                           profile['browser.download.manager.showWhenStarting'] = false
                           profile['pdfjs.disabled'] = true
                           caps = Selenium::WebDriver::Remote::Capabilities.firefox(profile: profile)
                           caps['acceptInsecureCerts'] = true
                           caps['browserName'] = 'firefox'
                         when 'ie'
                           caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer
                           caps['ignore_protected_mode_settings'] = true
                           caps['ignore_zoom_level'] = true
                           caps['iedriverVersion'] = '3.141.0'
                           caps['browserName'] = 'internet explorer'
                         else # when 'chrome'
                           caps = Selenium::WebDriver::Remote::Capabilities.chrome
                           google_download_path = ENV['DOWNLOAD_FOLDER'].gsub('/','\\')
                           caps['goog:chromeOptions'] = {
                               w3c: true,
                               args: ['--disable-popup-blocking', '--safebrowsing-disable-download-protection', '--safebrowsing-disable-extension-blacklist'],
                               prefs: { 'safebrowsing.enabled': true, download: { prompt_for_download: false, default_directory: google_download_path },
                                        'profile.default_content_setting_values.automatic_downloads': 1 } }
                           caps['browserName'] = 'chrome'
                         end
                         caps
                       end
end

And below the line of code that will create the @browser instance.

if is_running_on_sauceLabs != 'true'
      url = "http://127.0.0.1:5556/wd/hub" # running locally
    else
      url = "http://saucelabs_uname:saucelabs_pwd@saucelabs_grid_url/wd/hub"
    end
browser = Watir::Browser.new(:remote,
                                 http_client: client,
                                 url: url,
                                 desired_capabilities: @caps)
    $UPLOAD_VM = false
    if  is_running_on_sauceLabs == 'true'
      browser.driver.file_detector = lambda do |args|
        str = args.first.to_s
        str if File.exist?(str) && File.file?(str) && ($UPLOAD_VM == false)
      end

once the browser is initialized calling the below line when we are on the file upload page.

# @complete_path  - holds the absolute path to the file
@browser.file_field(xpath: "//*[contains(text(), 'Upload')]/input[@type='file']").set(@complete_path)

Let me know if you need any more information.

@sriup
Copy link
Contributor Author

sriup commented Oct 9, 2019

FYI - After further digging found out that the root cause of the issue is w3c: true in the capabilities. This issue is not happening when w3c: false.

@sriup sriup changed the title Ruby - Unable to upload file due to "Selenium::WebDriver::Error::UnknownCommandError:" Ruby - Unable to upload file when w3c browser capability is set to true Oct 9, 2019
@p0deje
Copy link
Member

p0deje commented Oct 10, 2019

What version of Grid do you use? It looks to me that you use recent ChromeDriver but maybe old Grid?

@sriup
Copy link
Contributor Author

sriup commented Oct 10, 2019

Currently we are using "3.141.59" .

image

Message from Jenkins console:
Starting Selenium 3.141.59 hub...

@p0deje
Copy link
Member

p0deje commented Oct 11, 2019

This is strange. I'm running the exact same configuration and it works perfectly fine for me:

  1. Grid 3.141.59
  2. Grid node 3.141.59
  3. Chrome 77
  4. ChromeDriver 77
  5. selenium-webdriver 3.142.6
require 'selenium-webdriver'

Selenium::WebDriver.logger.level = :info

begin
  driver = Selenium::WebDriver.for(:remote, url: 'http://localhost:4444/wd/hub', desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome('goog:chromeOptions' => {'w3c' => true}, 'browserName' => 'chrome'))
  driver.file_detector = ->(args) { args.first }
  driver.get 'https://www.websupergoo.com/file-upload-1.aspx'
  driver.find_element(css: 'input[type="file"]').send_keys __FILE__
ensure
  driver.quit
end
$ bundle exec ruby test.rb
...
2019-10-11 13:01:08 INFO Selenium -> POST session/289aac9491a2d491f4f79d5918152ba9/se/file
2019-10-11 13:01:08 INFO Selenium    >>> http://localhost:4444/wd/hub/session/289aac9491a2d491f4f79d5918152ba9/se/file | {"file":"UEsDBBQAAAAIACRoS09nX7TGPwEAAPcBAAAHAAAAdGVzdC5yYm2RP2vDMBDFd38KkUU2xDalnQTJ0j9QKC20Q4dSjG1dbFFZUk+nuCHku1d2SpMhWk560nu6n4TwHRQC4x40GBWGfIRGotoC8iR5+xOFeIfmblYLbbtuKrAFzVZMKLOxSdJAp0zC2NEa9UvWjcVUIAyWYMkCasF4T+REWWrb1rq3nsRNHOUoyz40fMkk+NidrNra1Y3SihR4cSlbiNc5V4jbs6NF26MdIOWdtZ04Ll4cKWs8Z6s12/Pxup1nhAEOS8YbtKMHfK4HmHV+NPEs+4crNkpDJYGgJTuh5uu0xs5nbM+mGvfREzucDB3QkdRH1HEci/jGPjjA2FbR2qGcEvPgtK1lflXU3v3w8+uMrCLxAIbS1kd+rowL9EE7B6vF5F188qzwEM99wc6zqnp4fLqvqgSMDwinqPjXFEWZ/AJQSwECNAMUAAAACAAkaEtPZ1+0xj8BAAD3AQAABwAAAAAAAAABAAAApIEAAAAAdGVzdC5yYlBLBQYAAAAAAQABADUAAABkAQAAAAA="}
2019-10-11 13:01:08 INFO Selenium <- {
  "value": "\u002fvar\u002ffolders\u002f3s\u002fyybq9c5n4pd0z9t4phtp6ml00000gn\u002fT\u002f289aac9491a2d491f4f79d5918152ba9\u002fupload8137789732763530948file\u002ftest.rb"
}
...

As you can see there is a request to /se/file and it's correctly handled by Grid.

Screenshot 2019-10-11 at 12 57 04

Can you strip down your test case to Ruby script like I made?

@sriup
Copy link
Contributor Author

sriup commented Oct 11, 2019

Sure, will check and update.

@alcalyn
Copy link

alcalyn commented Oct 31, 2019

Having the same issue using PHP Behat.

Seems to be related to docksal/behat#7

@sriup
Copy link
Contributor Author

sriup commented Jan 3, 2020

I don't see 'session/:session_id/se/file' end-point in the list of available endpoints from 'http://www.w3.org/TR/2015/WD-webdriver-20150918/#list-of-endpoints` page.

@twalpole
Copy link
Contributor

twalpole commented Jan 3, 2020

@sridharUpputuri it’s not a webdriver specified endpoint - it’s a selenium extension, as identified by the /se in the path

@AutomatedTester
Copy link
Member

Closing this as requested info not given

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-rb Ruby Bindings J-awaiting answer Question asked of user; a reply moves it to triage again
Projects
None yet
Development

No branches or pull requests

5 participants