web-dev-qa-db-ja.com

不明なコマンドのエラーに対処するためにchromedriverでw3cをオフにする方法:W3Cにいる間は非W3C標準コマンドを呼び出せません

Chromeのバージョン75がリリースされたばかりで、テストは適切に実行されなくなりました。以下に貼り付けたスタックトレースが表示されます。Ruby on Rails v。5.1.6.2、rspec、Selenium-webdriver 3.8.0。

スタックトレース:

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'

ドライバー構成:

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

更新:

capabilities = { "chromeOptions" => {'w3c' => false} }を使用して、テストを一時的に動作させることができました。

Chromedriverを更新した後、「不明なエラー:DevToolsActivePortファイルが存在しません」というエラーを受け取り始めました。この問題を修正するために、Selenium-webdriver gemを3.142.3にアップグレードしました。これにより問題が修正され、追加のパラメーターなしでw3cを使用できるようになりました。

19
Julie

これは、ミンクを使ってBehatで行う方法です。#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

PHP Behat-Mink-Seleniumユーザーは、この投稿を参照してください: https://medium.com/@alex.designworks/chromedriver-75-enforces-w3c-standard-breaking-behat-tests-460cad435545 およびGitHubの問題 https://github.com/minkphp/MinkSelenium2Driver/issues/29

この投稿の「回避策」は、Behat-Mink-Seleniumを使用している場合はChrome 74にフォールバックすることです。

0
Phil Davis