briar 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,8 +23,13 @@ module Briar
23
23
  end
24
24
 
25
25
  def should_see_navbar_back_button
26
- unless navbar_has_back_button?
27
- screenshot_and_raise 'there is no navigation bar back button'
26
+ timeout = BRIAR_WAIT_TIMEOUT * 2.0
27
+ msg = "waited for '#{timeout}' seconds but did not see navbar back button"
28
+ wait_for(:timeout => timeout,
29
+ :retry_frequency => 0.2,
30
+ :post_timeout => 0.1,
31
+ :timeout_message => msg) do
32
+ navbar_has_back_button?
28
33
  end
29
34
  end
30
35
 
@@ -41,17 +46,43 @@ module Briar
41
46
  titles.index(name)
42
47
  end
43
48
 
44
- def should_see_navbar_button (name)
45
- idx = index_of_navbar_button name
46
- if idx.nil?
47
- screenshot_and_raise "there should be a navbar button named '#{name}'"
49
+ def should_see_navbar_button (name, is_ui_button=false)
50
+ if is_ui_button
51
+ qstr = "button marked:'#{name}' parent navigationBar"
52
+ timeout = BRIAR_WAIT_TIMEOUT
53
+ msg = "waited for '#{timeout}' seconds but did not see '#{name}' in navigation bar"
54
+ wait_for(:timeout => timeout,
55
+ :retry_frequency => 0.2,
56
+ :post_timeout => 0.1,
57
+ :timeout_message => msg) do
58
+ element_exists qstr
59
+ end
60
+ else
61
+ idx = index_of_navbar_button name
62
+ if idx.nil?
63
+ # check to see if it is a ui button
64
+ should_see_navbar_button(name, true)
65
+ end
48
66
  end
49
67
  end
50
68
 
51
- def should_not_see_navbar_button (name)
52
- idx = index_of_navbar_button name
53
- unless idx.nil?
54
- screenshot_and_raise "i should not see a navbar button named #{name}"
69
+
70
+ def should_not_see_navbar_button (name, is_ui_button=false)
71
+ if is_ui_button
72
+ qstr = "button marked:'#{name}' parent navigationBar"
73
+ timeout = 1.0
74
+ msg = "waited for '#{timeout}' seconds but i still see '#{name}' in navigation bar"
75
+ wait_for(:timeout => timeout,
76
+ :retry_frequency => 0.2,
77
+ :post_timeout => 0.1,
78
+ :timeout_message => msg) do
79
+ element_does_not_exist qstr
80
+ end
81
+ else
82
+ idx = index_of_navbar_button name
83
+ unless idx.nil?
84
+ screenshot_and_raise "i should not see a navbar button named #{name}"
85
+ end
55
86
  end
56
87
  end
57
88
 
@@ -82,8 +113,8 @@ module Briar
82
113
 
83
114
  touch_transition('navigationItemButtonView first',
84
115
  "view marked:'#{view}'",
85
- {:timeout=>TOUCH_TRANSITION_TIMEOUT,
86
- :retry_frequency=>TOUCH_TRANSITION_RETRY_FREQ})
116
+ {:timeout => TOUCH_TRANSITION_TIMEOUT,
117
+ :retry_frequency => TOUCH_TRANSITION_RETRY_FREQ})
87
118
  step_pause
88
119
  end
89
120
 
@@ -113,15 +144,20 @@ module Briar
113
144
  touch_navbar_item item_name, view_id
114
145
  end
115
146
 
116
-
117
147
  def navbar_has_title? (title)
118
- sleep(0.2)
119
- query('navigationItemView', AL).include?(title)
120
- end
121
-
122
- def should_see_navbar_with_title(title)
123
- unless navbar_has_title? title
124
- screenshot_and_raise "after waiting, i did not see navbar with title #{title}"
148
+ all_items = query("navigationItemView marked:'#{title}'")
149
+ button_items = query('navigationItemButtonView')
150
+ non_button_items = all_items.delete_if { |item| button_items.include?(item) }
151
+ !non_button_items.empty?
152
+ end
153
+
154
+ def should_see_navbar_with_title(title, timeout=BRIAR_WAIT_TIMEOUT)
155
+ msg = "waited for '#{timeout}' seconds but i did not see #{title} in navbar"
156
+ wait_for(:timeout => timeout,
157
+ :retry_frequency => 0.2,
158
+ :post_timeout => 0.1,
159
+ :timeout_message => msg) do
160
+ navbar_has_title? title
125
161
  end
