SurfCustomCalabash 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: aa6393311248346a1bfdbb65386455b6299b01b5
4
- data.tar.gz: 49d689215e69269719e47378f7298449d1b03070
2
+ SHA256:
3
+ metadata.gz: 2584314c724fb94ff419dd4513cf5ff7aff9cfa1aa096e57ee788b2f2f8eb14f
4
+ data.tar.gz: ba9ac40807f121a1dfab4e34b646528cc970c097cb1d32dcb08907231e88f1c7
5
5
  SHA512:
6
- metadata.gz: fb9273680f9bf8ea1b0aa4fdc0884d40d29dd39cfdf437044b0f46e2c4bfc55c053fa505f86e2704030e311aa131fed91a0e25ee3ed2df2a612cec097f4aacb0
7
- data.tar.gz: cb8d7e6e95c75051f0d19d4bec14c3dc7284f4b76be85351d6b2c905c60f696b8bd7be0604005baa49ef58c185f5b9b932799c5bbc502b73bfe94709e38c3c6f
6
+ metadata.gz: 19a77b8a812760dfc779faf6580e315014ba9628919b6912744d63baab971bd6880edbd56a4c4d0466d57093b302bb2c49dcb42ecb7872e51607d55a6ec22495
7
+ data.tar.gz: b1e7895eade91dc479e2afffda0feabc4fb3cc639183e0f40e885827eac7a345f15e58f6a8ba1257fd7762019cc1d2c284516311bb8fb4578abb65b69a61cd78
@@ -6,7 +6,7 @@ require "SurfCustomCalabash/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "SurfCustomCalabash"
8
8
  spec.version = SurfCustomCalabash::VERSION
9
- spec.authors = ["Alexey Hripunov"]
9
+ spec.authors = ["Alexey Hripunov", "Igor Tolubaev"]
10
10
  spec.email = ["hripunov@surfstudio.ru"]
11
11
 
12
12
  spec.summary = "Custom methods for calabash ios and android"
@@ -1,271 +1,365 @@
1
1
  require 'rspec/expectations'
2
2
 
3
- module CommonMethods
4
-
3
+ def enter_text_from_keyboard(text, timeout_duration: 5)
4
+ wait_for_keyboard(timeout: timeout_duration)
5
+ keyboard_enter_text(text)
6
+ end
5
7
 
6
- def enter_text(text)
7
- wait_for_keyboard(:timeout=>5)
8
- keyboard_enter_text(text)
9
- end
8
+ # ----------------------------------------------Custom Taps-----------------------------------------------------------
9
+ # wait element and tap
10
+ def tap_on(element, timeout_duration: 15, sleep_duration: 0.5)
11
+ wait_element(element, timeout_duration: timeout_duration, sleep_duration: sleep_duration)
12
+ touch(element)
13
+ end
10
14
 
11
- # ----------------------------------------------Custom Taps-----------------------------------------------------------
12
- # wait element and tap
13
- def tap_on(element)
14
- wait_for_elements_exist(element, :timeout=>15, :retry_frequency=>5)
15
- sleep(0.5)
16
- touch(element)
17
- end
15
+ def tap_on_text(text, timeout_duration: 15, sleep_duration: 0.5)
16
+ tap_on("* {text CONTAINS'#{text}'}", timeout_duration: timeout_duration, sleep_duration: sleep_duration)
17
+ end
18
18
 
19
- def tap_on_text(text)
20
- tap_on("* {text CONTAINS'#{text}'}")
19
+ # if element exists - tap, if not - swipe until element exists and tap
20
+ def tap_or_swipe(element, timeout_duration: 30, sleep_duration: 0.5)
21
+ if element_does_not_exist(element)
22
+ light_swipe_until_exists('down', element, timeout_duration: timeout_duration)
21
23
  end
24
+ tap_on(element, sleep_duration: sleep_duration)
25
+ end
22
26
 
23
- # if element exists - tap, if not - swipe until element exists and tap
24
- def tap_or_swipe(element)
25
- if element_exists(element)
26
- sleep(1)
27
- touch(element)
28
- else
29
- until_element_exists(element,:action => lambda{light_swipe('down')}, :timeout => 30)
30
- touch(element)
31
- end
32
- end
27
+ # ----------------------------------------------------Custom Waits----------------------------------------------------
28
+ def wait_element(element, timeout_duration: 15, sleep_duration: 0, retry_frequency: 0.3)
29
+ wait_for_element_exists(element, timeout: timeout_duration, retry_frequency: retry_frequency)
30
+ sleep(sleep_duration)
31
+ end
33
32
 
34
- # ----------------------------------------------------Custom Waits----------------------------------------------------
35
- def wait_element(element)
36
- wait_for_element_exists(element, :timeout=>15)
37
- end
33
+ def wait_no_element(element, timeout_duration: 15, sleep_duration: 0, retry_frequency: 0.3)
34
+ wait_for_element_does_not_exist(element, timeout: timeout_duration, retry_frequency: retry_frequency)
35
+ sleep(sleep_duration)
36
+ end
38
37
 
