web-dev-qa-db-fra.com

Comment désactiver w3c dans chromedriver pour résoudre la commande d'erreur inconnue: impossible d'appeler une commande standard non W3C en W3C

Avec la version 75 de Chrome vient de sortir, nos tests ne fonctionnent plus correctement. Ils donnent la trace de pile collée ci-dessous. Nous utilisons Ruby on Rails v. 5.1.6.2 avec rspec, Selenium-webdriver 3.8.0.

Trace de la pile:

Selenium::WebDriver::Error::UnknownCommandError:
            unknown command: Cannot call non W3C standard command while in W3C mode
          # 0   chromedriver                        0x000000010c46e8e9 chromedriver + 3594473
          # 1   chromedriver                        0x000000010c3fe543 chromedriver + 3134787
          # 2   chromedriver                        0x000000010c1aa29f chromedriver + 692895
          # 3   chromedriver                        0x000000010c11a691 chromedriver + 104081
          # 4   chromedriver                        0x000000010c11b7d5 chromedriver + 108501
          # 5   chromedriver                        0x000000010c42d555 chromedriver + 3327317
          # 6   chromedriver                        0x000000010c438e60 chromedriver + 3374688
          # 7   chromedriver                        0x000000010c438bf8 chromedriver + 3374072
          # 8   chromedriver                        0x000000010c40cd39 chromedriver + 3194169
          # 9   chromedriver                        0x000000010c4396d8 chromedriver + 3376856
          # 10  chromedriver                        0x000000010c420f27 chromedriver + 3276583
          # 11  chromedriver                        0x000000010c456064 chromedriver + 3493988
          # 12  chromedriver                        0x000000010c474617 chromedriver + 3618327
          # 13  libsystem_pthread.dylib             0x00007fff7744c2eb _pthread_body + 126
          # 14  libsystem_pthread.dylib             0x00007fff7744f249 _pthread_start + 66
          # 15  libsystem_pthread.dylib             0x00007fff7744b40d thread_start + 13
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/response.rb:69:in `assert_ok'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/response.rb:32:in `initialize'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/http/common.rb:81:in `new'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/http/common.rb:81:in `create_response'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/http/default.rb:104:in `request'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/http/common.rb:59:in `call'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/bridge.rb:166:in `execute'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/oss/bridge.rb:579:in `execute'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/remote/oss/bridge.rb:526:in `element_displayed?'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/Selenium-webdriver-3.8.0/lib/Selenium/webdriver/common/element.rb:199:in `displayed?'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/Selenium/node.rb:148:in `visible?'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/node/element.rb:269:in `block in visible?'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/node/base.rb:81:in `synchronize'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/node/element.rb:269:in `visible?'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/queries/selector_query.rb:84:in `matches_filters?'
          # /Users/julie/.rvm/gems/Ruby-2.5.1/gems/capybara-2.17.0/lib/capybara/result.rb:29:in `block in initialize'

Notre configuration de pilote:

File.write(LOG_FILE_PATH, '')
Selenium::WebDriver.logger.level = :debug
Selenium::WebDriver.logger.output = LOG_FILE_PATH
Capybara.register_driver :Selenium do |app|
  # from https://github.com/SeleniumHQ/Selenium/issues/3738
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs: {browser: 'ALL'})
  options = Selenium::WebDriver::Chrome::Options.new
  options.add_argument '--disable-infobars' # hide info bar about chrome automating test
  # if we don't use this flag, every Selenium test will die with the error:
  # "unknown error: Chrome failed to start: exited abnormally"
  options.add_argument '--no-sandbox'
  options.add_argument '--headless' if ENV.fetch("HEADLESS", nil).present?
  options.add_argument '--window-size=1600,2400'
  options.add_argument '-–allow-file-access-from-files' # TODO Julie - may help with file specs?
  options.add_preference('homepage', 'about:blank') # TODO is this working?
  options.add_preference('profile.default_content_settings.popups', 0)
  options.add_preference('download.default_directory', DownloadHelpers::PATH.to_s)
  Capybara::Selenium::Driver.new(
    app,
    clear_local_storage: true,
    clear_session_storage: true,
    browser: :chrome,
    options: options,
    desired_capabilities: capabilities,
  )
end

MISE À JOUR:

J'ai pu faire fonctionner nos tests temporairement en utilisant capabilities = { "chromeOptions" => {'w3c' => false} }.

Après la mise à jour de chromedriver, nous avons commencé à recevoir l'erreur "erreur inconnue: le fichier DevToolsActivePort n'existe pas". Afin de résoudre ce problème, nous avons mis à niveau notre gem Selenerium-webdriver à 3.142.3 et cela a résolu le problème, nous permettant d'utiliser w3c sans aucun paramètre supplémentaire.

19
Julie

Voici comment cela peut être fait dans Behat avec Mink: # behat #mink

  Behat\MinkExtension:
    base_url: "your_site_url"
    browser_name: 'chrome'
    goutte: ~
    javascript_session: Selenium2
    Selenium2:
      wd_Host: http://127.0.0.1:4444/wd/hub
      capabilities:
        browser: chrome
        extra_capabilities:
          chromeOptions:
            args: ['--headless', '--disable-gpu']
            w3c: false
0
Shweta Sharma

Les utilisateurs de PHP Behat-Mink-Selenium voient ce post pour plus d'informations: https://medium.com/@alex.designworks/chromedriver-75-enforces-w3c-standard-breaking-behat-tests-460cad435545 et problème GitHub https://github.com/minkphp/MinkSelenium2Driver/issues/29

À partir de ce post, la "solution de contournement" est de revenir à Chrome 74 pour ceux qui utilisent Behat-Mink-Selenium.

0
Phil Davis