screen-object 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/.rspec +2 -0
- data/ChangeLog +7 -0
- data/Gemfile +9 -0
- data/Rakefile +28 -0
- data/cucumber.yml +4 -0
- data/features/button.feature +28 -0
- data/features/checkbox.feature +11 -0
- data/features/navigation.feature +10 -0
- data/features/step_definitions/button_step.rb +46 -0
- data/features/step_definitions/checkbox_step.rb +12 -0
- data/features/step_definitions/navigation_steps.rb +14 -0
- data/features/step_definitions/table_step.rb +5 -0
- data/features/step_definitions/textfield_step.rb +5 -0
- data/features/support/appium.txt +9 -0
- data/features/support/appium_ios.txt +11 -0
- data/features/support/env.rb +30 -0
- data/features/support/screen.rb +79 -0
- data/features/support/screens/buttons_screen.rb +8 -0
- data/features/support/screens/landing_screen.rb +6 -0
- data/features/support/screens/main_screen.rb +6 -0
- data/features/table.feature +11 -0
- data/features/textfield.feature +10 -0
- data/lib/screen-object.rb +161 -0
- data/lib/screen-object/.DS_Store +0 -0
- data/lib/screen-object/accessors.rb +457 -0
- data/lib/screen-object/accessors/button.rb +36 -0
- data/lib/screen-object/accessors/checkbox.rb +38 -0
- data/lib/screen-object/accessors/element.rb +144 -0
- data/lib/screen-object/accessors/image.rb +25 -0
- data/lib/screen-object/accessors/table.rb +26 -0
- data/lib/screen-object/accessors/text.rb +46 -0
- data/lib/screen-object/accessors/textfield.rb +41 -0
- data/lib/screen-object/appium_server.rb +58 -0
- data/lib/screen-object/elements.rb +21 -0
- data/lib/screen-object/load_appium.rb +31 -0
- data/lib/screen-object/screen_factory.rb +43 -0
- data/lib/screen-object/version.rb +4 -0
- data/screen-object.gemspec +28 -0
- data/spec/integration/appium_server_spec.rb +24 -0
- data/spec/lib/appium_server_spec.rb +59 -0
- data/spec/lib/screen_object_spec.rb +37 -0
- data/spec/screen-object/button_spec.rb +25 -0
- data/spec/screen-object/checkbox_spec.rb +35 -0
- data/spec/screen-object/element_spec.rb +205 -0
- data/spec/screen-object/image_spec.rb +21 -0
- data/spec/screen-object/text_field_spec.rb +37 -0
- data/spec/screen-object/text_spec.rb +29 -0
- data/spec/spec_helper.rb +29 -0
- metadata +201 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
#require_relative File.expand_path('../element',__FILE__)
|
16
|
+
|
17
|
+
|
18
|
+
module ScreenObject
|
19
|
+
module AppElements
|
20
|
+
class Button < AppElements::Element
|
21
|
+
|
22
|
+
def tap
|
23
|
+
element.click
|
24
|
+
end
|
25
|
+
|
26
|
+
def enabled?
|
27
|
+
begin
|
28
|
+
element.enabled?
|
29
|
+
rescue
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
|
16
|
+
module ScreenObject
|
17
|
+
module AppElements
|
18
|
+
class CheckBox < AppElements::Element
|
19
|
+
|
20
|
+
def checked?
|
21
|
+
if element.attribute('checked') == 'true'
|
22
|
+
return true
|
23
|
+
else
|
24
|
+
return false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def check
|
29
|
+
element.click unless checked?
|
30
|
+
end
|
31
|
+
|
32
|
+
def uncheck
|
33
|
+
element.click if checked?
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
module ScreenObject
|
16
|
+
module AppElements
|
17
|
+
|
18
|
+
class Element
|
19
|
+
|
20
|
+
attr_reader :locator
|
21
|
+
|
22
|
+
def initialize(locator)
|
23
|
+
@locator=locator.split("~")
|
24
|
+
end
|
25
|
+
|
26
|
+
def driver
|
27
|
+
$driver
|
28
|
+
end
|
29
|
+
|
30
|
+
def click
|
31
|
+
element.click
|
32
|
+
end
|
33
|
+
|
34
|
+
def value
|
35
|
+
element.value
|
36
|
+
end
|
37
|
+
|
38
|
+
def exists?
|
39
|
+
begin
|
40
|
+
element.displayed?
|
41
|
+
rescue
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def element
|
47
|
+
driver.find_element(:"#{locator[0]}",locator[1])
|
48
|
+
end
|
49
|
+
|
50
|
+
def elements
|
51
|
+
driver.find_elements(:"#{locator[0]}",locator[1])
|
52
|
+
end
|
53
|
+
|
54
|
+
def element_attributes
|
55
|
+
%w[name resource-id value text]
|
56
|
+
end
|
57
|
+
|
58
|
+
def dynamic_xpath(text)
|
59
|
+
concat_attribute=[]
|
60
|
+
element_attributes.each{|i| concat_attribute << %Q(contains(@#{i}, '#{text}'))}
|
61
|
+
puts "//#{locator[0]}[#{concat_attribute.join(' or ')}]"
|
62
|
+
locator1="xpath~//#{locator[0]}[#{concat_attribute.join(' or ')}]"
|
63
|
+
@locator=locator1.split("~")
|
64
|
+
element
|
65
|
+
end
|
66
|
+
|
67
|
+
def dynamic_text_exists? dynamic_text
|
68
|
+
begin
|
69
|
+
dynamic_xpath(dynamic_text).displayed?
|
70
|
+
rescue
|
71
|
+
false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def scroll
|
76
|
+
$driver.execute_script 'mobile: scrollTo',:element => element.ref
|
77
|
+
# $driver.execute_script("mobile: scroll",:direction => direction.downcase, :element => element.ref)
|
78
|
+
end
|
79
|
+
|
80
|
+
def scroll_to_text(text)
|
81
|
+
$driver.scroll_to(text)
|
82
|
+
end
|
83
|
+
|
84
|
+
def scroll_to_exact_text(text)
|
85
|
+
$driver.scroll_to_exact(text)
|
86
|
+
end
|
87
|
+
|
88
|
+
def scroll_for_element_click
|
89
|
+
if element.displayed?
|
90
|
+
element.click
|
91
|
+
else
|
92
|
+
scroll
|
93
|
+
element.click
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def scroll_for_dynamic_element_click (expected_text)
|
98
|
+
if dynamic_xpath(expected_text).displayed?
|
99
|
+
element.click
|
100
|
+
else
|
101
|
+
scroll
|
102
|
+
element.click
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def click_text(text)
|
107
|
+
if exists?
|
108
|
+
click
|
109
|
+
else
|
110
|
+
scroll_to_text(text)
|
111
|
+
element.click
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def click_dynamic_text(text)
|
116
|
+
if dynamic_text_exists?(text)
|
117
|
+
element.click
|
118
|
+
else
|
119
|
+
scroll_to_text(text)
|
120
|
+
element.click
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def click_exact_text(text)
|
125
|
+
if exists?
|
126
|
+
click
|
127
|
+
else
|
128
|
+
scroll_to_exact_text(text)
|
129
|
+
element.click
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def click_dynamic_exact_text(text)
|
134
|
+
if dynamic_text_exists?(text)
|
135
|
+
element.click
|
136
|
+
else
|
137
|
+
scroll_to_exact_text(text)
|
138
|
+
element.click
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
module ScreenObject
|
16
|
+
module AppElements
|
17
|
+
class Image < AppElements::Element
|
18
|
+
|
19
|
+
def click
|
20
|
+
element.click
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
module ScreenObject
|
16
|
+
module AppElements
|
17
|
+
|
18
|
+
class Table < AppElements::Element
|
19
|
+
|
20
|
+
def cell_count
|
21
|
+
elements.length
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
module ScreenObject
|
16
|
+
module AppElements
|
17
|
+
class Text < AppElements::Element
|
18
|
+
|
19
|
+
def text
|
20
|
+
element.text()
|
21
|
+
end
|
22
|
+
|
23
|
+
def click
|
24
|
+
element.click
|
25
|
+
end
|
26
|
+
|
27
|
+
def dynamic_text_exists? dynamic_text
|
28
|
+
begin
|
29
|
+
dynamic_xpath(dynamic_text).displayed?
|
30
|
+
rescue
|
31
|
+
false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def dynamic_text dynamic_text
|
36
|
+
begin
|
37
|
+
dynamic_xpath(dynamic_text).displayed?
|
38
|
+
text
|
39
|
+
rescue
|
40
|
+
false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
module ScreenObject
|
16
|
+
module AppElements
|
17
|
+
class TextField < AppElements::Element
|
18
|
+
|
19
|
+
def text=(text)
|
20
|
+
element.send_keys text
|
21
|
+
end
|
22
|
+
|
23
|
+
def text
|
24
|
+
element.text
|
25
|
+
end
|
26
|
+
|
27
|
+
def clear
|
28
|
+
element.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
def enabled?
|
32
|
+
begin
|
33
|
+
element.enabled?
|
34
|
+
rescue
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
require 'childprocess'
|
16
|
+
|
17
|
+
#
|
18
|
+
# This class is designed to start and stop the appium server process. In order to use
|
19
|
+
# it you must have appium and node installed on your computer. You can pass parameters
|
20
|
+
# to appium at startup via the constructor.
|
21
|
+
#
|
22
|
+
module ScreenObject
|
23
|
+
class AppiumServer
|
24
|
+
|
25
|
+
attr_accessor :process
|
26
|
+
|
27
|
+
|
28
|
+
def initialize(params={})
|
29
|
+
@params = params
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Start the appium server
|
34
|
+
#
|
35
|
+
def start
|
36
|
+
@process = ChildProcess.build(*parameters)
|
37
|
+
process.start
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Stop the appium server
|
42
|
+
#
|
43
|
+
def stop
|
44
|
+
process.stop
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def parameters
|
50
|
+
cmd = ['appium']
|
51
|
+
@params.each do |key, value|
|
52
|
+
cmd << '--'+key.to_s
|
53
|
+
cmd << value.to_s if not value.nil? and value.size > 0
|
54
|
+
end
|
55
|
+
cmd
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
=begin
|
2
|
+
***********************************************************************************************************
|
3
|
+
Copyright 2016 Capital One Services, LLC
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
See the License for the specific language governing permissions and limitations under the License.
|
12
|
+
***********************************************************************************************************
|
13
|
+
=end
|
14
|
+
|
15
|
+
require 'screen-object/accessors/element'
|
16
|
+
require 'screen-object/accessors/button'
|
17
|
+
require 'screen-object/accessors/image'
|
18
|
+
require 'screen-object/accessors/text'
|
19
|
+
require 'screen-object/accessors/textfield'
|
20
|
+
require 'screen-object/accessors/checkbox'
|
21
|
+
require 'screen-object/accessors/table'
|