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