spriteCloud / lapis-lazuli

Cucumber helper functions and scaffolding for easier test automation suite development.
Other
7 stars 7 forks source link

No error is thrown when element is not present using only :element in combination with a :context #42

Open sjieg opened 8 years ago

sjieg commented 8 years ago

Reproduce:

browser.goto 'google.com'
parent = browser.find(:like => [:a, :href, '//www.google.nl/intl/en/ads/?'])
elm = browser.find(
  :input,
  :context => parent,
  :filter_by => :present?
)
# => #<Watir::HTMLElement:0x11f46a1c located=false selector={element: (webdriver element)}>
elm.present?
# => false
elm = browser.find(
  :like => [:input, :name, 'q'],
  :context => parent,
  :filter_by => :present?
)
# => RuntimeError: Error in find - Cannot find elements with selectors: (...)

The above shows that LL isn't throwing an error when only searching for an element (without any attribute or value).

Workaround:

if !elm.present?
  error 'Unable to find element.'
end

Note that :filter_by => :present? is not necessary, because this is the LL default. I've added it to emphasize on it.

sjieg commented 7 years ago

I've investigated more into this problem. It seems the issue is not necessarily Lapis Lazuli. When using :a as a value in the find function, you're not directly creating a hash, but just adding a value to an array. So:

value = :a, :filter_by => :present?
#is the same as
[
  :a,
  {
    :filter_by => :present?
  }
]

But when using the long notation, the selector will be a hash instead of a array:

value = :element => a, :filter_by => :present?
# is the same as
{
  :element => :a,
  :filter_by => :present?
}

This difference is causing LL to ignore the :context: given with an element, because the :context is in a Hash, inside an Array inside a Hash.

For now this is too much effort to change, and the solution for now should be to not use direct selections.