Difference between revisions of "Lapis Lazuli:Default values for find / multi find / find all / multi find all and wait options"

From Test Automation Wiki
Jump to: navigation, search
(Created page with "Lapis Lazuli is a tool to helps you select an element easier than Watir and it also applies best practises. On this page it is explained how to select an element in multiple w...")
 
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Lapis Lazuli is a tool to helps you select an element easier than Watir and it also applies best practises. On this page it is explained how to select an element in multiple ways.
 
 
## Defaults
 
 
 
The default options for a find action:
 
The default options for a find action:
 
<syntaxhighlight lang="ruby">
 
<syntaxhighlight lang="ruby">
Line 8: Line 4:
 
browser.find(
 
browser.find(
 
   :element => {:attribute => :value}, # E.G. :input => {:name => 'username'}
 
   :element => {:attribute => :value}, # E.G. :input => {:name => 'username'}
   :filter_by => :present?, # Only look for elements that are present
+
   :filter_by => :present?, # :present? / :exists? Can we see and interact with it or is it anywhere in the code
 
   :context => a_different_element, # Optionally add a context element to search within
 
   :context => a_different_element, # Optionally add a context element to search within
 
   :pick => :first, # pick the :first / :last / :random / [int] of the found elements
 
   :pick => :first, # pick the :first / :last / :random / [int] of the found elements
Line 14: Line 10:
 
   :message => nil, # When nil a default error will be thrown, else you can add a string for a custom error message
 
   :message => nil, # When nil a default error will be thrown, else you can add a string for a custom error message
 
)
 
)
 +
 
# find_all defaults, returns an array of elements
 
# find_all defaults, returns an array of elements
 
browser.find_all(
 
browser.find_all(
Line 19: Line 16:
 
   :pick => nil, # When :pick is nil, all found elements will be returned in an array
 
   :pick => nil, # When :pick is nil, all found elements will be returned in an array
 
)
 
)
 +
 
# multi_find defaults, returns 1 element that matches ANY of the selectors
 
# multi_find defaults, returns 1 element that matches ANY of the selectors
 
browser.multi_find(
 
browser.multi_find(
Line 36: Line 34:
 
# The rest of the options are the same as browser.find
 
# The rest of the options are the same as browser.find
 
)
 
)
 +
 
# multi_find_all, returns all the elements that match any of the selectors
 
# multi_find_all, returns all the elements that match any of the selectors
browser.multi_find(
+
browser.multi_find_all(
 
   :selectors => [# A list of different element selectors
 
   :selectors => [# A list of different element selectors
 
     # The same as with browser.multi_find
 
     # The same as with browser.multi_find
Line 45: Line 44:
 
# The rest of the options are the same as browser.find
 
# The rest of the options are the same as browser.find
 
)
 
)
 +
 
# wait, waits 10 seconds for the selectors to return a value and else throws an error
 
# wait, waits 10 seconds for the selectors to return a value and else throws an error
 
browser.wait(
 
browser.wait(
Line 51: Line 51:
 
   :condition => :until # wait :until or :while an element is present
 
   :condition => :until # wait :until or :while an element is present
 
)
 
)
 +
 
# wait_all. multi_wait & multi_wait_all are the same as their find relatives, but than with the wait options.
 
# wait_all. multi_wait & multi_wait_all are the same as their find relatives, but than with the wait options.
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
On [[Lapis Lazuli:Selecting an element]] we go deeper into how to use this in practise.

Latest revision as of 10:36, 1 June 2017

The default options for a find action:

# find defaults, returns 1 element
browser.find(
  :element => {:attribute => :value}, # E.G. :input => {:name => 'username'}
  :filter_by => :present?, # :present? / :exists? Can we see and interact with it or is it anywhere in the code
  :context => a_different_element, # Optionally add a context element to search within
  :pick => :first, # pick the :first / :last / :random / [int] of the found elements
  :throw => true, # When false, no error will be thrown if the element can't be found
  :message => nil, # When nil a default error will be thrown, else you can add a string for a custom error message
)

# find_all defaults, returns an array of elements
browser.find_all(
  # All the options are the same, except:
  :pick => nil, # When :pick is nil, all found elements will be returned in an array
)

# multi_find defaults, returns 1 element that matches ANY of the selectors
browser.multi_find(
  :selectors => [# A list of different element selectors
    {
      :element => {:attribute => 'value'}, # E.G. :input => {:name => 'username'}
      :filter_by => :present?, # Only look for elements that are present
      :context => a_different_element # Optionally add a context element to search within
    },
    {
      :anotherElement => {:attribute => 'differentValue'}, # E.G. :input => {:name => 'username'}
      :filter_by => :present?, # Only look for elements that are present
      :context => a_different_element # Optionally add a context element to search within
    }
  ],
  :mode => :match_any, # :match_one / :match_any / :match_all of the given selectors
# The rest of the options are the same as browser.find
)

# multi_find_all, returns all the elements that match any of the selectors
browser.multi_find_all(
  :selectors => [# A list of different element selectors
    # The same as with browser.multi_find
  ],
  :mode => :match_any, # :match_one / :match_any / :match_all of the given selectors
  :pick => nil, # When :pick is nil, all found elements will be returned in an array
# The rest of the options are the same as browser.find
)

# wait, waits 10 seconds for the selectors to return a value and else throws an error
browser.wait(
  # All the options are the same as browser.find
  :timeout => 10, # [int] in seconds to wait for the element to appear
  :condition => :until # wait :until or :while an element is present
)

# wait_all. multi_wait & multi_wait_all are the same as their find relatives, but than with the wait options.

On Lapis Lazuli:Selecting an element we go deeper into how to use this in practise.