appom 0.4.0 → 0.5.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/README.md +9 -0
- data/lib/appom.rb +16 -2
- data/lib/appom/element_container.rb +62 -4
- data/lib/appom/page.rb +42 -2
- data/lib/appom/version.rb +1 -1
- data/lib/appom/wait.rb +40 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2f17ca36a2cd4e5621ecf4f2d2d842f229494df5cb2ca7629fb02faba05115f
|
4
|
+
data.tar.gz: 646ba303457e66fd2517b45100efac3e15bd97d1fd3ced1d7bc9cccccdacc4aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aad052c0abe308b033616d60e94598c500d2eebba065677a49ac59fe170227305fea83f7a918c3be2f7265fec82fed4920c5257de92057cf36d759ddc1564540
|
7
|
+
data.tar.gz: 50b469a37d97e15f9a001b7e9cda5c7e5ea7a37598b7667259bbac93d6c9cdee999c6e5584fccf7afd4e57514bba6194f6e19ce9fdf2c699ee01b489cc8c4fc4
|
data/README.md
CHANGED
@@ -45,6 +45,12 @@ end
|
|
45
45
|
```
|
46
46
|
`appium_lib_options` and `caps` are options to initiate a appium driver. You can follow [Appium Ruby Client](https://github.com/appium/ruby_lib)
|
47
47
|
|
48
|
+
### Change default max wait time
|
49
|
+
```ruby
|
50
|
+
Appom.configure do |config|
|
51
|
+
config.max_wait_time = 30
|
52
|
+
end
|
53
|
+
```
|
48
54
|
|
49
55
|
### Define a page
|
50
56
|
```ruby
|
@@ -55,6 +61,9 @@ class LoginPage < Appom::Page
|
|
55
61
|
end
|
56
62
|
```
|
57
63
|
|
64
|
+
The Appom Wiki has lots of additional information about Appom. Please browse the Wiki after finishing this README:
|
65
|
+
https://github.com/hoangtaiki/appom/wiki
|
66
|
+
|
58
67
|
## Example
|
59
68
|
[authentication-appom-appium](https://github.com/hoangtaiki/authentication-appom-appium) is an example about using Appom with Appium.
|
60
69
|
|
data/lib/appom.rb
CHANGED
@@ -5,16 +5,28 @@ require 'appium_lib'
|
|
5
5
|
require 'appom/cucumber'
|
6
6
|
|
7
7
|
module Appom
|
8
|
-
# A item was defined without a selector
|
8
|
+
# A item was defined without a selector.
|
9
9
|
class InvalidElementError < StandardError; end
|
10
|
-
# A block was passed to the method, which it cannot
|
10
|
+
# A block was passed to the method, which it cannot interpreter.
|
11
11
|
class UnsupportedBlockError < StandardError; end
|
12
|
+
# The condition that was being evaluated inside the block did not evaluate
|
13
|
+
# to true within the time limit.
|
14
|
+
class TimeoutError < StandardError; end
|
15
|
+
# An element could not be located on the page using the given search parameters.
|
16
|
+
class NoSuchElementError < StandardError; end
|
12
17
|
|
13
18
|
autoload :ElementContainer, 'appom/element_container'
|
14
19
|
autoload :Page, 'appom/page'
|
20
|
+
autoload :Wait, 'appom/wait'
|
15
21
|
|
16
22
|
class << self
|
17
23
|
attr_accessor :driver
|
24
|
+
attr_accessor :max_wait_time
|
25
|
+
|
26
|
+
# Configure appom
|
27
|
+
def configure
|
28
|
+
yield self
|
29
|
+
end
|
18
30
|
|
19
31
|
# Register a new appium driver for Appom.
|
20
32
|
# @return [Appium::Driver] A appium driver instance
|
@@ -41,6 +53,8 @@ module Appom
|
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
56
|
+
|
57
|
+
@max_wait_time = 20
|
44
58
|
end
|
45
59
|
|
46
60
|
World(Appom)
|
@@ -36,7 +36,7 @@ module Appom
|
|
36
36
|
# element :email, :accessibility_id, 'email_text_field'
|
37
37
|
#
|
38
38
|
# @param name Element name
|
39
|
-
# @param *find_args An array contain information to find the element. It contains locator
|
39
|
+
# @param *find_args An array contain information to find the element. It contains locator strategy and search target
|
40
40
|
# http://appium.io/docs/en/commands/element/find-element/
|
41
41
|
#
|
42
42
|
# Element doesn't support block so that will raise if pass a block when declare
|
@@ -57,7 +57,7 @@ module Appom
|
|
57
57
|
# elements :contact_cell, :accessibility_id, 'contact_cell'
|
58
58
|
#
|
59
59
|
# @param name Element name
|
60
|
-
# @param *find_args An array contain information to find the elements. It contains locator
|
60
|
+
# @param *find_args An array contain information to find the elements. It contains locator strategy and search target
|
61
61
|
# http://appium.io/docs/en/commands/element/find-element/
|
62
62
|
#
|
63
63
|
# Elements doesn't support block so that will raise if pass a block when declare
|
@@ -83,7 +83,7 @@ module Appom
|
|
83
83
|
|
84
84
|
private
|
85
85
|
|
86
|
-
# Add item to @mapped_items or define
|
86
|
+
# Add item to @mapped_items or define method to notify that we can't find item without args
|
87
87
|
def build(name, *find_args)
|
88
88
|
if find_args.empty?
|
89
89
|
create_error_method(name)
|
@@ -91,14 +91,72 @@ module Appom
|
|
91
91
|
add_to_mapped_items(name)
|
92
92
|
yield
|
93
93
|
end
|
94
|
+
add_helper_methods(name, *find_args)
|
94
95
|
end
|
95
96
|
|
96
|
-
# Define
|
97
|
+
# Define method to notify that we can't find item without args
|
97
98
|
def create_error_method(name)
|
98
99
|
define_method(name) do
|
99
100
|
raise Appom::InvalidElementError
|
100
101
|
end
|
101
102
|
end
|
103
|
+
|
104
|
+
def add_helper_methods(name, *find_args)
|
105
|
+
create_existence_checker(name, *find_args)
|
106
|
+
create_nonexistence_checker(name, *find_args)
|
107
|
+
create_get_all_elements(name, *find_args)
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_helper_method(proposed_method_name, *find_args)
|
111
|
+
if find_args.empty?
|
112
|
+
create_error_method(proposed_method_name)
|
113
|
+
else
|
114
|
+
yield
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Check element exist
|
120
|
+
# We will try to find all elements with *find_args
|
121
|
+
# Condition is pass when response is not empty
|
122
|
+
#
|
123
|
+
def create_existence_checker(element_name, *find_args)
|
124
|
+
method_name = "has_#{element_name}?"
|
125
|
+
create_helper_method(method_name, *find_args) do
|
126
|
+
define_method(method_name) do |*runtime_args|
|
127
|
+
args = merge_args(find_args, runtime_args)
|
128
|
+
wait_check_util_not_empty(*args)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Check element non-existent
|
135
|
+
# We will try to find all elements with *find_args
|
136
|
+
# Condition is pass when response is empty
|
137
|
+
#
|
138
|
+
def create_nonexistence_checker(element_name, *find_args)
|
139
|
+
method_name = "has_no_#{element_name}?"
|
140
|
+
create_helper_method(method_name, *find_args) do
|
141
|
+
define_method(method_name) do |*runtime_args|
|
142
|
+
args = merge_args(find_args, runtime_args)
|
143
|
+
wait_check_util_empty(*args)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# Try to get all elements until not get empty array
|
150
|
+
#
|
151
|
+
def create_get_all_elements(element_name, *find_args)
|
152
|
+
method_name = "get_all_#{element_name}"
|
153
|
+
create_helper_method(method_name, *find_args) do
|
154
|
+
define_method(method_name) do |*runtime_args|
|
155
|
+
args = merge_args(find_args, runtime_args)
|
156
|
+
wait_check_util_empty(*args)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
102
160
|
end
|
103
161
|
end
|
104
162
|
end
|
data/lib/appom/page.rb
CHANGED
@@ -5,12 +5,52 @@ module Appom
|
|
5
5
|
|
6
6
|
# Find an element
|
7
7
|
def find(*find_args)
|
8
|
-
Appom.
|
8
|
+
wait = Wait.new(timeout: Appom.max_wait_time)
|
9
|
+
wait.until { Appom.driver.find_element(*find_args) }
|
9
10
|
end
|
10
11
|
|
11
12
|
# Find elements
|
12
13
|
def all(*find_args)
|
13
14
|
Appom.driver.find_elements(*find_args)
|
14
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
|
15
55
|
end
|
16
|
-
end
|
56
|
+
end
|
data/lib/appom/version.rb
CHANGED
data/lib/appom/wait.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Appom
|
2
|
+
class Wait
|
3
|
+
DEFAULT_TIMEOUT = 5
|
4
|
+
DEFAULT_INTERVAL = 0.25
|
5
|
+
|
6
|
+
##
|
7
|
+
# Create a new Wait instance
|
8
|
+
#
|
9
|
+
# @param [Hash] opts Options for this instance
|
10
|
+
# @option opts [Numeric] :timeout (5) Seconds to wait before timing out.
|
11
|
+
# @option opts [Numeric] :interval (0.25) Seconds to sleep between polls.
|
12
|
+
#
|
13
|
+
def initialize(opts = {})
|
14
|
+
@timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT)
|
15
|
+
@interval = opts.fetch(:interval, DEFAULT_INTERVAL)
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Wait until the given block returns a true value.
|
20
|
+
#
|
21
|
+
# @raise [Error::TimeOutError]
|
22
|
+
# @return [Object] the result of the block
|
23
|
+
#
|
24
|
+
def until
|
25
|
+
end_time = Time.now + @timeout
|
26
|
+
|
27
|
+
until Time.now > end_time
|
28
|
+
begin
|
29
|
+
result = yield
|
30
|
+
return result if result
|
31
|
+
rescue
|
32
|
+
end
|
33
|
+
|
34
|
+
sleep @interval
|
35
|
+
end
|
36
|
+
|
37
|
+
raise Appom::TimeoutError, "Timed out after #{@timeout}s."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
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.5.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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appium_lib
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/appom/element_container.rb
|
68
68
|
- lib/appom/page.rb
|
69
69
|
- lib/appom/version.rb
|
70
|
+
- lib/appom/wait.rb
|
70
71
|
homepage: https://github.com/hoangtaiki/appom
|
71
72
|
licenses:
|
72
73
|
- MIT
|