39
- def wait_no_element(element)
40
- wait_for_element_does_not_exist(element, :timeout=>15)
41
- end
38
+ # wait trait-element on screen
39
+ def wait_for_screen(timeout_duration: 30, sleep_duration: 0, retry_frequency: 0.3)
40
+ wait_element(trait, sleep_duration: sleep_duration, timeout_duration: timeout_duration, retry_frequency: retry_frequency)
41
+ end
42
42
 
43
- # wait trait-element on screen
44
- def wait_for_screen
45
- wait_for_elements_exist(trait, :timeout=>25)
43
+ # ----------------------------------------------------Custom Swipe----------------------------------------------------
44
+ def strong_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
45
+ Timeout::timeout(timeout_duration) do
46
+ while element_exists(element_destination) do
47
+ strong_swipe(dir, sleep_duration: sleep_duration)
48
+ end
46
49
  end
50
+ end
47
51
 
48
- # ----------------------------------------------------Custom Swipe----------------------------------------------------
49
- def strong_swipe_until_not_exist(dir, element_destination)
50
- until_element_does_not_exist(element_destination,
51
- :action => lambda{strong_swipe(dir)})
52
+ def normal_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
53
+ Timeout::timeout(timeout_duration) do
54
+ while element_exists(element_destination) do
55
+ normal_swipe(dir, sleep_duration: sleep_duration)
56
+ end
52
57
  end
58
+ end
53
59
 
54
- def normal_swipe_until_not_exist(dir, element_destination)
55
- until_element_does_not_exist(element_destination,
56
- :action => lambda{normal_swipe(dir)})
60
+ def light_swipe_until_not_exist(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
61
+ Timeout::timeout(timeout_duration) do
62
+ while element_exists(element_destination) do
63
+ light_swipe(dir, sleep_duration: sleep_duration)
64
+ end
57
65
  end
66
+ end
58
67
 
59
- def light_swipe_until_not_exist(dir, element_destination)
60
- until_element_does_not_exist(element_destination,
61
- :action => lambda{light_swipe( dir)})
68
+ def strong_swipe_until_exists(dir, element_destination, sleep_duration: 0.5, timeout_duration: 30)
69
+ Timeout::timeout(timeout_duration) do
70
+ while element_does_not_exist(element_destination) do
71
+ strong_swipe(dir, sleep_duration: sleep_duration)
72
+ end
62
73
  end
74
+ end
63
75
 
64
- def strong_swipe_until_exists(dir, element_destination)
65
- until_element_exists(element_destination,
66
- :action => lambda{strong_swipe( dir)})
76
+ def normal_swipe_until_exists(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
77
+ Timeout::timeout(timeout_duration) do
78
+ while element_does_not_exist(element_destination) do
79
+ normal_swipe(dir, sleep_duration: sleep_duration)
80
+ end
67
81
  end
82
+ end
68
83
 
69
- def normal_swipe_until_exists(dir, element_destination)
70
- until_element_exists(element_destination,
71
- :action => lambda{normal_swipe( dir); sleep(2)}, :timeout=>40)
84
+ def light_swipe_until_exists(dir, element_destination, sleep_duration: 0.2, timeout_duration: 30)
85
+ Timeout::timeout(timeout_duration) do
86
+ while element_does_not_exist(element_destination) do
87
+ light_swipe(dir, sleep_duration: sleep_duration)
88
+ end
72
89
  end
90
+ end
73
91
 
74
- def light_swipe_until_exists(dir, element_destination)
75
- until_element_exists(element_destination,
76
- :action => lambda{light_swipe( dir); sleep(2)}, :timeout=>60)
77
-
92
+ def strong_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.5, timeout_duration: 30)
93
+ Timeout::timeout(timeout_duration) do
94
+ while element_does_not_exist(element_destination) do
95
+ strong_swipe_element(element, dir, sleep_duration: sleep_duration)
96
+ end
78
97
  end
98
+ end
79
99
 
80
- def strong_swipe_element_until_exists(dir, element, element_destination)
81
- until_element_exists(element_destination,
82
- :action => lambda{strong_swipe_element(element, dir)})
100
+ def normal_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
101
+ Timeout::timeout(timeout_duration) do
102
+ while element_does_not_exist(element_destination) do
103
+ normal_swipe_element(element, dir, sleep_duration: sleep_duration)
104
+ end
83
105
  end
106
+ end
84
107
 
85
- def light_swipe_element_until_exists(dir, element, element_destination)
86
- until_element_exists(element_destination,
87
- :action => lambda{light_swipe_element(element, dir)}, :timeout=>70)
108
+ def light_swipe_element_until_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
109
+ Timeout::timeout(timeout_duration) do
110
+ while element_does_not_exist(element_destination) do
111
+ light_swipe_element(element, dir, sleep_duration: sleep_duration)
112
+ end
88
113
  end
114
+ end
89
115
 
90
- def strong_swipe_element_until_not_exists(dir, element, element_destination)
91
- until_element_does_not_exist(element_destination,
92
- :action => lambda{pan(element, dir)})
116
+ def strong_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.5, timeout_duration: 30)
117
+ Timeout::timeout(timeout_duration) do
118
+ while element_exists(element_destination) do
119
+ strong_swipe_element(element, dir, sleep_duration: sleep_duration)
120
+ end
93
121
  end