126
162
  end
127
163
 
@@ -1,6 +1,5 @@
1
1
  require 'calabash-cucumber'
2
2
 
3
-
4
3
  module Briar
5
4
  module Core
6
5
 
@@ -12,6 +11,13 @@ module Briar
12
11
  sleep(ANIMATION_PAUSE)
13
12
  end
14
13
 
14
+ def uia_not_available
15
+ env('NO_LAUNCH') == '1'
16
+ end
17
+
18
+ def uia_available
19
+ not uia_not_available
20
+ end
15
21
 
16
22
  def view_exists? (view_id)
17
23
  !query("view marked:'#{view_id}'").empty?
@@ -33,6 +39,31 @@ module Briar
33
39
  element_exists("view text:'#{text}'")
34
40
  end
35
41
 
42
+ def should_see_view_with_frame(view_id, frame)
43
+ res = query("view marked:'#{view_id}'").first
44
+ if res.empty?
45
+ screenshot_and_raise "should see view with id '#{view_id}'"
46
+ end
47
+ actual = res['frame']
48
+ ['x', 'y', 'width', 'height'].each { |key|
49
+ avalue = actual[key]
50
+ evalue = frame[key]
51
+ screenshot_and_raise "#{view_id} should have '#{key}' '#{evalue}' but found '#{avalue}'"
52
+ }
53
+ end
54
+
55
+ def should_see_view_with_center(view_id, center_ht)
56
+ res = query("view marked:'#{view_id}'").first
57
+ if res.nil?
58
+ screenshot_and_raise "should see view with id '#{view_id}'"
59
+ end
60
+
61
+ actual_ht = {x: res['rect']['center_x'], y: res['rect']['center_y']}
62
+
63
+ unless actual_ht == center_ht
64
+ screenshot_and_raise "#{view_id} has center '#{actual_ht}' but should have center '#{center_ht}'"
65
+ end
66
+ end
36
67
 
37
68
  def should_see_view_after_animation (view_id)
38
69
  pending "WARN: deprecated 0.0.8 - use 'wait_for_view #{view_id}' instead"
@@ -51,25 +82,59 @@ module Briar
51
82
  end
52
83
 
53
84
  def touch_view_named(view_id)
85
+ wait_for_view view_id
54
86
  touch("view marked:'#{view_id}'")
55
87
  end
56
88
 
57
- def touch_and_wait_for_view(view_id, view_to_wait_for, timeout=1.0)
89
+ def touch_and_wait_for_view(view_id, view_to_wait_for, timeout=BRIAR_WAIT_TIMEOUT)
58
90
  touch_view_named(view_id)
59
91
  wait_for_view(view_to_wait_for, timeout)
60
92
  end
61
93
 
62
- def wait_for_view (view_id, timeout=1.0)
94
+ def wait_for_view (view_id, timeout=BRIAR_WAIT_TIMEOUT)
63
95
  msg = "waited for '#{timeout}' seconds but did not see '#{view_id}'"
64
96
  wait_for(:timeout => timeout,
65
97
  :retry_frequency => 0.2,
66
98
  :post_timeout => 0.1,
67
- :timeout_message => msg ) do
99
+ :timeout_message => msg) do
68
100
  view_exists? view_id
69
101
  end
70
102
  end
71
103
 
72
- def wait_for_views(views, timeout=1.0)
104
+ def wait_for_query(qstr, timeout=BRIAR_WAIT_TIMEOUT)
105
+ msg = "waited for '#{timeout}' seconds but did not see\n '#{qstr}'"
106
+ wait_for(:timeout => timeout,
107
+ :retry_frequency => 0.2,
108
+ :post_timeout => 0.1,
109
+ :timeout_message => msg) do
110
+ !query(qstr).empty?
111
+ end
112
+ end
113
+
114
+ def wait_for_custom_view (view_class, view_id, timeout=BRIAR_WAIT_TIMEOUT)
115
+ msg = "waited for '#{timeout}' seconds but did not see '#{view_id}'"
116
+ wait_for(:timeout => timeout,
117
+ :retry_frequency => 0.2,
118
+ :post_timeout => 0.1,
119
+ :timeout_message => msg) do
120
+ !query("view:'#{view_class}' marked:'#{view_id}'").empty?
121
+ end
122
+ end
123
+
124
+ def touch_custom_view(view_class, view_id, timeout=BRIAR_WAIT_TIMEOUT)
125
+ wait_for_custom_view view_class, view_id, timeout
126
+ touch("view:'#{view_class}' marked:'#{view_id}'")
127
+ end
128
+
129
+
130
+ def touch_custom_view_and_wait_for_view(view_class, view_id, view_to_wait_for, timeout=BRIAR_WAIT_TIMEOUT)
131
+ wait_for_custom_view view_class, view_id, timeout
132
+ touch("view:'#{view_class}' marked:'#{view_id}'")
133
+ wait_for_view view_to_wait_for, timeout
134
+ end
135
+
136
+
137
+ def wait_for_views(views, timeout=BRIAR_WAIT_TIMEOUT)
73
138
  msg = "waited for '#{timeout}' seconds but did not see '#{views}'"
