appom 0.6.0 → 0.7.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.rb +2 -0
- data/lib/appom/element_container.rb +79 -8
- data/lib/appom/element_finder.rb +69 -0
- data/lib/appom/page.rb +3 -64
- data/lib/appom/section.rb +28 -0
- data/lib/appom/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32300dd3f4ed1e4ff737e2614ab06ce5c976b4cab63701b83207ab56419c1ebf
|
4
|
+
data.tar.gz: de9ef291dee27ace03da53c601f29b7d0143cf71ad51dcf95e32ba5cf494f2be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e356e9bd0586b78bc5cd8dc47dbb11e3de9cdaf531db7fdc27e4a64fa25e03162be3e04ba0126be099162500cce4a1723617f880bcf26000a2d1216cf812a0f4
|
7
|
+
data.tar.gz: 37c7e1ad64adae8dbf3a0033bbfe0264d11c7d9ae35c4a2df0d1e535298c9c6868011db5f322e64090134a42958851f8f1dff9b2dea6aa56b032a3cd8fa3ce10
|
data/lib/appom.rb
CHANGED
@@ -18,6 +18,8 @@ module Appom
|
|
18
18
|
autoload :ElementContainer, 'appom/element_container'
|
19
19
|
autoload :Page, 'appom/page'
|
20
20
|
autoload :Wait, 'appom/wait'
|
21
|
+
autoload :Section, 'appom/section'
|
22
|
+
autoload :ElementFinder, 'appom/element_finder'
|
21
23
|
|
22
24
|
class << self
|
23
25
|
attr_accessor :driver
|
@@ -42,13 +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
|
-
build_element(name, *find_args) do
|
46
|
-
define_method(name) do
|
45
|
+
build_element(name, *find_args) do
|
46
|
+
define_method(name) do |*runtime_args, &block|
|
47
47
|
raise_if_block(self, name, !block.nil?, :element)
|
48
|
-
|
48
|
+
_find(*merge_args(find_args, runtime_args))
|
49
49
|
end
|
50
50
|
define_method("#{name}_params") do
|
51
|
-
merge_args(find_args
|
51
|
+
merge_args(find_args)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -66,13 +66,41 @@ module Appom
|
|
66
66
|
# Elements doesn't support block so that will raise if pass a block when declare
|
67
67
|
#
|
68
68
|
def elements(name, *find_args)
|
69
|
-
build_elements(name, *find_args) do
|
70
|
-
define_method(name) do
|
69
|
+
build_elements(name, *find_args) do
|
70
|
+
define_method(name) do |*runtime_args, &block|
|
71
71
|
raise_if_block(self, name, !block.nil?, :elements)
|
72
|
-
|
72
|
+
_all(*merge_args(find_args, runtime_args))
|
73
73
|
end
|
74
74
|
define_method("#{name}_params") do
|
75
|
-
merge_args(find_args
|
75
|
+
merge_args(find_args)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def section(name, *args, &block)
|
81
|
+
section_class, find_args = extract_section_options(args, &block)
|
82
|
+
build_element(name, *find_args) do
|
83
|
+
define_method(name) do |*runtime_args, &block|
|
84
|
+
section_element = _find(*merge_args(find_args, runtime_args))
|
85
|
+
section_class.new(self, section_element)
|
86
|
+
end
|
87
|
+
define_method("#{name}_params") do
|
88
|
+
merge_args(find_args)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def sections(name, *args, &block)
|
94
|
+
section_class, find_args = extract_section_options(args, &block)
|
95
|
+
build(name, *find_args) do
|
96
|
+
define_method(name) do |*runtime_args, &block|
|
97
|
+
raise_if_block(self, name, !block.nil?, :sections)
|
98
|
+
_all(*merge_args(find_args, runtime_args)).map do |element|
|
99
|
+
section_class.new(self, element)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
define_method("#{name}_params") do
|
103
|
+
merge_args(find_args)
|
76
104
|
end
|
77
105
|
end
|
78
106
|
end
|
@@ -207,6 +235,49 @@ module Appom
|
|
207
235
|
end
|
208
236
|
end
|
209
237
|
end
|
238
|
+
|
239
|
+
##
|
240
|
+
# Extract section options
|
241
|
+
# @return section class name and the remaining parameters
|
242
|
+
#
|
243
|
+
def extract_section_options(args, &block)
|
244
|
+
if args.first.is_a?(Class)
|
245
|
+
klass = args.shift
|
246
|
+
section_class = klass if klass.ancestors.include?(Appom::Section)
|
247
|
+
end
|
248
|
+
|
249
|
+
section_class = deduce_section_class(section_class, &block)
|
250
|
+
arguments = deduce_search_arguments(section_class, args)
|
251
|
+
[section_class, arguments]
|
252
|
+
end
|
253
|
+
|
254
|
+
##
|
255
|
+
# Deduce section class
|
256
|
+
#
|
257
|
+
def deduce_section_class(base_class, &block)
|
258
|
+
klass = base_class
|
259
|
+
|
260
|
+
klass = Class.new(klass || Appom::Section, &block) if block_given?
|
261
|
+
|
262
|
+
unless klass
|
263
|
+
raise ArgumentError, 'You should provide descendant of Appom::Section class or/and a block as the second argument.'
|
264
|
+
end
|
265
|
+
klass
|
266
|
+
end
|
267
|
+
|
268
|
+
##
|
269
|
+
# Deduce search parameters
|
270
|
+
#
|
271
|
+
def deduce_search_arguments(section_class, args)
|
272
|
+
extract_search_arguments(args) ||
|
273
|
+
extract_search_arguments(section_class.default_search_arguments) ||
|
274
|
+
raise(ArgumentError, 'You should provide search arguments in section creation or set_default_search_arguments within section class')
|
275
|
+
end
|
276
|
+
|
277
|
+
def extract_search_arguments(args)
|
278
|
+
args if args && !args.empty?
|
279
|
+
end
|
280
|
+
|
210
281
|
end
|
211
282
|
end
|
212
283
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Appom
|
2
|
+
module ElementFinder
|
3
|
+
# Find an element
|
4
|
+
def _find(*find_args)
|
5
|
+
wait = Wait.new(timeout: Appom.max_wait_time)
|
6
|
+
wait.until { page.find_element(*find_args) }
|
7
|
+
end
|
8
|
+
|
9
|
+
# Find elements
|
10
|
+
def _all(*find_args)
|
11
|
+
page.find_elements(*find_args)
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Use wait to check element non-exist
|
16
|
+
# Before timeout we will try to find elements and check response is empty
|
17
|
+
#
|
18
|
+
def wait_check_util_empty(*find_args)
|
19
|
+
wait = Wait.new(timeout: Appom.max_wait_time)
|
20
|
+
wait.until do
|
21
|
+
page.find_elements(*find_args).empty?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Use wait to check element exist
|
27
|
+
# Before timeout we will try to find elements and check response is not empty
|
28
|
+
#
|
29
|
+
def wait_check_util_not_empty(*find_args)
|
30
|
+
wait = Wait.new(timeout: Appom.max_wait_time)
|
31
|
+
wait.until do
|
32
|
+
!page.find_elements(*find_args).empty?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Use wait to get elements
|
38
|
+
# Before timeout we will try to find elements until response is not empty
|
39
|
+
#
|
40
|
+
def wait_util_get_not_empty(*find_args)
|
41
|
+
wait = Wait.new(timeout: Appom.max_wait_time)
|
42
|
+
wait.until do
|
43
|
+
result = page.find_elements(*find_args)
|
44
|
+
# If reponse is empty we will return false to make it not pass Wait condition
|
45
|
+
if result.empty?
|
46
|
+
return false
|
47
|
+
end
|
48
|
+
# Return result
|
49
|
+
return result
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
##
|
54
|
+
# Wait until an element will be enable
|
55
|
+
#
|
56
|
+
def wait_util_element_enabled(*find_args)
|
57
|
+
wait = Wait.new(timeout: Appom.max_wait_time)
|
58
|
+
wait.until { page.find_element(*find_args).enabled? }
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Wait until an element will be disable
|
63
|
+
#
|
64
|
+
def wait_util_element_disabled(*find_args)
|
65
|
+
wait = Wait.new(timeout: Appom.max_wait_time)
|
66
|
+
wait.until { !page.find_element(*find_args).enabled? }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/appom/page.rb
CHANGED
@@ -2,71 +2,10 @@ module Appom
|
|
2
2
|
class Page
|
3
3
|
include Appium
|
4
4
|
include ElementContainer
|
5
|
+
include ElementFinder
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
wait = Wait.new(timeout: Appom.max_wait_time)
|
9
|
-
wait.until { Appom.driver.find_element(*find_args) }
|
10
|
-
end
|
11
|
-
|
12
|
-
# Find elements
|
13
|
-
def all(*find_args)
|
14
|
-
Appom.driver.find_elements(*find_args)
|
15
|
-
end
|
16
|
-
|
17
|
-
##
|
18
|
-
# Use wait to check element non-exist
|
19
|
-
# Before timeout we will try to find elements and check response is empty
|
20
|
-
#
|
21
|
-
def wait_check_util_empty(*find_args)
|
22
|
-
wait = Wait.new(timeout: Appom.max_wait_time)
|
23
|
-
wait.until do
|
24
|
-
Appom.driver.find_elements(*find_args).empty?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# Use wait to check element exist
|
30
|
-
# Before timeout we will try to find elements and check response is not empty
|
31
|
-
#
|
32
|
-
def wait_check_util_not_empty(*find_args)
|
33
|
-
wait = Wait.new(timeout: Appom.max_wait_time)
|
34
|
-
wait.until do
|
35
|
-
!Appom.driver.find_elements(*find_args).empty?
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
##
|
40
|
-
# Use wait to get elements
|
41
|
-
# Before timeout we will try to find elements until response is not empty
|
42
|
-
#
|
43
|
-
def wait_util_get_not_empty(*find_args)
|
44
|
-
wait = Wait.new(timeout: Appom.max_wait_time)
|
45
|
-
wait.until do
|
46
|
-
result = Appom.driver.find_elements(*find_args)
|
47
|
-
# If reponse is empty we will return false to make it not pass Wait condition
|
48
|
-
if result.empty?
|
49
|
-
return false
|
50
|
-
end
|
51
|
-
# Return result
|
52
|
-
return result
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
##
|
57
|
-
# Wait until an element will be enable
|
58
|
-
#
|
59
|
-
def wait_util_element_enabled(*find_args)
|
60
|
-
wait = Wait.new(timeout: Appom.max_wait_time)
|
61
|
-
wait.until { Appom.driver.find_element(*find_args).enabled? }
|
62
|
-
end
|
63
|
-
|
64
|
-
##
|
65
|
-
# Wait until an element will be disable
|
66
|
-
#
|
67
|
-
def wait_util_element_disabled(*find_args)
|
68
|
-
wait = Wait.new(timeout: Appom.max_wait_time)
|
69
|
-
wait.until { !Appom.driver.find_element(*find_args).enabled? }
|
7
|
+
def page
|
8
|
+
@page || Appom.driver
|
70
9
|
end
|
71
10
|
end
|
72
11
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Appom
|
2
|
+
class Section
|
3
|
+
include Appium
|
4
|
+
include ElementContainer
|
5
|
+
include ElementFinder
|
6
|
+
|
7
|
+
attr_reader :root_element, :parent
|
8
|
+
|
9
|
+
def initialize(parent, root_element)
|
10
|
+
@parent = parent
|
11
|
+
@root_element = root_element
|
12
|
+
end
|
13
|
+
|
14
|
+
def page
|
15
|
+
root_element || super
|
16
|
+
end
|
17
|
+
|
18
|
+
def parent_page
|
19
|
+
candidate_page = parent
|
20
|
+
until candidate_page.is_a?(SitePrism::Page)
|
21
|
+
candidate_page = candidate_page.parent
|
22
|
+
end
|
23
|
+
candidate_page
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
end
|
28
|
+
end
|
data/lib/appom/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry.Tran
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appium_lib
|
@@ -65,7 +65,9 @@ files:
|
|
65
65
|
- lib/appom.rb
|
66
66
|
- lib/appom/cucumber.rb
|
67
67
|
- lib/appom/element_container.rb
|
68
|
+
- lib/appom/element_finder.rb
|
68
69
|
- lib/appom/page.rb
|
70
|
+
- lib/appom/section.rb
|
69
71
|
- lib/appom/version.rb
|
70
72
|
- lib/appom/wait.rb
|
71
73
|
homepage: https://github.com/hoangtaiki/appom
|