122
+ end
94
123
 
95
- def light_swipe_element_until_not_exists(dir, element, element_destination)
96
- until_element_does_not_exist(element_destination,
97
- :action => lambda{light_swipe_element(element, dir)}, :timeout=>70)
124
+ def normal_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
125
+ Timeout::timeout(timeout_duration) do
126
+ while element_exists(element_destination) do
127
+ normal_swipe_element(element, dir, sleep_duration: sleep_duration)
128
+ end
98
129
  end
130
+ end
99
131
 
100
- def swipe_to_text(dir, text)
101
- sleep(1)
102
- if dir == 'вверх'
103
- until_element_exists("* {text CONTAINS'#{text}'}", :action => lambda{light_swipe('up'); sleep(1)}, :timeout => 60)
104
- elsif dir == 'вниз'
105
- until_element_exists("* {text CONTAINS'#{text}'}", :action => lambda{light_swipe('down'); sleep(1.5)}, :timeout => 60)
132
+ def light_swipe_element_until_not_exists(dir, element, element_destination, sleep_duration: 0.2, timeout_duration: 30)
133
+ Timeout::timeout(timeout_duration) do
134
+ while element_exists(element_destination) do
135
+ light_swipe_element(element, dir, sleep_duration: sleep_duration)
106
136
  end
107
137
  end
138
+ end
108
139
 
