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...")
 
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.
 
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
+
== Defaults ==
  
 
The default options for a find action:
 
The default options for a find action:
Line 14: Line 14:
 
   :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 20:
 
   :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 38:
 
# 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(
Line 45: Line 48:
 
# 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 55:
 
   :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>

Revision as of 13:51, 31 May 2017

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:

# find defaults, returns 1 element
browser.find(
  :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
  :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(
  :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.