74
139
  options = {:timeout => timeout,
75
140
  :retry_frequency => 0.2,
@@ -80,7 +145,7 @@ module Briar
80
145
  end
81
146
  end
82
147
 
83
- def wait_for_view_to_disappear(view_id, timeout=1.0)
148
+ def wait_for_view_to_disappear(view_id, timeout=BRIAR_WAIT_TIMEOUT)
84
149
  msg = "waited for '#{timeout}' seconds for '#{view_id}' to disappear but it is still visible"
85
150
  options = {:timeout => timeout,
86
151
  :retry_frequency => 0.2,
@@ -91,12 +156,12 @@ module Briar
91
156
  end
92
157
  end
93
158
 
94
-
95
- def touch_and_wait_to_disappear(view_id, timeout=1.0)
159
+ def touch_and_wait_to_disappear(view_id, timeout=BRIAR_WAIT_TIMEOUT)
96
160
  touch_view_named(view_id)
97
161
  wait_for_view_to_disappear view_id, timeout
98
162
  end
99
-
163
+
164
+
100
165
  # backdoor helpers
101
166
  # canonical backdoor command: 'calabash_backdoor_handle_command'
102
167
  # selector key = :selector
@@ -111,6 +176,12 @@ module Briar
111
176
  json = "{\":selector\" : \"#{command}\", \":args\" : #{array}}"
112
177
  backdoor('calabash_backdoor_handle_command:', json)
113
178
  end
179
+
180
+ def tokenize_list (list)
181
+ tokens = list.split(/[,]|(and )/)
182
+ stripped = tokens.map { |elm| elm.strip }
183
+ stripped.delete_if { |elm| ['and', 'or', ''].include?(elm) }
184
+ end
114
185
  end
115
186
  end
116
187
 
@@ -4,8 +4,8 @@ module Briar
4
4
  module Control
5
5
  module Button
6
6
  include Briar::Core
7
- def button_exists? (name)
8
- res = query("button marked:'#{name}'", :alpha)
7
+ def button_exists? (button_id)
8
+ res = query("button marked:'#{button_id}'", :alpha)
9
9
  if res.empty?
10
10
  false
11
11
  else
@@ -13,10 +13,8 @@ module Briar
13
13
  end
14
14
  end
15
15
 
16
- def should_see_button (name)
17
- unless button_exists? name
18
- screenshot_and_raise "i did not see a button with marked #{name}"
19
- end
16
+ def should_see_button (button_id)
17
+ wait_for_button button_id
20
18
  end
21
19
 
22
20
  def should_not_see_button (button_id)
@@ -30,31 +28,30 @@ module Briar
30
28
 
31
29
  def should_see_button_with_title(name, title)
32
30
  should_see_button name
33
- if query("button marked:'#{title}' child label", :text).empty?
34
- screenshot_and_raise "i do not see a button marked #{name} with title #{title}"
31
+ if query("button marked:'#{name}' child label", :text).empty?
32
+ screenshot_and_raise "i do not see a button marked '#{name}' with title '#{title}'"
35
33
  end
36
34
  end
37
35
 
38
- def touch_button (name)
39
- should_see_button name
40
- touch("button marked:'#{name}'")
41
- step_pause
36
+ def touch_button (button_id)
37
+ should_see_button button_id
38
+ touch("button marked:'#{button_id}'")
42
39
  end
43
40
 
44
41
  def touch_button_and_wait_for_view (button_id, view_id)
45
- touch_transition("button marked:'#{button_id}'",
46
- "view marked:'#{view_id}'",
47
- {:timeout=>TOUCH_TRANSITION_TIMEOUT,
48
- :retry_frequency=>TOUCH_TRANSITION_RETRY_FREQ})
42
+ touch_button(button_id)
43
+ unless view_id.nil?
44
+ wait_for_view view_id
45
+ end
49
46
  end
50
47
 
51
- def touch_button_and_wait_for_view_to_disappear (button_id, view_id, timeout=1.0)
48
+ def touch_button_and_wait_for_view_to_disappear (button_id, view_id, timeout=BRIAR_WAIT_TIMEOUT)
52
49
  touch_button button_id
53
50
  wait_for_view_to_disappear view_id, timeout
54
51
  end
55
52
 
56
53
 
57
- def wait_for_button (button_id, timeout=1.0)
54
+ def wait_for_button (button_id, timeout=BRIAR_WAIT_TIMEOUT)
58
55
  msg = "waited for '#{timeout}' seconds but did not see button '#{button_id}'"
59
56
  wait_for(:timeout => timeout,
60
57
  :retry_frequency => 0.2,
@@ -64,7 +61,7 @@ module Briar
64
61
  end
65
62
  end
66
63
 
67
- def wait_for_button_with_title (button_id, title, timeout=1.0)
64
+ def wait_for_button_with_title (button_id, title, timeout=BRIAR_WAIT_TIMEOUT)
68
65
  msg = "waited for '#{timeout}' seconds but did not see button '#{button_id}' with title '#{title}'"
69
66
  wait_for(:timeout => timeout,
70
67
  :retry_frequency => 0.2,
data/lib/briar/email.rb CHANGED
@@ -3,8 +3,17 @@ require 'calabash-cucumber'
3
3
  module Briar
4
4
  module Email
5
5
 
6
- def warn_about_ios6_email_view
7
- warn 'WARN: iOS6 detected - cannot test for email views on iOS simulator or devices'
6
+ def email_testable?
7
+ return true if device.ios5?
8
+ uia_available?
9
+ end
10
+
11
+ def email_not_testable?
12
+ not email_testable?()
13
+ end
14
+
15
+ def warn_about_no_ios5_email_view
16
+ warn 'WARN: iOS > 5 detected - cannot test for email views on iOS simulator or devices unless we use UIAutomation'
8
17
  end
9
18
 
10
19
  def email_body
@@ -12,10 +21,10 @@ module Briar
12
21
  end
13
22
 
14
23
  def email_body_contains? (text)
15
- if device.ios6?
16
- warn 'WARN: iOS6 detected - cannot test for email body text https://groups.google.com/d/topic/calabash-ios/Ff3XFsjp-B0/discussion'
17
- else
24
+ if device.ios5?
18
25
  !query("view:'MFComposeTextContentView' {text LIKE '*#{text}*'}").empty?
26
+ else
27
+ warn 'WARN: iOS > 5 detected - cannot test for email body text'
19
28
  end
20
29
  end
21
30
 
@@ -24,18 +33,18 @@ module Briar
24
33
  end
25
34
 
26
35
  def email_subject_is? (text)
27
- if device.ios6?
28
- warn 'WARN: iOS6 detected - cannot test for email subject text https://groups.google.com/d/topic/calabash-ios/Ff3XFsjp-B0/discussion'
29
- else
36
+ if device.ios5?
30
37
  email_subject.eql? text
38
+ else
39
+ warn 'WARN: iOS > 5 detected - cannot test for email subject text'
31
40
  end
32
41
  end
33
42
 
34
43
  def email_subject_has_text_like? (text)
35
- if device.ios6?
36
- warn 'WARN: iOS6 detected - cannot test for email subject text https://groups.google.com/d/topic/calabash-ios/Ff3XFsjp-B0/discussion'
37
- else
44
+ if device.ios5?
38
45
  !query("view:'MFComposeSubjectView' {text LIKE '*#{text}*'}").empty?
46
+ else
47
+ warn 'WARN: iOS > 5 detected - cannot test for email subject text'
39
48
  end
40
49
  end
41
50
 
@@ -44,10 +53,10 @@ module Briar
44
53
  end
45
54
 
46
55
  def email_to_field_is? (text)
47
- if device.ios6?
48
- warn 'WARN: iOS6 detected - cannot test for email to field https://groups.google.com/d/topic/calabash-ios/Ff3XFsjp-B0/discussion'
49
- else
56
+ if device.ios5?
50
57
  email_to.eql? text
58
+ else
59
+ warn 'WARN: iOS > 5 detected - cannot test for email to field'
51
60
  end
52
61
  end
53
62
 
@@ -72,40 +81,89 @@ module Briar
72
81
  end
73
82
 
74
83
  def is_ios6_mail_view
75
- device.ios6?
84
+ warn 'WARN: deprected 0.0.9'
76
85
  end
77
86
 
78
- def should_see_mail_view (timeout=1.0)
79
- if device.ios6?
80
- screenshot_and_raise 'iOS6 detected - cannot test for email viewhttps://groups.google.com/d/topic/calabash-ios/Ff3XFsjp-B0/discussion'
87
+ def should_see_mail_view (timeout=BRIAR_WAIT_TIMEOUT)
88
+ if email_not_testable?
89
+ warn_about_no_ios5_email_view
90
+ return
81
91
  end
82
92
 
83
93
  msg = "waited for '#{timeout}' seconds but did not see email compose view"
94
+ dev = device()
84
95
  wait_for(:timeout => timeout,
85
96
  :retry_frequency => 0.2,
86
97
  :post_timeout => 0.1,
87
- :timeout_message => msg ) do
88
- is_ios5_mail_view
98
+ :timeout_message => msg) do
99
+ if dev.ios5?
100
+ is_ios5_mail_view
101
+ else
102
+ view_exists? 'compose email'
103
+ end
89
104
  end
90
105
  end
91
106
 
107
+ #noinspection RubyResolve
92
108
  def device_can_send_email
93
109
  return true if device.simulator?
94
- backdoor('calabash_backdoor_configured_for_mail:', 'ignorable').eql? 'YES'
110
+ if defined? backdoor_device_configured_for_mail?
111
+ backdoor_device_configured_for_mail?
112
+ else
113
+ pending 'you will need to create a backdoor method to check if the device can send an email'
114
+ end
95
115
  end
96
116
 
97
117
  def delete_draft_and_wait_for (view_id)
98
- if device.ios6?
99
- warn_about_ios6_email_view
118
+ if email_not_testable?
119
+ warn_about_no_ios5_email_view
120
+ return
121
+ end
122
+
123
+ # does a wait for iOS > 5 + uia available
124
+ should_see_mail_view
125
+
126
+ device = device()
127
+
128
+ if device.ios5?
129
+ touch_navbar_item_and_wait_for_view 'Cancel', 'Delete Draft'
130
+ step_pause
131
+ touch_sheet_button_and_wait_for_view 'Delete Draft', view_id
100
132
  else
101
- should_see_mail_view
102
- touch_navbar_item 'Cancel'
103
- wait_for_animation
104
- touch_transition("button marked:'Delete Draft'",
105
- "view marked:'#{view_id}'",
106
- {:timeout=>TOUCH_TRANSITION_TIMEOUT,
107
- :retry_frequency=>TOUCH_TRANSITION_RETRY_FREQ})
133
+ sbo = status_bar_orientation.to_sym
134
+
135
+ if sbo.eql?(:left) or sbo.eql?(:right)
136
+ pending "iOS > 5 detected AND orientation '#{sbo}' - there is a bug in UIAutomation that prohibits touching the cancel button"
137
+ end
138
+
139
+ # might also occur on devices, but i don't know
140
+ if sbo.eql?(:up) and device.ipad? and device.simulator?
141
+ pending "iOS > 5 detected AND orientation '#{sbo}' AND simulator - there is a bug in UIAutomation prohibits touching the cancel button"
142
+ end
143
+
144
+ timeout = BRIAR_WAIT_TIMEOUT * 2
145
+ msg = "waited for '#{timeout}' seconds but did not see cancel button"
146
+ wait_for(:timeout => timeout,
147
+ :retry_frequency => 1.1,
148
+ :post_timeout => 0.1,
149
+ :timeout_message => msg) do
150
+ uia_element_exists?(:view, marked: 'Cancel')
151
+ end
152
+
153
+ uia_tap_mark('Cancel')
154
+ msg = "waited for '#{timeout}' seconds but did not see dismiss email action sheet"
155
+ wait_for(:timeout => timeout,
156
+ :retry_frequency => 1.1,
157
+ :post_timeout => 0.1,
158
+ :timeout_message => msg) do
159
+ uia_element_exists?(:view, marked: 'Delete Draft')
160
+ end
161
+
162
+ uia_tap_mark('Delete Draft')
163
+
164
+ wait_for_view_to_disappear 'compose email'
108
165
  end
166
+ step_pause
109
167
  end
110
168
  end
111
169
  end