109
- # Drag element from one place to place of other element
110
- def drag_element(element_from , element_to)
111
- x_from = get_coordinate_x(element_from)
112
- y_from = get_coordinate_y(element_from)
140
+ def swipe_to_text(dir, text, sleep_duration:0.2, timeout_duration: 30)
141
+ light_swipe_until_exists(dir, "* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
142
+ end
113
143
 
114
- x_to = get_coordinate_x(element_to)
115
- y_to = get_coordinate_y(element_to)
116
- drag_coordinates(x_from, y_from, x_to, y_to, 10, 0.5, 0.5)
144
+ # -------------------------------------------------Asserts------------------------------------------------------------
145
+ def assert_eql_with_rescue(element1, element2)
146
+ begin
147
+ expect(element1).to eq(element2)
148
+ true
149
+ rescue RSpec::Expectations::ExpectationNotMetError
150
+ false
117
151
  end
152
+ end
118
153
 
119
- # -------------------------------------------------Asserts------------------------------------------------------------
120
- def assert_eql_with_rescue(element1, element2)
121
- begin
122
- expect(element1).to eq(element2)
123
- true
124
- rescue Exception => e
125
- false
126
- end
127
- end
154
+ def assert_eql(element1, element2)
155
+ expect(element1).to eq(element2)
156
+ end
128
157
 
129
- def assert_eql(element1, element2)
130
- expect(element1).to eq(element2)
131
- end
158
+ def assert_not_eql(element1, element2)
159
+ expect(element1).not_to eql(element2)
160
+ end
132
161
 
133
- def assert_not_eql(element1, element2)
134
- expect(element1).not_to eql(element2)
135
- end
162
+ def assert_true(element)
163
+ expect(element).to be true
164
+ end
136
165
 
137
- def assert_true(element)
138
- expect(element).to be true
139
- end
166
+ def assert_false(element)
167
+ expect(element).to be false
168
+ end
140
169
 
141
- def assert_false(element)
142
- expect(element).to be false
143
- end
170
+ def assert_nil(element)
171
+ expect(element).to be_nil
172
+ end
144
173
 
145
- def assert_nil(element)
146
- expect(element).to be_nil
147
- end
174
+ # ------------------------------------------Generate String-----------------------------------------------------------
175
+ def get_random_num_string(length)
176
+ source = (0..9).to_a
177
+ key = ""
178
+ length.times{ key += source[rand(source.size)].to_s }
179
+ return key
180
+ end
148
181
 
149
- # ------------------------------------------Generate String-----------------------------------------------------------
150
- def get_random_num_string(length)
151
- source=(0..9).to_a
152
- key=""
153
- length.times{ key += source[rand(source.size)].to_s }
154
- return key
155
- end
182
+ def get_random_text_string(length)
183
+ source = ("a".."z").to_a
184
+ key = ""
185
+ length.times{ key += source[rand(source.size)].to_s }
186
+ return key
187
+ end
156
188
 
157
- def get_random_text_string(length)
158
- source=("a".."z").to_a
159
- key=""
160
- length.times{ key += source[rand(source.size)].to_s }
161
- return key
162
- end
189
+ def get_random_email
190
+ return get_random_text_string(7) + "@" + get_random_text_string(2) + ".test"
191
+ end
163
192
 
164
- def get_random_email
165
- return get_random_text_string(7) + "@" + get_random_text_string(2) + ".test"
166
- end
193
+ # get first digital from string
194
+ def extract_num_from_str(text)
195
+ text.gsub!(/[[:space:]]/, '')
196
+ num = text.scan(/\d+/).first.nil? ? "0" : text.scan(/\d+/).first
197
+ p num
198
+ end
167
199
 
168
- # get first digital from string
169
- def extract_num_from_str(text)
170
- text.gsub!(/[[:space:]]/, '')
171
- num = text.scan(/\d+/).first.nil? ? "0" : text.scan(/\d+/).first
172
- p num
173
- end
200
+ # get last digital from string
201
+ def extract_last_num_from_str(text)
202
+ text.gsub!(/[[:space:]]/, '')
203
+ num = text.scan(/\d+/).first.nil? ? "0" : text.scan(/\d+/).last
204
+ p num
205
+ end
174
206
 
175
- # get text from first element
176
- def remember(element)
177
- wait_for_element_exists(element, :timeout => 5)
178
- sleep(1.5)
179
- name = query(element)
180
- save_name = name.first['text']
181
- puts(save_name)
182
- return save_name
183
- end
207
+ # get text from first element
208
+ def remember(element, sleep_duration: 1, timeout_duration: 5)
209
+ wait_element(element, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
210
+ name = query(element)
211
+ save_name = name.first['text']
212
+ puts(save_name)
213
+ return save_name
214
+ end
184
215
 
185
- # get text from last element
186
- def remember_last_text(element)
187
- wait_for_element_exists(element, :timeout => 5)
188
- sleep(1.5)
189
- name = query(element)
190
- save_name = name.last['text']
191
- puts(save_name)
192
- return save_name
193
- end
216
+ # get text from last element
217
+ def remember_last_text(element, sleep_duration: 1, timeout_duration: 5)
218
+ wait_element(element, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
219
+ name = query(element)
220
+ save_name = name.last['text']
221
+ puts(save_name)
222
+ return save_name
223
+ end
194
224
 
195
- # wait text
196
- def check_text(text)
197
- wait_for_element_exists("* {text CONTAINS'#{text}'}", :timeout => 5, :retry_frequency => 2)
198
- end
225
+ # wait text
226
+ def check_text(text, sleep_duration: 0, timeout_duration: 5)
227
+ wait_element("* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
228
+ end
199
229
 
200
- def no_check_text(text)
201
- wait_for_element_does_not_exist("* {text CONTAINS'#{text}'}", :timeout => 5, :retry_frequency => 5)
202
- end
230
+ def no_check_text(text, timeout_duration: 5)
231
+ warn "Deprecated with 0.1.9 version SurfCustomCalabash, use check_no_text intead"
232
+ check_no_text(text, timeout_duration: timeout_duration)
233
+ end
203
234
 
204
- # get element's coordinates
205
- def get_coordinate_x(element)
206
- el = query(element)
207
- coordinate = el[0]['rect']['center_x']
208
- # puts(coordinate)
209
- return coordinate.to_i
210
- end
235
+ def check_no_text(text, sleep_duration: 0, timeout_duration: 5)
236
+ wait_no_element("* {text CONTAINS'#{text}'}", sleep_duration: sleep_duration, timeout_duration: timeout_duration)
237
+ end
211
238
 
212
- def get_coordinate_y(element)
213
- el = query(element)
214
- coordinate = el[0]['rect']['center_y']
215
- # puts(coordinate)
216
- return coordinate.to_i
217
- end
239
+ # get element's coordinates
240
+ def get_coordinate_x(element)
241
+ el = query(element)
242
+ coordinate = el[0]['rect']['center_x']
243
+ return coordinate.to_i
244
+ end
245
+
246
+ def get_coordinate_y(element)
247
+ el = query(element)
248
+ coordinate = el[0]['rect']['center_y']
249
+ return coordinate.to_i
250
+ end
218
251
 
252
+ # Drag element from one place to place of other element
253
+ def drag_element(element_from , element_to)
254
+ x_from = get_coordinate_x(element_from)
255
+ y_from = get_coordinate_y(element_from)
219
256
 
220
- # if elements cross - return true, if not - false
221
- def cross_coordinate(element_front, element_behind)
222
- cross = false
257
+ x_to = get_coordinate_x(element_to)
258
+ y_to = get_coordinate_y(element_to)
259
+ drag_coordinates(x_from, y_from, x_to, y_to, 10, 0.5, 0.5)
260
+ end
261
+
262
+ # if elements cross - return true, if not - false
263
+ def cross_coordinate(element_front, element_behind, delta: 100)
264
+ cross = false
223
265
 
224
- if element_exists(element_front) && element_exists(element_behind)
225
- coordinate_front = get_coordinate_y(element_front)
226
- coordinate_behind = get_coordinate_y(element_behind)
227
- delta = 100
266
+ if element_exists(element_front) && element_exists(element_behind)
267
+ coordinate_front = get_coordinate_y(element_front)
268
+ coordinate_behind = get_coordinate_y(element_behind)
228
269
 
229
- if coordinate_front < coordinate_behind + delta
230
- cross = true
231
- else
232
- cross = false
233
- end
270
+ if coordinate_front < coordinate_behind + delta
271
+ cross = true
272
+ else
273
+ cross = false
234
274
  end
235
- # puts(cross)
236
- return cross
237
275
  end
276
+ # puts(cross)
277
+ return cross
278
+ end
238
279
 
239
- # swipe down if two element cross
240
- def swipe_if_cross(element_front, element_behind)
241
- if cross_coordinate(element_front, element_behind)
242
- light_swipe("down")
280
+ # swipe down if two element cross
281
+ def swipe_if_cross(element_front, element_behind, timeout_duration: 30, sleep_duration: 1)
282
+ Timeout::timeout(timeout_duration) do
283
+ while cross_coordinate(element_front, element_behind) do
284
+ light_swipe("down", sleep_duration: sleep_duration)
243
285
  end
244
- sleep(1)
245
286
  end
287
+ end
246
288
 
247
- # if apps support two localization, this method check exists text in different locations
248
- def text_with_locale(text_locale1, text_locale2)
249
- if element_exists("* {text BEGINSWITH '#{text_locale2}'}")
250
- puts (element_exists("* {text BEGINSWITH '#{text_locale2}'}"))
251
- return "* {text BEGINSWITH '#{text_locale2}'}"
252
- elsif element_exists("* {text BEGINSWITH '#{text_locale1}'}")
253
- puts(element_exists("* {text BEGINSWITH '#{text_locale1}'}"))
254
- return "* {text BEGINSWITH '#{text_locale1}'}"
289
+ # --------------------------------------------------Localization------------------------------------------------------
290
+ # get locale apps - Ru or Eng
291
+ # parameter - element with text
292
+ def get_app_location(element, sleep_duration: 1)
293
+ sleep(sleep_duration)
294
+ if element_exists(element)
295
+ text_element = remember(element)
296
+ if check_cyrillic(text_element)
297
+ locale = 'RUS'
255
298
  else
256
- return ("No such query!")
299
+ locale = 'ENG'
257
300
  end
301
+ else
302
+ p "Fail localization"
303
+ locale = ''
258
304
  end
305
+ p locale
306
+ return locale
307
+ end
308
+
309
+ # check cyrillic symbols in string
310
+ def check_cyrillic(str)
311
+ regexp = /\p{Cyrillic}+.*?\.?/
312
+ if str.match(regexp).nil?
313
+ return false
314
+ else
315
+ return true
316
+ end
317
+ end
318
+
319
+ # if apps support two localization, this method check exists text in different locations
320
+ def text_with_locale(text_locale1, text_locale2, sleep_duration: 1)
321
+ sleep(sleep_duration)
322
+
323
+ # $locale is global variables
324
+ # $locale setup in first app launch
325
+ if !$locale.nil?
326
+ if check_cyrillic(text_locale1)
327
+ rus_locale = "* {text CONTAINS '#{text_locale1}'}"
328
+ eng_locale = "* {text CONTAINS '#{text_locale2}'}"
329
+ elsif check_cyrillic(text_locale2)
330
+ rus_locale = "* {text CONTAINS '#{text_locale2}'}"
331
+ eng_locale = "* {text CONTAINS '#{text_locale1}'}"
332
+ end
259
333
 
260
- # if apps support two localization, this method check exists label in different locations
261
- def label_with_locale(mark1, mark2)
262
- if element_exists("* marked:'#{mark1}'")
263
- return "* marked:'#{mark1}'"
264
- elsif element_exists("* marked:'#{mark2}'")
265
- return "* marked:'#{mark2}'"
334
+ if $locale == "RUS"
335
+ return rus_locale
336
+ elsif $locale == "ENG"
337
+ return eng_locale
338
+ end
339
+ else
340
+ # if $locale is not Rus or Eng
341
+ # wait element on screen with text_locale1 or text_locale2
342
+ locale_el1 = "* {text CONTAINS '#{text_locale1}'}"
343
+ locale_el2 = "* {text CONTAINS '#{text_locale2}'}"
344
+
345
+ if element_exists(locale_el1)
346
+ return locale_el1
347
+ elsif element_exists(locale_el2)
348
+ return locale_el2
266
349
  else
267
- return false
350
+ return ("No such query!")
268
351
  end
269
352
  end
353
+ end
270
354
 
355
+ # if apps support two localization, this method check exists label in different locations
356
+ def label_with_locale(mark1, mark2)
357
+ if element_exists("* marked:'#{mark1}'")
358
+ return "* marked:'#{mark1}'"
359
+ elsif element_exists("* marked:'#{mark2}'")
360
+ return "* marked:'#{mark2}'"
361
+ else
362
+ return false
363
+ end
271
364
  end
365
+
@@ -1,90 +1,123 @@
1
1
  require 'calabash-android'
2
2
  require 'SurfCustomCalabash/CommonMethods'
3
3
 
4
- module DroidMethods
5
- include Calabash::Android::Operations
6
- include CommonMethods
7
-
8
- def close_keyboard
9
- if keyboard_visible?
10
- hide_soft_keyboard
11
- end
4
+ def close_keyboard
5
+ if keyboard_visible?
6
+ hide_soft_keyboard
12
7
  end
8
+ end
13
9
 
14
- #----------------------------------------------Custom Android Swipe---------------------------------------------------
15
- def strong_swipe(dr)
16
- if dr == "up"
17
- perform_action('drag', 50, 50, 15, 75, 4)
18
- elsif dr == "down"
19
- perform_action('drag', 50, 50, 60, 5, 1)
20
- elsif dr == "left"
21
- perform_action('drag', 90, 0, 50, 50, 10)
22
- elsif dr == "right"
23
- perform_action('drag', 0, 90, 50, 50, 10)
24
- end
25
- end
10
+ def submit_keyboard
11
+ press_user_action_button
12
+ end
26
13
 
27
- def normal_swipe(dr)
28
- if dr == "up"
29
- perform_action('drag', 50, 50, 45, 80, 10)
30
- elsif dr == "down"
31
- perform_action('drag', 50, 50, 80, 45, 10)
32
- end
14
+ #----------------------------------------------Custom Android Swipe---------------------------------------------------
15
+ def strong_swipe(dr, sleep_duration: 0)
16
+ if dr == "up"
17
+ perform_action('drag', 50, 50, 15, 75, 25)
18
+ elsif dr == "down"
19
+ perform_action('drag', 50, 50, 75, 15, 25)
20
+ elsif dr == "left"
21
+ perform_action('drag', 90, 0, 50, 50, 10)
22
+ elsif dr == "right"
23
+ perform_action('drag', 0, 90, 50, 50, 10)
24
+ else
25
+ p "Use direction 'up', 'down', 'left', 'right'"
33
26
  end
27
+ sleep(sleep_duration)
28
+ end
34
29
 
35
- def light_swipe(dr)
36
- if dr == "down"
37
- perform_action('drag', 50, 50, 80, 70, 10)
38
- elsif dr == "up"
39
- perform_action('drag', 50, 50, 70, 80, 5)
40
- end
30
+ def normal_swipe(dr, sleep_duration: 0)
31
+ if dr == "up"
32
+ perform_action('drag', 50, 50, 15, 45, 25)
33
+ elsif dr == "down"
34
+ perform_action('drag', 50, 50, 45, 15, 25)
35
+ elsif dr == "left"
36
+ perform_action('drag', 50, 0, 50, 50, 10)
37
+ elsif dr == "right"
38
+ perform_action('drag', 0, 50, 50, 50, 10)
39
+ else
40
+ p "Use direction 'up', 'down', 'left', 'right'"
41
41
  end
42
+ sleep(sleep_duration)
43
+ end
42
44
 
43
- def strong_swipe_element(element, dir)
44
- if dir == 'left'
45
- flick(element, :left)
46
- elsif dir == 'right'
47
- flick(element, :right)
48
- elsif dir == 'down'
49
- flick(element, :up)
50
- elsif dir == 'up'
51
- flick(element, :down)
52
- end
45
+ def light_swipe(dr, sleep_duration: 0)
46
+ if dr == "up"
47
+ perform_action('drag', 50, 50, 15, 30, 25)
48
+ elsif dr == "down"
49
+ perform_action('drag', 50, 50, 30, 15, 25)
50
+ elsif dr == "left"
51
+ perform_action('drag', 25, 0, 50, 50, 10)
52
+ elsif dr == "right"
53
+ perform_action('drag', 0, 25, 50, 50, 10)
54
+ else
55
+ p "Use direction 'up', 'down', 'left', 'right'"
53
56
  end
57
+ sleep(sleep_duration)
58
+ end
54
59
 
55
- def normal_swipe_element(element, dir)
56
- if dir == 'left'
57
- pan(element, :left)
58
- elsif dir == 'right'
59
- pan(element, :right)
60
- elsif dir == 'down'
61
- pan(element, :up)
62
- elsif dir == 'up'
63
- pan(element, :down)
64
- end
60
+ def strong_swipe_element(element, dir, sleep_duration: 0)
61
+ if dir == 'left'
62
+ flick(element, :left)
63
+ elsif dir == 'right'
64
+ flick(element, :right)
65
+ elsif dir == 'down'
66
+ flick(element, :up)
67
+ elsif dir == 'up'
68
+ flick(element, :down)
69
+ else
70
+ p "Use direction 'up', 'down', 'left', 'right'"
65
71
  end
72
+ sleep(sleep_duration)
73
+ end
66
74
 
67
- def light_swipe_element(element, dir)
68
- if dir == 'left'
69
- pan(element, :left)
70
- elsif dir == 'right'
71
- pan(element, :right)
72
- elsif dir == 'down'
73
- pan(element, :up)
74
- elsif dir == 'up'
75
- pan(element, :down)
76
- end
75
+ def normal_swipe_element(element, dir, sleep_duration: 0)
76
+ if dir == 'left'
77
+ pan(element, :left)
78
+ elsif dir == 'right'
79
+ pan(element, :right)
80
+ elsif dir == 'down'
81
+ pan(element, :up)
82
+ elsif dir == 'up'
83
+ pan(element, :down)
84
+ else
85
+ p "Use direction 'up', 'down', 'left', 'right'"
77
86
  end
87
+ sleep(sleep_duration)
88
+ end
78
89
 
79
- # swipe trait-element from element_destination
80
- def light_swipe_trait_until_exists(dir, element_destination)
81
- until_element_exists(element_destination,
82
- :action => lambda{light_swipe_element(trait, dir)}, :timeout=>50)
90
+ def light_swipe_element(element, dir, sleep_duration: 0)
91
+ if dir == 'left'
92
+ pan(element, :left)
93
+ elsif dir == 'right'
94
+ pan(element, :right)
95
+ elsif dir == 'down'
96
+ pan(element, :up)
97
+ elsif dir == 'up'
98
+ pan(element, :down)
99
+ else
100
+ p "Use direction 'up', 'down', 'left', 'right'"
83
101
  end
102
+ sleep(sleep_duration)
103
+ end
84
104
 
85
- # pull-to-refresh screen
86
- def ptr
87
- perform_action('drag', 50, 50, 15, 75, 4)
88
- end
105
+ # swipe trait-element from element_destination
106
+ def light_swipe_trait_until_exists(dir, element_destination, sleep_duration: 0, timeout_duration: 30)
107
+ light_swipe_element_until_exists(dir, trait, element_destination, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
108
+ end
109
+
110
+ # pull-to-refresh screen
111
+ def ptr
112
+ perform_action('drag', 50, 50, 15, 75, 4)
113
+ end
114
+
115
+ # strong swipe to up of the screen
116
+ def swipe_to_up
117
+ 5.times {perform_action('drag', 50, 50, 15, 70, 1)}
118
+ end
89
119
 
120
+ # strong swipe to down of the screen
121
+ def swipe_to_down
122
+ 5.times {perform_action('drag', 50, 50, 60, 10, 1)}
90
123
  end
@@ -1,89 +1,134 @@
1
1
  require 'calabash-cucumber/ibase'
2
2
  require 'SurfCustomCalabash/CommonMethods'
3
3
 
4
- module IosMethods
5
- include CommonMethods
6
-
7
- #----------------------------------------------Custom Swipe iOS-------------------------------------------------------
8
- def strong_swipe(dir)
9
- if dir == 'left'
10
- swipe :left, force: :strong
11
- elsif dir == 'right'
12
- swipe :right, force: :strong
13
- elsif dir == 'up'
14
- swipe :down, force: :strong
15
- elsif dir == 'down'
16
- swipe :up, force: :strong
17
- end
4
+ # close keyboard with a swipe of the screen
5
+ def close_keyboard
6
+ if keyboard_visible?
7
+ pan_coordinates({x: 100, y: 150}, {x: 100, y: 250})
18
8
  end
9
+ end
19
10
 
20
- def normal_swipe(dir)
21
- if dir == 'left'
22
- swipe :left, force: :normal
23
- elsif dir == 'right'
24
- swipe :right, force: :normal
25
- elsif dir == 'up'
26
- swipe :down, force: :normal
27
- elsif dir == 'down'
28
- swipe :up, force: :normal
11
+ # tap on Done on keyboard
12
+ def submit_keyboard
13
+ if keyboard_visible?
14
+ if element_exists("* marked:'Toolbar Done Button'")
15
+ touch("* marked:'Toolbar Done Button'")
16
+ else
17
+ tap_keyboard_action_key
29
18
  end
30
19
  end
20
+ end
31
21
 
32
- def light_swipe(dir)
33
- if dir == 'left'
34
- swipe :left, force: :light
35
- elsif dir == 'right'
36
- swipe :right, force: :light
37
- elsif dir == 'up'
38
- swipe :down, force: :light
39
- elsif dir == 'down'
40
- swipe :up, force: :light
41
- end
22
+ #----------------------------------------------Custom Swipe iOS-------------------------------------------------------
23
+ def strong_swipe(dir, sleep_duration: 0)
24
+ if dir == 'left'
25
+ swipe :left, force: :strong
26
+ elsif dir == 'right'
27
+ swipe :right, force: :strong
28
+ elsif dir == 'up'
29
+ swipe :down, force: :strong
30
+ elsif dir == 'down'
31
+ swipe :up, force: :strong
32
+ else
33
+ p "Use direction 'up', 'down', 'left', 'right'"
42
34
  end
35
+ sleep(sleep_duration)
36
+ end
43
37
 
44
- def strong_swipe_element(element, dir)
45
- if dir == 'left'
46
- swipe :left, :query => element, force: :strong
47
- elsif dir == 'right'
48
- swipe :right, :query => element, force: :strong
49
- elsif dir == 'up'
50
- swipe :down, :query => element, force: :strong
51
- elsif dir == 'down'
52
- swipe :up, :query => element, force: :strong
53
- end
38
+ def normal_swipe(dir, sleep_duration: 0)
39
+ if dir == 'left'
40
+ swipe :left, force: :normal
41
+ elsif dir == 'right'
42
+ swipe :right, force: :normal
43
+ elsif dir == 'up'
44
+ swipe :down, force: :normal
45
+ elsif dir == 'down'
46
+ swipe :up, force: :normal
47
+ else
48
+ p "Use direction 'up', 'down', 'left', 'right'"
54
49
  end
50
+ sleep(sleep_duration)
51
+ end
55
52
 
56
- def normal_swipe_element(element, dir)
57
- if dir == 'left'
58
- swipe :left, :query => element, force: :normal
59
- elsif dir == 'right'
60
- swipe :right, :query => element, force: :normal
61
- elsif dir == 'up'
62
- swipe :down, :query => element, force: :normal
63
- elsif dir == 'down'
64
- swipe :up, :query => element, force: :normal
65
- end
53
+ def light_swipe(dir, sleep_duration: 0)
54
+ if dir == 'left'
55
+ swipe :left, force: :light
56
+ elsif dir == 'right'
57
+ swipe :right, force: :light
58
+ elsif dir == 'up'
59
+ swipe :down, force: :light
60
+ elsif dir == 'down'
61
+ swipe :up, force: :light
62
+ else
63
+ p "Use direction 'up', 'down', 'left', 'right'"
66
64
  end
65
+ sleep(sleep_duration)
66
+ end
67
67
 
68
- def light_swipe_element(element, dir)
69
- if dir == 'left'
70
- swipe :left, :query => element, force: :light
71
- elsif dir == 'right'
72
- swipe :right, :query => element, force: :light
73
- elsif dir == 'up'
74
- swipe :down, :query => element, force: :light
75
- elsif dir == 'down'
76
- swipe :up, :query => element, force: :light
77
- end
68
+ def strong_swipe_element(element, dir, sleep_duration: 0)
69
+ if dir == 'left'
70
+ swipe :left, :query => element, force: :strong
71
+ elsif dir == 'right'
72
+ swipe :right, :query => element, force: :strong
73
+ elsif dir == 'up'
74
+ swipe :down, :query => element, force: :strong
75
+ elsif dir == 'down'
76
+ swipe :up, :query => element, force: :strong
77
+ else
78
+ p "Use direction 'up', 'down', 'left', 'right'"
78
79
  end
80
+ sleep(sleep_duration)
81
+ end
79
82
 
80
- def light_swipe_trait_until_exists(dir, element_destination)
81
- normal_swipe_until_exists(dir, element_destination)
83
+ def normal_swipe_element(element, dir, sleep_duration: 0)
84
+ if dir == 'left'
85
+ swipe :left, :query => element, force: :normal
86
+ elsif dir == 'right'
87
+ swipe :right, :query => element, force: :normal
88
+ elsif dir == 'up'
89
+ swipe :down, :query => element, force: :normal
90
+ elsif dir == 'down'
91
+ swipe :up, :query => element, force: :normal
92
+ else
93
+ p "Use direction 'up', 'down', 'left', 'right'"
82
94
  end
95
+ sleep(sleep_duration)
96
+ end
83
97
 
84
- # pull-to-refresh screen
85
- def ptr
86
- swipe(:down, :offset => {:x => 0, :y => -200})
98
+ def light_swipe_element(element, dir, sleep_duration: 0)
99
+ if dir == 'left'
100
+ swipe :left, :query => element, force: :light
101
+ elsif dir == 'right'
102
+ swipe :right, :query => element, force: :light
103
+ elsif dir == 'up'
104
+ swipe :down, :query => element, force: :light
105
+ elsif dir == 'down'
106
+ swipe :up, :query => element, force: :light
107
+ else
108
+ p "Use direction 'up', 'down', 'left', 'right'"
87
109
  end
110
+ sleep(sleep_duration)
111
+ end
112
+
113
+ def light_swipe_trait_until_exists(dir, element_destination, sleep_duration: 0, timeout_duration: 30)
114
+ normal_swipe_until_exists(dir, element_destination, sleep_duration: sleep_duration, timeout_duration: timeout_duration)
115
+ end
116
+
117
+ # pull-to-refresh screen
118
+ def ptr
119
+ pan_coordinates({x: 50, y: 100}, {x: 50, y: 600})
120
+ end
121
+
122
+ # touch on status bar -> scroll to up of the screen
123
+ def swipe_to_up
124
+ touch(nil, :offset => {:x => 0, :y => 0})
125
+ end
126
+
127
+ # strong swipe to down of the screen
128
+ def swipe_to_down
129
+ 10.times {swipe :up, force: :strong}
130
+ end
88
131
 
132
+ def back_swipe
133
+ pan_coordinates({x:0, y:300}, {x:500, y:300})
89
134
  end
@@ -1,3 +1,3 @@
1
1
  module SurfCustomCalabash
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SurfCustomCalabash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Hripunov
8
- autorequire:
8
+ - Igor Tolubaev
9
+ autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
12
+ date: 2020-07-29 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -81,7 +82,7 @@ metadata:
81
82
  homepage_uri: https://github.com/alexeyhripunov/SurfCustomCalabash
82
83
  source_code_uri: https://github.com/alexeyhripunov/SurfCustomCalabash
83
84
  changelog_uri: https://github.com/alexeyhripunov/SurfCustomCalabash
84
- post_install_message:
85
+ post_install_message:
85
86
  rdoc_options: []
86
87
  require_paths:
87
88
  - lib
@@ -96,9 +97,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
98
99
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.5.2.1
101
- signing_key:
100
+ rubyforge_project:
101
+ rubygems_version: 2.7.6
102
+ signing_key:
102
103
  specification_version: 4
103
104
  summary: Custom methods for calabash ios and android
104
105
  test_files: []