Module: Briar::Bars
- Defined in:
- lib/briar/bars/navbar.rb,
lib/briar/bars/tabbar.rb,
lib/briar/bars/toolbar.rb
Instance Method Summary collapse
- #date_is_in_navbar(date) ⇒ Object
- #go_back_after_waiting(opts = {}) ⇒ Object
- #go_back_and_wait_for_view(view) ⇒ Object
-
#index_of_navbar_button(name) ⇒ Object
will not work to detect left/right buttons.
- #index_of_tabbar_item(name) ⇒ Object
- #navbar_has_back_button? ⇒ Boolean
- #navbar_has_title?(title) ⇒ Boolean
- #navbar_visible? ⇒ Boolean
- #should_not_see_navbar ⇒ Object
- #should_not_see_navbar_back_button ⇒ Object
-
#should_not_see_navbar_button(mark, opts = {}) ⇒ Object
todo convert args to hash and mirror the should_see_navbar_button is_ui_button=false).
- #should_not_see_tabbar ⇒ Object
- #should_not_see_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
- #should_see_navbar ⇒ Object
- #should_see_navbar_back_button ⇒ Object
-
#should_see_navbar_button(mark, opts = {}) ⇒ Object
bar_button_type options => button <= the button is a UIButton bar_item <= the button is UIBarButtonItem.
- #should_see_navbar_with_title(title, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
- #should_see_tab_at_index(name, index) ⇒ Object
- #should_see_tabbar ⇒ Object
- #should_see_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
- #should_see_toolbar_button(button_id, opts = {:timeout => BRIAR_WAIT_TIMEOUT, :toolbar_id => nil}) ⇒ Object
- #tabbar_visible? ⇒ Boolean
- #toolbar_button_exists?(button_id, opts = {:toolbar_id => nil}) ⇒ Boolean
- #toolbar_exists?(id) ⇒ Boolean
- #toolbar_qstr(toolbar_id = nil) ⇒ Object
- #touch_navbar_item(item_name, wait_for_view_id = nil) ⇒ Object
- #touch_navbar_item_and_wait_for_view(item_name, view_id) ⇒ Object
- #touch_tabbar_item(name, wait_for_view_id = nil) ⇒ Object
- #touch_toolbar_button(button_id, opts = {}) ⇒ Object
- #wait_for_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
- #wait_for_toolbar_button(button_id, opts = {}) ⇒ Object
- #wait_for_toolbar_to_disappear(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
Instance Method Details
#date_is_in_navbar(date) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/briar/bars/navbar.rb', line 119 def (date) with_leading = date.strftime('%a %b %d') without_leading = date.strftime("%a %b #{date.day}") items = query('navigationItemView', AL) items.include?(with_leading) || items.include?(without_leading) end |
#go_back_after_waiting(opts = {}) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/briar/bars/navbar.rb', line 127 def go_back_after_waiting(opts={}) default_opts = {:wait_before_going_back => 0.2, :timeout => BRIAR_WAIT_TIMEOUT, :timeout_message => nil, :wait_step_pause => BRIAR_WAIT_STEP_PAUSE, :retry_frequency => BRIAR_WAIT_RETRY_FREQ} opts = default_opts.merge(opts) wait_before = opts[:wait_before_going_back] sleep(wait_before) msg = opts[:timeout_message] timeout = opts[:timeout] if msg.nil? msg = "waited for '#{timeout + wait_before}' for navbar back button but didn't see it" end wait_for(:timeout => timeout, :retry_frequency => opts[:retry_frequency], :post_timeout => opts[:wait_step_pause], :timeout_message => msg) do not query('navigationItemButtonView first').empty? end touch('navigationItemButtonView first') step_pause end |
#go_back_and_wait_for_view(view) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/briar/bars/navbar.rb', line 153 def go_back_and_wait_for_view (view) sleep(0.2) timeout = BRIAR_WAIT_TIMEOUT msg = "waited '#{timeout}' seconds but did not see navbar back button" wait_for(wait_opts(msg, timeout)) do not query('navigationItemButtonView first').empty? end touch_transition('navigationItemButtonView first', "view marked:'#{view}'", {:timeout => TOUCH_TRANSITION_TIMEOUT, :retry_frequency => TOUCH_TRANSITION_RETRY_FREQ}) step_pause end |
#index_of_navbar_button(name) ⇒ Object
will not work to detect left/right buttons
55 56 57 58 |
# File 'lib/briar/bars/navbar.rb', line 55 def (name) titles = query('navigationButton', AL) titles.index(name) end |
#index_of_tabbar_item(name) ⇒ Object
21 22 23 24 |
# File 'lib/briar/bars/tabbar.rb', line 21 def (name) tabs = query('tabBarButton', AL) tabs.index(name) end |
#navbar_has_back_button? ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/briar/bars/navbar.rb', line 21 def res = query('navigationItemButtonView') return false if res.empty? # sometime the back button is there, but has zero rect frame = res.first['frame'] ['x', 'y', 'width', 'height'].each { |key| if frame[key] != 0 return true end } false end |
#navbar_has_title?(title) ⇒ Boolean
197 198 199 200 201 202 |
# File 'lib/briar/bars/navbar.rb', line 197 def (title) all_items = query("navigationItemView marked:'#{title}'") = query('navigationItemButtonView') = all_items.delete_if { |item| .include?(item) } !.empty? end |
#navbar_visible? ⇒ Boolean
5 6 7 |
# File 'lib/briar/bars/navbar.rb', line 5 def !query('navigationBar').empty? end |
#should_not_see_navbar ⇒ Object
15 16 17 18 19 |
# File 'lib/briar/bars/navbar.rb', line 15 def if screenshot_and_raise 'should not see the nav bar' end end |
#should_not_see_navbar_back_button ⇒ Object
47 48 49 50 51 |
# File 'lib/briar/bars/navbar.rb', line 47 def if screenshot_and_raise 'i should not see navigation bar back button' end end |
#should_not_see_navbar_button(mark, opts = {}) ⇒ Object
todo convert args to hash and mirror the should_see_navbar_button is_ui_button=false)
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/briar/bars/navbar.rb', line 90 def (mark, opts={}) if (not opts.is_a?(Hash)) and (not opts.nil?) warn "\nWARN: deprecated 0.1.4 - you should no longer pass a Boolean '#{opts}' as an arg, pass opts hash instead" = opts ? :button : :bar_item opts = {:bar_button_type => } end default_opts = {:bar_button_type => :bar_item, :timeout => BRIAR_WAIT_TIMEOUT} opts = default_opts.merge(opts) if opts[:bar_button_type] == :button queries = ["buttonLabel marked:'#{mark}' parent navigationBar", "button marked:'#{mark}' parent navigationBar"] timeout = opts[:timeout] msg = "waited for '#{timeout}' seconds but i still see '#{mark}' in navigation bar" wait_for(:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg) do queries.all? { |query| element_does_not_exist query } end else idx = mark unless idx.nil? # check to see if it is a ui button mark, {:bar_button_type => :button} end end end |
#should_not_see_tabbar ⇒ Object
15 16 17 18 19 |
# File 'lib/briar/bars/tabbar.rb', line 15 def if screenshot_and_raise 'i should not see the tabbar' end end |
#should_not_see_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
22 23 24 25 |
# File 'lib/briar/bars/toolbar.rb', line 22 def (, timeout=BRIAR_WAIT_TIMEOUT) , timeout screenshot_and_raise "did not expect to see toolbar with id '#{}'" if end |
#should_see_navbar ⇒ Object
9 10 11 12 13 |
# File 'lib/briar/bars/navbar.rb', line 9 def unless screenshot_and_raise 'should see the nav bar' end end |
#should_see_navbar_back_button ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/briar/bars/navbar.rb', line 36 def timeout = BRIAR_WAIT_TIMEOUT * 2.0 msg = "waited for '#{timeout}' seconds but did not see navbar back button" wait_for(:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg) do end end |
#should_see_navbar_button(mark, opts = {}) ⇒ Object
bar_button_type options => button <= the button is a UIButton bar_item <= the button is UIBarButtonItem
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/briar/bars/navbar.rb', line 63 def (mark, opts={}) default_opts = {:bar_button_type => :bar_item, :timeout => BRIAR_WAIT_TIMEOUT} opts = default_opts.merge(opts) if opts[:bar_button_type] == :button queries = ["buttonLabel marked:'#{mark}' parent navigationBar", "button marked:'#{mark}' parent navigationBar"] timeout = opts[:timeout] msg = "waited for '#{timeout}' seconds but did not see '#{mark}' in navigation bar" wait_for(:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg) do queries.any? { |query| element_exists query } end else idx = mark if idx.nil? # check to see if it is a ui button mark, {:bar_button_type => :button} end end end |
#should_see_navbar_with_title(title, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'lib/briar/bars/navbar.rb', line 204 def (title, timeout=BRIAR_WAIT_TIMEOUT) msg = "waited for '#{timeout}' seconds but i did not see #{title} in navbar" wait_for(:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg) do title end end |
#should_see_tab_at_index(name, index) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/briar/bars/tabbar.rb', line 45 def should_see_tab_at_index(name, index) tabs = query('tabBarButton', AL) unless tabs.index(name) == index.to_i screenshot_and_raise "should have seen tab named '#{name}' at index '#{index}' but found these: '#{tabs}'" end end |
#should_see_tabbar ⇒ Object
9 10 11 12 13 |
# File 'lib/briar/bars/tabbar.rb', line 9 def unless screenshot_and_raise 'i should see the tabbar' end end |
#should_see_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
18 19 20 |
# File 'lib/briar/bars/toolbar.rb', line 18 def (, timeout=BRIAR_WAIT_TIMEOUT) (, timeout) end |
#should_see_toolbar_button(button_id, opts = {:timeout => BRIAR_WAIT_TIMEOUT, :toolbar_id => nil}) ⇒ Object
68 69 70 71 |
# File 'lib/briar/bars/toolbar.rb', line 68 def (, opts={:timeout => BRIAR_WAIT_TIMEOUT, :toolbar_id => nil}) , opts end |
#tabbar_visible? ⇒ Boolean
5 6 7 |
# File 'lib/briar/bars/tabbar.rb', line 5 def element_exists('tabBar') end |
#toolbar_button_exists?(button_id, opts = {:toolbar_id => nil}) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/briar/bars/toolbar.rb', line 27 def (, opts={:toolbar_id => nil}) = opts[:toolbar_id] if .nil? not query("toolbar descendant view marked:'#{}'").empty? else not query("toolbar marked:'#{}' descendant view marked:'#{}'").empty? end # the problem here is that toolbar buttons come in many different flavors ## look for text button #text_button_arr = query("toolbar child toolbarTextButton child button child buttonLabel", :text) #has_text_button = text_button_arr.index(name_or_id) != nil ## look for non_text button #toolbar_button_arr = query("toolbar child toolbarButton", AL) #has_toolbar_button = toolbar_button_arr.index(name_or_id) != nil # #has_text_button or has_toolbar_button end |
#toolbar_exists?(id) ⇒ Boolean
14 15 16 |
# File 'lib/briar/bars/toolbar.rb', line 14 def (id) !query("toolbar marked:'#{id}'").empty? end |
#toolbar_qstr(toolbar_id = nil) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/briar/bars/toolbar.rb', line 6 def (=nil) if .nil? 'toolbar' else "toolbar marked:'#{}'" end end |
#touch_navbar_item(item_name, wait_for_view_id = nil) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/briar/bars/navbar.rb', line 168 def (item_name, wait_for_view_id=nil) timeout = BRIAR_WAIT_TIMEOUT msg = "waited '#{timeout}' seconds for nav bar item '#{item_name}' to appear" wait_for(wait_opts(msg, timeout)) do ((item_name) != nil) || (item_name) end sleep(0.2) idx = item_name if idx touch("navigationButton index:#{idx}") unless wait_for_view_id.nil? wait_for_view wait_for_view_id end step_pause elsif item_name item_name, wait_for_view_id else screenshot_and_raise "could not find navbar item '#{item_name}'" end end |
#touch_navbar_item_and_wait_for_view(item_name, view_id) ⇒ Object
193 194 195 |
# File 'lib/briar/bars/navbar.rb', line 193 def (item_name, view_id) item_name, view_id end |
#touch_tabbar_item(name, wait_for_view_id = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/briar/bars/tabbar.rb', line 26 def (name, wait_for_view_id=nil) sleep(0.2) wait_for(:timeout => BRIAR_WAIT_TIMEOUT, :retry_frequency => BRIAR_WAIT_RETRY_FREQ) do (name) != nil end idx = name if idx touch "tabBarButton index:#{idx}" unless wait_for_view_id.nil? wait_for_view wait_for_view_id end step_pause else screenshot_and_raise "tabbar button with name #{name} does not exist" end end |
#touch_toolbar_button(button_id, opts = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/briar/bars/toolbar.rb', line 99 def (, opts={}) if opts.is_a?(Hash) default_opts ={:wait_for_view => nil, :timeout => BRIAR_WAIT_TIMEOUT, :toolbar_id => nil} opts = default_opts.merge(opts) else _deprecated('0.1.2', "second argument should be a hash - found '#{opts}'", :warn) opts = {:wait_for_view => opts[:wait_for_view], :timeout => BRIAR_WAIT_TIMEOUT, :toolbar_id => nil} end , opts = (opts[:toolbar_id]) touch("#{} descendant view marked:'#{}'") wait_for_view = opts[:wait_for_view] unless wait_for_view.nil? timeout = opts[:timeout] msg = "touched '#{}' and waited for '#{timeout}' sec but did not see '#{wait_for_view}'" = {:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg} wait_for() do view_exists? wait_for_view end end end |
#wait_for_toolbar(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/briar/bars/toolbar.rb', line 86 def (, timeout=BRIAR_WAIT_TIMEOUT) msg = "waited for '#{timeout}' seconds but did not see toolbar marked: '#{}'" = {:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg} wait_for() do end end |
#wait_for_toolbar_button(button_id, opts = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/briar/bars/toolbar.rb', line 46 def (, opts={}) default_opts = {:timeout => BRIAR_WAIT_TIMEOUT, :toolbar_id => nil} opts = default_opts.merge(opts) timeout=opts[:timeout] = opts[:toolbar_id] if .nil? msg = "waited for '#{timeout}' seconds but did not see toolbar button marked: '#{}'" else msg = "waited for '#{timeout}' seconds but did not see toolbar button marked: '#{}' in toolbar '#{}'" end = {:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg} wait_for() do , opts end end |
#wait_for_toolbar_to_disappear(toolbar_id, timeout = BRIAR_WAIT_TIMEOUT) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/briar/bars/toolbar.rb', line 73 def (, timeout=BRIAR_WAIT_TIMEOUT) msg = "waited for '#{timeout}' seconds but i still see toolbar marked: '#{}'" = {:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg} wait_for() do not end end |