appom 1.1.6 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/appom/element_container.rb +3 -47
- data/lib/appom/element_finder.rb +51 -20
- data/lib/appom/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35d79b86da3958d465691aa8f67adff728310412cfe8f898ec1f00b16efc0102
|
4
|
+
data.tar.gz: 3bea92052029e696b96c86bdacbdddaeaca1972fced1bb0e27592d0d13e1ca46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dfdae46709e5bc0657ae10c92010e2979ad8285673545b662fb04402b0dae1fa4a360b4755b05e5da303a66b9796e66be6b2cf113df4af05241b32cb8f2915c
|
7
|
+
data.tar.gz: d49e352631b8cd97fb50b5ba7bd5e712eb63cb23e01cdefb1125802382f79b200c590a042c5a511da794bd2b191ce010c27257a9207322c79ad93cafe2c1a578
|
@@ -42,20 +42,13 @@ module Appom
|
|
42
42
|
# Element doesn't support block so that will raise if pass a block when declare
|
43
43
|
#
|
44
44
|
def element(name, *find_args)
|
45
|
-
|
46
|
-
|
47
|
-
build_element(name, *args) do
|
45
|
+
build_element(name, *find_args) do
|
48
46
|
define_method(name) do |*runtime_args, &block|
|
49
47
|
raise_if_block(self, name, !block.nil?, :element)
|
50
|
-
|
51
|
-
_find(*merge_args(args, runtime_args))
|
52
|
-
else
|
53
|
-
find_element_has_text(text, *merge_args(args, runtime_args))
|
54
|
-
end
|
48
|
+
_find(*merge_args(find_args, runtime_args))
|
55
49
|
end
|
56
50
|
|
57
|
-
create_get_element_params(name,
|
58
|
-
define_get_element_text(name, text)
|
51
|
+
create_get_element_params(name, find_args)
|
59
52
|
end
|
60
53
|
end
|
61
54
|
|
@@ -274,43 +267,6 @@ module Appom
|
|
274
267
|
end
|
275
268
|
end
|
276
269
|
|
277
|
-
##
|
278
|
-
# Get text is passed when declared element
|
279
|
-
#
|
280
|
-
def define_get_element_text(element_name, text)
|
281
|
-
method_name = "#{element_name}_text"
|
282
|
-
define_method(method_name) do
|
283
|
-
text
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
##
|
288
|
-
# Deduce args and other parameters
|
289
|
-
# @return args for appium and other parameters
|
290
|
-
#
|
291
|
-
def deduce_element_args(args)
|
292
|
-
# Flatten argument array first if we are in case array inside array
|
293
|
-
args = args.flatten
|
294
|
-
|
295
|
-
if args.empty?
|
296
|
-
raise(ArgumentError, 'You should provide search arguments in element creation')
|
297
|
-
end
|
298
|
-
|
299
|
-
# Get last key and check if it contain 'text' key
|
300
|
-
text = nil
|
301
|
-
|
302
|
-
args.each do |arg|
|
303
|
-
if arg.is_a?(Hash)
|
304
|
-
# Extract text value
|
305
|
-
if arg.key?(:text)
|
306
|
-
text = arg[:text]
|
307
|
-
args.delete(arg)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|
311
|
-
[args, text]
|
312
|
-
end
|
313
|
-
|
314
270
|
##
|
315
271
|
# Extract section options
|
316
272
|
# @return section class name and the remaining parameters
|
data/lib/appom/element_finder.rb
CHANGED
@@ -2,16 +2,32 @@ module Appom
|
|
2
2
|
module ElementFinder
|
3
3
|
# Find an element
|
4
4
|
def _find(*find_args)
|
5
|
+
args, text, visible = deduce_element_args(find_args)
|
5
6
|
wait = Wait.new(timeout: Appom.max_wait_time)
|
7
|
+
|
6
8
|
wait.until do
|
7
|
-
elements = page.find_elements(*
|
9
|
+
elements = page.find_elements(*args)
|
8
10
|
elements.each do |element|
|
9
|
-
|
11
|
+
# No need to check. Just return first element
|
12
|
+
if visible.nil? && text.nil?
|
10
13
|
return element
|
11
14
|
end
|
12
|
-
end
|
13
15
|
|
14
|
-
|
16
|
+
if !visible.nil? && !text.nil?
|
17
|
+
if element.displayed? && element.text == text
|
18
|
+
return element
|
19
|
+
end
|
20
|
+
elsif !visible.nil?
|
21
|
+
if element.displayed?
|
22
|
+
return element
|
23
|
+
end
|
24
|
+
elsif !text.nil?
|
25
|
+
if element.text == text
|
26
|
+
return element
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
raise Appom::ElementsEmptyError, "Not found element with text #{text}"
|
15
31
|
end
|
16
32
|
end
|
17
33
|
|
@@ -44,22 +60,6 @@ module Appom
|
|
44
60
|
end
|
45
61
|
end
|
46
62
|
|
47
|
-
# Find element with has text match with `text` value
|
48
|
-
# If not find element will raise error
|
49
|
-
def find_element_has_text(text, *find_args)
|
50
|
-
wait = Wait.new(timeout: Appom.max_wait_time)
|
51
|
-
wait.until do
|
52
|
-
elements = page.find_elements(*find_args)
|
53
|
-
elements.each do |element|
|
54
|
-
if element.displayed? && element.text == text
|
55
|
-
return element
|
56
|
-
end
|
57
|
-
|
58
|
-
raise Appom::ElementsEmptyError, "Not found element with text #{text}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
63
|
# Function is used to check
|
64
64
|
# Note: Function WILL NOT RETURN ELEMENT
|
65
65
|
def wait_until(type, *find_args)
|
@@ -81,5 +81,36 @@ module Appom
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def deduce_element_args(args)
|
88
|
+
# Flatten argument array first if we are in case array inside array
|
89
|
+
args = args.flatten
|
90
|
+
|
91
|
+
if args.empty?
|
92
|
+
raise(ArgumentError, 'You should provide search arguments in element creation')
|
93
|
+
end
|
94
|
+
|
95
|
+
# Get last key and check if it contain 'text' key
|
96
|
+
text = nil
|
97
|
+
visible = nil
|
98
|
+
|
99
|
+
args.each do |arg|
|
100
|
+
if arg.is_a?(Hash)
|
101
|
+
# Extract text value
|
102
|
+
if arg.key?(:text)
|
103
|
+
text = arg[:text]
|
104
|
+
args.delete(arg)
|
105
|
+
end
|
106
|
+
# Extract visible value
|
107
|
+
if arg.key?(:visible)
|
108
|
+
visible = arg[:visible]
|
109
|
+
args.delete(arg)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
[args, text, visible]
|
114
|
+
end
|
84
115
|
end
|
85
116
|
end
|
data/lib/appom/version.rb
CHANGED