meglish 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/meglish.rb +230 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a33e98ec5019f3c7430792697ceda3afd26cbdc1
|
4
|
+
data.tar.gz: edf7559f926cc0e479ca8625fbd209b3cafdd4f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6cd92291f4f0d8e84f5a04b9d43b5aff3ebba53edc57bd20a3c8d7dd4c4b08a6251e6a3e3a847711d71beff8698919210eb1261d10d211f33838f65abc5cbf09
|
7
|
+
data.tar.gz: 76f718217235fa55086c95773dd39244f80c3cd380e6f2d3442c09694987cd820fdc463b28a80ae1ef7de7ac8dd52755d525a2ca37b5c57ceca055074598bcf8
|
data/lib/meglish.rb
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
module MeglishCommands
|
2
|
+
|
3
|
+
def clear_text_element(_query, _options = {})
|
4
|
+
find_element_on_screen(_query, _options)
|
5
|
+
touch(_query.strip)
|
6
|
+
clear_text
|
7
|
+
end
|
8
|
+
|
9
|
+
def element_enabled?(_query, _options = {})
|
10
|
+
element = find_elements(_query, _options)
|
11
|
+
find_element_on_screen(_query, _options)
|
12
|
+
find_elements(_query, _options).first['enabled'] unless element.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def element_visible?(_query, _options = {})
|
16
|
+
element = find_elements(_query, _options)
|
17
|
+
find_element_on_screen(_query, _options) unless element.nil?
|
18
|
+
find_elements(_query, _options).first['visible'] unless element.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_coordinate_element(_query, _options = {})
|
22
|
+
find_element_on_screen(_query, _options)
|
23
|
+
find_coordinate(_query, _options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_element_on_screen(_query, _options = {})
|
27
|
+
_query = include_all(_query, _options)
|
28
|
+
logging(_query, 'NORMAL')
|
29
|
+
timeout = _options[:timeout].nil? ? 20 : _options[:timeout].to_i
|
30
|
+
wait_for_element_exists(_query, timeout: timeout)
|
31
|
+
sleep 0.5
|
32
|
+
scroll_to_element(_query, _options) if _options[:scroll_to_element].nil? || _options[:scroll_to_element]
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_elements(_query, _options = {})
|
36
|
+
query(include_all(_query, _options))
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_device_size
|
40
|
+
size = `adb shell dumpsys input | grep 'deviceSize' | awk '{ print $10 , $11 }'`
|
41
|
+
size = size[0..size.length - 3]
|
42
|
+
w, h = size.split(', ')
|
43
|
+
w = w.to_i
|
44
|
+
h = h.to_i
|
45
|
+
[w, h]
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_element(_query, _options = {})
|
49
|
+
find_element_on_screen(_query, _options)
|
50
|
+
query(include_all(_query, _options)).first
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_element_by_index(_query, _index, _options = {})
|
54
|
+
new_query = _query + ' index:' + _index
|
55
|
+
find_element_on_screen(_query, _options)
|
56
|
+
query(new_query).first
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_elements(_query, _options = {})
|
60
|
+
query(_query)
|
61
|
+
rescue
|
62
|
+
return []
|
63
|
+
end
|
64
|
+
|
65
|
+
def keyboard_enter_text_element(text, _options = {})
|
66
|
+
wait_for_keyboard
|
67
|
+
keyboard_enter_text text
|
68
|
+
hide_soft_keyboard
|
69
|
+
end
|
70
|
+
|
71
|
+
def long_press_element(_query, _options = {})
|
72
|
+
start_monkey
|
73
|
+
find_element_on_screen(_query, _options)
|
74
|
+
x, y = find_coordinate(_query, _options)
|
75
|
+
monkey_touch(:down, x, y)
|
76
|
+
kill_existing_monkey_processes
|
77
|
+
end
|
78
|
+
|
79
|
+
def long_press_release_element(_query, _options = {})
|
80
|
+
start_monkey
|
81
|
+
find_element_on_screen(_query, _options)
|
82
|
+
x, y = find_coordinate(_query, _options)
|
83
|
+
monkey_touch(:up, x, y)
|
84
|
+
kill_existing_monkey_processes
|
85
|
+
end
|
86
|
+
|
87
|
+
def long_press_and_touch_element(_query, _touch_element_query, _options = {})
|
88
|
+
long_press_element(_query, _options)
|
89
|
+
touch_element(_touch_element_query, _options)
|
90
|
+
end
|
91
|
+
|
92
|
+
def scroll_to_element(_query, _to_top_first = false, _options = {})
|
93
|
+
hide_soft_keyboard
|
94
|
+
unless (query(_query).first['rect']['height']).zero? && (query(_query).first['rect']['width']).zero?
|
95
|
+
w, h = get_device_size
|
96
|
+
x, y = find_coordinate(include_all(_query, _options))
|
97
|
+
|
98
|
+
scroll_until_find_element(_query, h, y, w, x)
|
99
|
+
swipe_until_find_element(_query, w, x, h, y)
|
100
|
+
end
|
101
|
+
rescue
|
102
|
+
logging('Scroll to element was ignored')
|
103
|
+
query(_query)
|
104
|
+
end
|
105
|
+
|
106
|
+
def scroll_to_top
|
107
|
+
perform_action('drag', 50, 50, 50, 1500, 1)
|
108
|
+
end
|
109
|
+
|
110
|
+
def select_spinner_item_element(_spinner_query, _text, _options = {})
|
111
|
+
touch_element(_spinner_query, _options)
|
112
|
+
touch_element("DropDownListView child CustomFontTextView text:'#{_text}'", _options)
|
113
|
+
end
|
114
|
+
|
115
|
+
def swipe_left(_query)
|
116
|
+
has_element = query(_query + ' parent HorizontalScrollView')
|
117
|
+
_query = has_element.empty? ? _query : _query + ' parent HorizontalScrollView'
|
118
|
+
pan_left(query_string: _query)
|
119
|
+
end
|
120
|
+
|
121
|
+
def swipe_right(_query)
|
122
|
+
has_element = query(_query + ' parent HorizontalScrollView')
|
123
|
+
_query = has_element.empty? ? _query : _query + ' parent HorizontalScrollView'
|
124
|
+
pan_right(query_string: _query)
|
125
|
+
end
|
126
|
+
|
127
|
+
def text_element(_query, _options = {})
|
128
|
+
get_element(_query, _options)['text']
|
129
|
+
end
|
130
|
+
|
131
|
+
def text_spinner_element(_query, _options = {})
|
132
|
+
_query += ' child CustomFontTextView'
|
133
|
+
get_element(_query, _options)['text']
|
134
|
+
end
|
135
|
+
|
136
|
+
def touch_element(_query, _options = {})
|
137
|
+
find_element_on_screen(_query, _options)
|
138
|
+
touch(_query.strip)
|
139
|
+
end
|
140
|
+
|
141
|
+
def touch_element_by_text_position(_query, _text, _options = {})
|
142
|
+
text_el = get_element(_query, _options)['text']
|
143
|
+
text_index = text_el.index(_text) + (_text.length / 2)
|
144
|
+
line_for_offset = query(_query, :getLayout, getLineForOffset: text_index)[0]
|
145
|
+
vertical = query(_query, :getLayout, getLineBaseline: line_for_offset)[0].to_i
|
146
|
+
horizontal = query(_query, :getLayout, getPrimaryHorizontal: text_index)[0].to_i
|
147
|
+
touch(_query, x: 0, y: 0, offset: { x: horizontal, y: vertical })
|
148
|
+
end
|
149
|
+
|
150
|
+
def touch_and_keyboard_text_element(_query, _text, _options = {})
|
151
|
+
find_element_on_screen(_query, _options)
|
152
|
+
touch(_query.strip)
|
153
|
+
clear_text if _options[:clear_text].nil? || _options[:clear_text] == true
|
154
|
+
keyboard_enter_text(_text)
|
155
|
+
hide_soft_keyboard
|
156
|
+
end
|
157
|
+
|
158
|
+
def wait_for_or_ignore(_query, _timeout = 3, _options = {})
|
159
|
+
_timeout *= 2
|
160
|
+
found = false
|
161
|
+
while _timeout > 0 && found == false
|
162
|
+
if find_elements(_query, _options).empty?
|
163
|
+
_timeout -= 1
|
164
|
+
sleep 0.5
|
165
|
+
else
|
166
|
+
found = true
|
167
|
+
end
|
168
|
+
end
|
169
|
+
found
|
170
|
+
end
|
171
|
+
|
172
|
+
def wait_for_text_element(_query, _timeout = 10, options = {})
|
173
|
+
count = 0
|
174
|
+
filled = ''
|
175
|
+
while (filled.nil? || filled.empty?)
|
176
|
+
return if count >= _timeout
|
177
|
+
filled = text_element(_query, options)
|
178
|
+
sleep 1
|
179
|
+
count += 1
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def wait_keyboard_visible?(_timeout = 3)
|
184
|
+
visible = 'false'
|
185
|
+
_timeout *= 2
|
186
|
+
while _timeout > 0 && visible == 'false'
|
187
|
+
field, visible = `adb shell dumpsys input_method | grep mInputShown | awk '{ print $4 }'`.split('=')
|
188
|
+
if visible == 'false'
|
189
|
+
_timeout -= 1
|
190
|
+
sleep 0.5
|
191
|
+
end
|
192
|
+
end
|
193
|
+
visible == 'true' ? true : false
|
194
|
+
end
|
195
|
+
|
196
|
+
private
|
197
|
+
|
198
|
+
def include_all(_query, _options = {})
|
199
|
+
include_all = true
|
200
|
+
unless _options.empty?
|
201
|
+
include_all = _options[:include_all].nil? ? true : _options[:include_all]
|
202
|
+
end
|
203
|
+
_query = 'all ' + _query if _query.include?('all ') == false && include_all == true
|
204
|
+
_query
|
205
|
+
end
|
206
|
+
|
207
|
+
def scroll_until_find_element(_query, _height, _coord_y, _width, _coord_x)
|
208
|
+
count_times = 0
|
209
|
+
if (_coord_y > _height / 2) && (_coord_x < _width)
|
210
|
+
scroll_down until query(_query).first['visible'] || (count_times += 1) >= 10
|
211
|
+
else
|
212
|
+
scroll_up until query(_query).first['visible'] || (count_times += 1) >= 10
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def swipe_element(_query, _options = {})
|
217
|
+
w, h = get_device_size
|
218
|
+
x, y = find_coordinate(include_all(_query, _options))
|
219
|
+
[w, h, x, y]
|
220
|
+
end
|
221
|
+
|
222
|
+
def swipe_until_find_element(_query, _width, _coord_x, _height, _coord_y)
|
223
|
+
count_times = 0
|
224
|
+
if (_coord_x > _width) && (_coord_y > _height)
|
225
|
+
swipe_left(_query) until query(_query).first['visible'] || (count_times += 1) >= 5
|
226
|
+
else
|
227
|
+
swipe_left(_query) until query(_query).first['visible'] || (count_times += 1) >= 5
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meglish
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eduardo Gomes Heinen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ''
|
14
|
+
email: eduardogheinen@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/meglish.rb
|
20
|
+
homepage: http://rubygems.org/gems/meglish
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Meglish a super framework to Calabash Android
|
44
|
+
test_files: []
|