appom 1.1.6 → 1.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
2
  SHA256:
3
- metadata.gz: ca73259e6cc6e55a6def1bf2b0bbe9609e2b6c0fe80a86e7fcc9f8193d6f53ac
4
- data.tar.gz: af52858128229cc9cdf69bf57bfb30cc2ec0e46816a7b33182981704ded448ed
3
+ metadata.gz: 35d79b86da3958d465691aa8f67adff728310412cfe8f898ec1f00b16efc0102
4
+ data.tar.gz: 3bea92052029e696b96c86bdacbdddaeaca1972fced1bb0e27592d0d13e1ca46
5
5
  SHA512:
6
- metadata.gz: 29fd801a109c6e10a11ad173b32b157398d239edefe041142811e6a1c521611090c731e981d9c8236028797aa7eefe14f2f27bb030d22c6d977295306c76a625
7
- data.tar.gz: 3eec972de070351475afe1178836b1031c7b64284d4f2878544a64f0c3d64d792e2b0a7905137a4410009f9be0954543e6ff86e144abd2b49a342eb104b6f381
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
- args, text = deduce_element_args(find_args)
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
- if text.nil?
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, args)
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
@@ -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(*find_args)
9
+ elements = page.find_elements(*args)
8
10
  elements.each do |element|
9
- if element.displayed?
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
- raise Appom::ElementsEmptyError, "Not found element displayed"
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
@@ -1,3 +1,3 @@
1
1
  module Appom
2
- VERSION = '1.1.6'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry.Tran