Module: Briar::Email
- Defined in:
- lib/briar/email.rb
Instance Method Summary collapse
- #delete_draft_and_wait_for(view_id, opts = {}) ⇒ Object
-
#device_can_send_email ⇒ Object
noinspection RubyResolve.
- #email_body ⇒ Object
- #email_body_contains?(text) ⇒ Boolean
- #email_not_testable? ⇒ Boolean
- #email_subject ⇒ Object
- #email_subject_has_text_like?(text) ⇒ Boolean
- #email_subject_is?(text) ⇒ Boolean
- #email_testable? ⇒ Boolean
- #email_to ⇒ Object
- #email_to_contains?(address) ⇒ Boolean
- #email_to_field_is?(text) ⇒ Boolean
- #is_ios5_mail_view ⇒ Object
- #should_see_mail_view(opts = {:timeout => BRIAR_WAIT_TIMEOUT, :email_view_mark => 'compose email'}) ⇒ Object
- #should_see_recipients(addresses) ⇒ Object
- #uia_send_email_to(addresses, opts = {}) ⇒ Object
- #uia_set_email_to(addresses, opts = {}) ⇒ Object
- #uia_touch_email_to(opts = {}) ⇒ Object
- #uia_touch_send_email ⇒ Object
- #warn_about_no_ios5_email_view ⇒ Object
Instance Method Details
#delete_draft_and_wait_for(view_id, opts = {}) ⇒ Object
122 123 124 125 126 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/briar/email.rb', line 122 def delete_draft_and_wait_for (view_id, opts={}) if email_not_testable? warn_about_no_ios5_email_view return end default_opts = {:timeout => BRIAR_WAIT_TIMEOUT, :email_view_mark => 'compose email'} opts = default_opts.merge(opts) # does a wait for iOS > 5 + uia available should_see_mail_view opts if ios5? 'Cancel', 'Delete Draft' step_pause 'Delete Draft', view_id else if ios6? or ios7? sbo = .to_sym if sbo.eql?(:left) or sbo.eql?(:right) pending "5 < iOS < 8 detected AND orientation '#{sbo}' - there is a bug in UIAutomation that prohibits touching the cancel button" end if sbo.eql?(:up) and ipad? pending "5 < iOS < 8 detected AND orientation '#{sbo}' AND ipad - there is a bug in UIAutomation prohibits touching the cancel button" end end timeout = BRIAR_WAIT_TIMEOUT msg = "waited for '#{timeout}' seconds but did not see cancel button" wait_for(:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg) do uia_element_exists?(:view, {:marked => 'Cancel'}) end uia_tap_mark('Cancel') # In iOS 8, there is no 'Delete Draft' action sheet, the email compose # view animates off. if !(ios8? || ios9?) msg = "waited for '#{timeout}' seconds but did not see dismiss email action sheet" wait_for(:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg) do uia_element_exists?(:view, {:marked => 'Delete Draft'}) end uia_tap_mark('Delete Draft') end wait_for_view_to_disappear default_opts[:email_view_mark] wait_for_view view_id end step_pause end |
#device_can_send_email ⇒ Object
noinspection RubyResolve
113 114 115 116 117 118 119 120 |
# File 'lib/briar/email.rb', line 113 def device_can_send_email return true if simulator? if defined? backdoor_device_configured_for_mail? backdoor_device_configured_for_mail? else pending 'you will need to create a backdoor method to check if the device can send an email' end end |
#email_body ⇒ Object
19 20 21 |
# File 'lib/briar/email.rb', line 19 def email_body query("view:'MFComposeTextContentView'", :text) end |
#email_body_contains?(text) ⇒ Boolean
23 24 25 26 27 28 29 |
# File 'lib/briar/email.rb', line 23 def email_body_contains? (text) if ios5? !query("view:'MFComposeTextContentView' {text LIKE '*#{text}*'}").empty? else warn 'WARN: iOS > 5 detected - cannot test for email body text' end end |
#email_not_testable? ⇒ Boolean
11 12 13 |
# File 'lib/briar/email.rb', line 11 def email_not_testable? not email_testable? end |
#email_subject ⇒ Object
31 32 33 |
# File 'lib/briar/email.rb', line 31 def email_subject query("view:'MFComposeSubjectView'", :text).first end |
#email_subject_has_text_like?(text) ⇒ Boolean
43 44 45 46 47 48 49 |
# File 'lib/briar/email.rb', line 43 def email_subject_has_text_like? (text) if ios5? !query("view:'MFComposeSubjectView' {text LIKE '*#{text}*'}").empty? else warn 'WARN: iOS > 5 detected - cannot test for email subject text' end end |
#email_subject_is?(text) ⇒ Boolean
35 36 37 38 39 40 41 |
# File 'lib/briar/email.rb', line 35 def email_subject_is? (text) if ios5? email_subject.eql? text else warn 'WARN: iOS > 5 detected - cannot test for email subject text' end end |
#email_testable? ⇒ Boolean
6 7 8 9 |
# File 'lib/briar/email.rb', line 6 def email_testable? return true if ios5? uia_available? end |
#email_to ⇒ Object
51 52 53 |
# File 'lib/briar/email.rb', line 51 def email_to query("view:'_MFMailRecipientTextField'", :text).first end |
#email_to_contains?(address) ⇒ Boolean
63 64 65 66 |
# File 'lib/briar/email.rb', line 63 def email_to_contains? (address) addrs = tokenize_list(email_to) addrs.include? address end |
#email_to_field_is?(text) ⇒ Boolean
55 56 57 58 59 60 61 |
# File 'lib/briar/email.rb', line 55 def email_to_field_is? (text) if ios5? email_to.eql? text else warn 'WARN: iOS > 5 detected - cannot test for email to field' end end |
#is_ios5_mail_view ⇒ Object
80 81 82 |
# File 'lib/briar/email.rb', line 80 def is_ios5_mail_view query("layoutContainerView descendant view:'MFMailComposeView'").count == 1 end |
#should_see_mail_view(opts = {:timeout => BRIAR_WAIT_TIMEOUT, :email_view_mark => 'compose email'}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/briar/email.rb', line 84 def should_see_mail_view (opts = {:timeout => BRIAR_WAIT_TIMEOUT, :email_view_mark => 'compose email'}) default_opts = {:timeout => BRIAR_WAIT_TIMEOUT, :email_view_mark => 'compose email'} merged = default_opts.merge(opts) if email_not_testable? warn_about_no_ios5_email_view return end timeout = merged[:timeout] msg = "waited for '#{timeout}' seconds but did not see email compose view" #noinspection RubyParenthesesAfterMethodCallInspection email_view_mark = merged[:email_view_mark] wait_for(:timeout => timeout, :retry_frequency => BRIAR_WAIT_RETRY_FREQ, :post_timeout => BRIAR_WAIT_STEP_PAUSE, :timeout_message => msg) do if ios5? is_ios5_mail_view else view_exists? email_view_mark end end end |
#should_see_recipients(addresses) ⇒ Object
TODO:
replace sleep with a wait_*
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/briar/email.rb', line 69 def should_see_recipients (addresses) should_see_mail_view sleep(0.4) addrs = addresses.split(/, ?/) addrs.each do |expected| unless email_to_contains? expected.strip screenshot_and_raise "expected to see '#{expected}' in the email 'to' field but found '#{email_to}'" end end end |
#uia_send_email_to(addresses, opts = {}) ⇒ Object
214 215 216 217 218 219 |
# File 'lib/briar/email.rb', line 214 def uia_send_email_to(addresses, opts={}) default_opts = {:wait_for_keyboard => true} opts = default_opts.merge(opts) uia_set_email_to addresses, opts uia_touch_send_email end |
#uia_set_email_to(addresses, opts = {}) ⇒ Object
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/briar/email.rb', line 199 def uia_set_email_to(addresses, opts={}) default_opts = {:wait_for_keyboard => true} opts = default_opts.merge(opts) uia_touch_email_to opts addresses.each do |addr| uia_type_string addr uia_enter step_pause end end |
#uia_touch_email_to(opts = {}) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/briar/email.rb', line 185 def uia_touch_email_to (opts={}) default_opts = {:wait_for_keyboard => true} opts = default_opts.merge(opts) if uia_not_available? screenshot_and_raise 'UIA needs to be available' end # with predicate # uia_tap(:textField, {[:label, :beginswith] => "'To:'"}) uia_tap(:textField, {:marked => 'toField'}) uia_wait_for_keyboard if opts[:wait_for_keyboard] end |
#uia_touch_send_email ⇒ Object
210 211 212 |
# File 'lib/briar/email.rb', line 210 def uia_touch_send_email uia_tap_mark('Send') end |
#warn_about_no_ios5_email_view ⇒ Object
15 16 17 |
# File 'lib/briar/email.rb', line 15 def warn_about_no_ios5_email_view warn 'WARN: iOS > 5 detected - cannot test for email views on iOS simulator or devices unless we use UIAutomation' end |