Module: Calabash::Cucumber::TestsHelpers
- Includes:
- FailureHelpers
- Included in:
- Operations, WaitHelpers
- Defined in:
- lib/calabash-cucumber/tests_helpers.rb
Overview
A collection of methods to help you write tests.
Instance Method Summary collapse
-
#check_element_does_not_exist(query) ⇒ nil
raises a Runtime error (and generates a screenshot) if at least one element matches query ‘query`.
-
#check_element_exists(query) ⇒ nil
raises a Runtime error (and generates a screenshot) unless at least one element matches query ‘query`.
-
#check_view_with_mark_exists(expected_mark) ⇒ nil
raises a Runtime error (and generates a screenshot) unless at least one element matches mark ‘expected_mark`.
-
#classes(uiquery, *args) ⇒ Array<String>
Returns the classes of all views matching ‘uiquery`.
-
#each_cell(opts = {:query => "tableView", :post_scroll => 0.3, :animate => true}, &block) ⇒ Object
Calls given block with each row and section (‘yield(row, sec)`).
-
#element_does_not_exist(uiquery) ⇒ Boolean
Returns true if no element matches query ‘uiquery`.
-
#element_exists(uiquery) ⇒ Boolean
Returns true if at least one element matches query ‘uiquery`.
-
#view_with_mark_exists(expected_mark) ⇒ Boolean
Returns true if at least one element matches query ‘“* marked:’#expected_mark‘”`.
Methods included from FailureHelpers
#fail, #screenshot, #screenshot_and_raise, #screenshot_embed
Instance Method Details
#check_element_does_not_exist(query) ⇒ nil
raises a Runtime error (and generates a screenshot) if at least one element matches query ‘query`.
55 56 57 58 59 |
# File 'lib/calabash-cucumber/tests_helpers.rb', line 55 def check_element_does_not_exist(query) if element_exists(query) screenshot_and_raise "Expected no elements to match query: #{query}" end end |
#check_element_exists(query) ⇒ nil
raises a Runtime error (and generates a screenshot) unless at least one element matches query ‘query`.
45 46 47 48 49 |
# File 'lib/calabash-cucumber/tests_helpers.rb', line 45 def check_element_exists(query) if not element_exists(query) screenshot_and_raise "No element found for query: #{query}" end end |
#check_view_with_mark_exists(expected_mark) ⇒ nil
raises a Runtime error (and generates a screenshot) unless at least one element matches mark ‘expected_mark`.
65 66 67 |
# File 'lib/calabash-cucumber/tests_helpers.rb', line 65 def check_view_with_mark_exists(expected_mark) check_element_exists("view marked:'#{expected_mark}'") end |
#classes(uiquery, *args) ⇒ Array<String>
Returns the classes of all views matching ‘uiquery`
15 16 17 |
# File 'lib/calabash-cucumber/tests_helpers.rb', line 15 def classes(uiquery,*args) query_map(uiquery,:class,*args) end |
#each_cell(opts = {:query => "tableView", :post_scroll => 0.3, :animate => true}, &block) ⇒ Object
Calls given block with each row and section (‘yield(row, sec)`). Alternates between scrolling to each cell and yielding.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/calabash-cucumber/tests_helpers.rb', line 77 def each_cell(opts={:query => "tableView", :post_scroll => 0.3, :animate => true}, &block) uiquery = opts[:query] || "tableView" skip = opts[:skip_if] check_element_exists(uiquery) secs = query(uiquery,:numberOfSections).first secs.times do |sec| rows = query(uiquery,{:numberOfRowsInSection => sec}).first rows.times do |row| next if skip and skip.call(row,sec) scroll_opts = {:section => sec, :row => row}.merge(opts) scroll_to_cell(scroll_opts) sleep(opts[:post_scroll]) if opts[:post_scroll] and opts[:post_scroll] > 0 yield(row, sec) end end end |
#element_does_not_exist(uiquery) ⇒ Boolean
Returns true if no element matches query ‘uiquery`.
22 23 24 |
# File 'lib/calabash-cucumber/tests_helpers.rb', line 22 def element_does_not_exist(uiquery) query(uiquery).empty? end |
#element_exists(uiquery) ⇒ Boolean
Returns true if at least one element matches query ‘uiquery`.
29 30 31 |
# File 'lib/calabash-cucumber/tests_helpers.rb', line 29 def element_exists(uiquery) not element_does_not_exist(uiquery) end |
#view_with_mark_exists(expected_mark) ⇒ Boolean
Returns true if at least one element matches query ‘“* marked:’#expected_mark‘”`
37 38 39 |
# File 'lib/calabash-cucumber/tests_helpers.rb', line 37 def view_with_mark_exists(expected_mark) element_exists("view marked:'#{expected_mark}'") end |