我最近继承了一个运行watir-webdriver(0.6.4)的Ruby测试套件,但不幸的是,套件在我的同事的机器上运行得很好,但是在我的机器上却出现了一些错误。我尝试将所有gem的每个版本都锁定在他的计算机上的确切版本中,以尝试解决兼容性问题,但没有问题。核心错误似乎是我从watir的内部`assert_valid_as_attribute'方法获得以下异常:
(Watir::Exception::MissingWayOfFindingObjectException: invalid attribute: :css)
我的代码中的发起呼叫是:
search_results.selectable_cards_plural.take(assets_selected).each { |assets| assets.fire_event ("onclick") }
search_results{...}.take
返回div数组。
以前有没有人看过这个问题?我看过另外两个SO帖子提到了这个问题,但是他们两个似乎都没有解决我的特定问题。
我在下面包含了我的gemfile.lock的一部分,以防有人轻易发现兼容性问题。我正在运行Ruby 2.5.0。是的,我计划在不久的将来更新测试以运行较新的gem版本,但是我希望同时运行这些旧的回归测试。
上述选择器:
def search_results; @browser.div(:class, 'search-results-grid') end
def selectable_cards_plural; divs(:css => 'div.p-card-hover.p-card-selectable:not(.p-card-selected)') end
所选元素为: class =“ p-card-hover p-card-selectable css-g6ribn-StyledCardHover-visible-visible-visible-visible-visible-StyledCardHover erkh22a0”
环境信息: macOS macOS 10.14.3(Mojave) Chrome版本72.0.3626.121 浏览器驱动程序:@browser = Watir :: Browser.new:chrome,:prefs => chrome_prefs,开关:%w [-window-size = 1600,900 --ignore-certificate-errors --disable-popup-blocking- -disable-translate]
堆栈跟踪:
Asset Section: Adding # When selecting specific # from search adds assets to section
Failure/Error: search_results.selectable_cards_plural.take(assets_selected).each { |assets| assets.fire_event ("onclick") }
Watir::Exception::MissingWayOfFindingObjectException:
invalid attribute: :css
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:238:in `assert_valid_as_attribute'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:219:in `normalize_selector'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:198:in `block in normalized_selector'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:195:in `each'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:195:in `normalized_selector'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:98:in `find_all_by_multiple'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/locators/element_locator.rb:46:in `locate_all'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/element_collection.rb:96:in `elements'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/element_collection.rb:86:in `to_a'
# /Users/jnguyen/.rvm/gems/ruby-2.5.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/element_collection.rb:29:in `each'
# ./lib/live_editor/assets_le.rb:37:in `take'
# ./lib/live_editor/assets_le.rb:37:in `select_assets'
# ./spec/smoke/live_editor/standard/asset_add_num_spec.rb:23:in `block (3 levels) in <top (required)>'
Gemfile.lock
{...}
commonwatir (4.0.0)
rake (12.3.2)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.2)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rspec_html_formatter (0.3.1)
activesupport (>= 4.1.4)
rouge (>= 1.6.1)
rspec-core (>= 3.0.3)
selenium-webdriver (2.53.4)
childprocess (~> 0.5)
rubyzip (~> 1.0)
websocket (~> 1.0)
watir (5.0.0)
commonwatir (~> 4)
watir-webdriver
watir-rspec (2.0.3)
rspec (~> 3.0)
watir (~> 5.0)
watir-scroll (0.1.0)
watir-webdriver
watir-webdriver (0.6.4)
selenium-webdriver (>= 2.18.0)
PLATFORMS
ruby
DEPENDENCIES
{...}
rake
rspec (= 3.5.0)
rspec-core (= 3.5.2)
rspec_html_formatter (~> 0.3.1)
selenium-webdriver (= 2.53.4)
watir (~> 5.0.0)
watir-rspec (= 2.0.3)
watir-scroll (~> 0.1.0)
watir-webdriver (= 0.6.4)
BUNDLED WITH
1.17.3
答案 0 :(得分:1)
似乎版本不匹配。
在v0.6.4中,以下内容将引发异常:
gem 'selenium-webdriver', '=2.53.4'
gem 'watir-webdriver', '=0.6.7'
require 'watir-webdriver'
browser = Watir::Browser.new :chrome
at_exit { browser.close }
p browser.divs(:css => 'div').count
#=> `assert_valid_as_attribute': invalid attribute: :css (Watir::Exception::MissingWayOfFindingObjectException)
在此版本中,:css
定位符的唯一支持是它本身的支持。上面的示例将包含:tag_name
定位符,这是导致异常的原因。您将不得不使用#elements
而不是divs
。
v0.6.8(https://github.com/watir/watir/pull/244)中已解决此问题。我希望您的代码库至少是使用v0.6.8创建的。