appium_lib 14.0.0 → 15.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,198 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module Appium
16
- # MultiTouch actions allow for multiple touches to happen at the same time,
17
- # for instance, to simulate multiple finger swipes.
18
- #
19
- # Create a series of touch actions by themselves (without a `prepare()`), then
20
- # add to a new MultiTouch action. When ready, call `prepare()` and all
21
- # actions will be executed simultaneously.
22
- #
23
- # @example
24
- #
25
- # action_1 = TouchAction.new.press(x: 45, y: 100).wait(5).release
26
- # action_2 = TouchAction.new.tap(element: el, x: 50, y:5, count: 3)
27
- #
28
- # multi_touch_action = MultiTouch.new
29
- # multi_touch_action.add action_1
30
- # multi_touch_action.add action_2
31
- # multi_touch_action.perform
32
- #
33
- # # with an arbitrary driver
34
- # driver = Appium::Driver.new(opts, false).start_driver # return an Appium::Core::Base::Driver instance
35
- # multi_touch_action = MultiTouch.new(driver)
36
- # multi_touch_action.add action_1
37
- # multi_touch_action.add action_2
38
- # multi_touch_action.perform
39
- #
40
- class MultiTouch < Core::MultiTouch
41
- class << self
42
- # Convenience method for pinching the screen.
43
- # Places two fingers at the edges of the screen and brings them together.
44
- # @param percentage (int) The percent size by which to shrink the screen when pinched.
45
- # @param auto_perform (boolean) Whether to perform the action immediately (default true)
46
- # @param driver (Driver) Set a driver to conduct the action. DEfault is global driver($driver)
47
- #
48
- # @example
49
- #
50
- # pinch 75 #=> Pinch the screen from the top right and bottom left corners
51
- #
52
- # Without auto_perform
53
- #
54
- # @example
55
- #
56
- # action = pinch 75, false #=> Pinch the screen from the top right and bottom left corners
57
- # action.perform #=> to 25% of its size.
58
- #
59
- # With driver
60
- #
61
- # @example
62
- # driver = Appium::Driver.new(opts, false).start_driver
63
- # pinch 75, true, driver #=> Pinch the screen from the top right and bottom left corners
64
- #
65
- def pinch(percentage = 25, auto_perform = true, driver = $driver)
66
- raise ArgumentError("Can't pinch to greater than screen size.") if percentage > 100
67
-
68
- rate = Float(percentage) / 100
69
- pinch = MultiTouch.new(driver)
70
-
71
- if driver.device_is_android?
72
- top, bottom = pinch_android(rate, pinch.driver)
73
- else
74
- top, bottom = pinch_ios(rate, pinch.driver)
75
- end
76
-
77
- pinch.add top
78
- pinch.add bottom
79
- return pinch unless auto_perform
80
-
81
- pinch.perform
82
- end
83
-
84
- # Convenience method for zooming the screen.
85
- # Places two fingers at the edges of the screen and brings them together.
86
- # @param percentage (int) The percent size by which to shrink the screen when pinched.
87
- # @param auto_perform (boolean) Whether to perform the action immediately (default true)
88
- # @param driver (Driver) Set a driver to conduct the action. DEfault is global driver($driver)
89
- #
90
- # @example
91
- #
92
- # action = zoom 200 #=> Zoom in the screen from the center until it doubles in size.
93
- #
94
- # Without auto_perform
95
- #
96
- # @example
97
- #
98
- # action = zoom 200, false #=> Zoom in the screen from the center until it doubles in size.
99
- # action.perform #=> to 25% of its size.
100
- #
101
- # With driver
102
- #
103
- # @example
104
- #
105
- # driver = Appium::Driver.new(opts, false).start_driver
106
- # pinch 200, true, driver #=> Zoom in the screen from the center until it doubles in size.
107
- #
108
- def zoom(percentage = 200, auto_perform = true, driver = $driver)
109
- raise ArgumentError("Can't zoom to smaller then screen size.") if percentage < 100
110
-
111
- rate = 100 / Float(percentage)
112
- zoom = MultiTouch.new(driver)
113
-
114
- if driver.device_is_android?
115
- top, bottom = zoom_android(rate, zoom.driver)
116
- else
117
- top, bottom = zoom_ios(rate, zoom.driver)
118
- end
119
-
120
- zoom.add top
121
- zoom.add bottom
122
- return zoom unless auto_perform
123
-
124
- zoom.perform
125
- end
126
-
127
- private
128
-
129
- # @private
130
- def pinch_android(rate, driver)
131
- height = 100
132
- offset = 100
133
-
134
- top = ::Appium::Core::TouchAction.new(driver)
135
- top.swipe start_x: offset, start_y: 1.0 * height + offset,
136
- end_x: 0.0, end_y: (rate - 1) * height, duration: 1_000
137
-
138
- bottom = ::Appium::Core::TouchAction.new(driver)
139
- bottom.swipe start_x: offset, start_y: 0.0 + offset,
140
- end_x: 0.0, end_y: (1 - rate) * height, duration: 1_000
141
-
142
- [top, bottom]
143
- end
144
-
145
- # @private
146
- def pinch_ios(rate, driver)
147
- height = 100
148
- offset = 100
149
-
150
- top = ::Appium::Core::TouchAction.new(driver)
151
- top.swipe start_x: 0.5, start_y: 0.0 + offset,
152
- end_x: 0.0, end_y: (1 - rate) * height, duration: 1_000
153
-
154
- bottom = ::Appium::Core::TouchAction.new(driver)
155
- bottom.swipe start_x: 0.5, start_y: 1.0 + offset,
156
- end_x: 0.0, end_y: rate * height, duration: 1_000
157
-
158
- [top, bottom]
159
- end
160
-
161
- # @private
162
- def zoom_android(rate, driver)
163
- height = 100
164
- offset = 100
165
-
166
- top = ::Appium::Core::TouchAction.new(driver)
167
- top.swipe start_x: offset, start_y: (1.0 - rate) * height + offset,
168
- end_x: 0.0, end_y: (rate - 1.0) * height, duration: 1_000
169
-
170
- bottom = ::Appium::Core::TouchAction.new(driver)
171
- bottom.swipe start_x: offset, start_y: rate * height + offset,
172
- end_x: 0.0, end_y: (1.0 - rate) * height, duration: 1_000
173
-
174
- [top, bottom]
175
- end
176
-
177
- # @private
178
- def zoom_ios(rate, driver)
179
- height = 100
180
- offset = 100
181
-
182
- top = ::Appium::Core::TouchAction.new(driver)
183
- top.swipe start_x: 0.5, start_y: (1 - rate) * height + offset,
184
- end_x: 0.0, end_y: - (1 - rate) * height, duration: 1_000
185
-
186
- bottom = ::Appium::Core::TouchAction.new(driver)
187
- bottom.swipe start_x: 0.5, start_y: rate * height + offset,
188
- end_x: 0.0, end_y: (1 - rate) * height, duration: 1_000
189
-
190
- [top, bottom]
191
- end
192
- end # self
193
-
194
- def initialize(driver = $driver)
195
- super(driver)
196
- end
197
- end # class MultiTouch
198
- end # module Appium
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module Appium
16
- # Perform a series of gestures, one after another. Gestures are chained
17
- # together and only performed when `perform()` is called. Default is conducted by global driver.
18
- #
19
- # Each method returns the object itself, so calls can be chained.
20
- #
21
- # @example
22
- #
23
- # action = TouchAction.new.press(x: 45, y: 100).wait(5).release
24
- # action.perform
25
- # action = TouchAction.new.swipe(....)
26
- # action.perform
27
- #
28
- # Or each methods can call without `TouchAction.new` as the following.
29
- # In this case, `perform` is called automatically.
30
- #
31
- # @example
32
- #
33
- # # called `swipe(...).perform` in this method.
34
- # swipe(start_x: 75, start_y: 500, end_x: 75, end_y: 20, duration: 500)
35
- #
36
- # If you'd like to perform the chain with an arbitrary driver:
37
- #
38
- # @example
39
- #
40
- # driver = Appium::Driver.new(opts, false).start_driver # return an Appium::Core::Base::Driver instance
41
- # action = TouchAction.new(driver).press(x: 45, y: 100).wait(5).release
42
- # action.perform
43
- # action = TouchAction.new(driver).swipe(....)
44
- # action.perform
45
- #
46
- class TouchAction < ::Appium::Core::TouchAction
47
- COMPLEX_ACTIONS = ::Appium::Core::TouchAction::COMPLEX_ACTIONS
48
-
49
- class << self
50
- COMPLEX_ACTIONS.each do |action|
51
- define_method(action) do |opts|
52
- auto_perform = opts.delete(:auto_perform) { |_k| true }
53
- ta = ::Appium::TouchAction.new($driver)
54
- ta.send(action, opts)
55
- return ta unless auto_perform
56
-
57
- ta.perform
58
- end
59
- end
60
- end
61
-
62
- def initialize(driver = $driver)
63
- super driver
64
- end
65
-
66
- def swipe(opts)
67
- start_x = opts.fetch :start_x, 0
68
- start_y = opts.fetch :start_y, 0
69
- end_x = opts.fetch :end_x, 0
70
- end_y = opts.fetch :end_y, 0
71
- duration = opts.fetch :duration, 200
72
-
73
- super(start_x: start_x, start_y: start_y, end_x: end_x, end_y: end_y, duration: duration)
74
- end
75
- end # class TouchAction
76
- end # module Appium