appium_lib_core 4.3.1 → 5.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,253 +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
- module Core
17
- class Base
18
- class Bridge
19
- class W3C < ::Selenium::WebDriver::Remote::W3C::Bridge
20
- include Device::DeviceLock
21
- include Device::Keyboard
22
- include Device::ImeActions
23
- include Device::Setting
24
- include Device::Context
25
- include Device::Value
26
- include Device::FileManagement
27
- include Device::KeyEvent
28
- include Device::ImageComparison
29
- include Device::AppManagement
30
- include Device::AppState
31
- include Device::ScreenRecord::Command
32
- include Device::Device
33
- include Device::TouchActions
34
- include Device::ExecuteDriver
35
- include Device::Orientation
36
-
37
- def commands(command)
38
- ::Appium::Core::Commands::W3C::COMMANDS[command]
39
- end
40
-
41
- # Returns all available sessions on the Appium server instance
42
- def sessions
43
- execute :get_all_sessions
44
- end
45
-
46
- # Perform touch actions for W3C module.
47
- # Generate +touch+ pointer action here and users can use this via +driver.action+
48
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/W3CActionBuilder.html
49
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/PointerActions.html
50
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
51
- #
52
- # 'mouse' action is by default in the Ruby client. Appium server force the +mouse+ action to +touch+ once in
53
- # the server side. So we don't consider the case.
54
- #
55
- # @example
56
- #
57
- # element = @driver.find_element(:id, "some id")
58
- # @driver.action.click(element).perform # The 'click' is a part of 'PointerActions'
59
- #
60
- def action(async = false)
61
- # Used for default duration of each touch actions
62
- # Override from 250 milliseconds to 50 milliseconds
63
- action_builder = super
64
- action_builder.default_move_duration = 0.05
65
- action_builder
66
- end
67
-
68
- # Port from MJSONWP
69
- def get_timeouts
70
- execute :get_timeouts
71
- end
72
-
73
- # Port from MJSONWP
74
- def session_capabilities
75
- ::Selenium::WebDriver::Remote::W3C::Capabilities.json_create execute(:get_capabilities)
76
- end
77
-
78
- # Port from MJSONWP
79
- def send_keys_to_active_element(key)
80
- text = ::Selenium::WebDriver::Keys.encode(key).join('')
81
- execute :send_keys_to_active_element, {}, { value: text.split(//) }
82
- end
83
-
84
- # For Appium
85
- # override
86
- def page_source
87
- # For W3C
88
- # execute_script('var source = document.documentElement.outerHTML;' \
89
- # 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \
90
- # 'return source;')
91
- execute :get_page_source
92
- end
93
-
94
- # For Appium
95
- # override
96
- def element_displayed?(element)
97
- # For W3C
98
- # https://github.com/SeleniumHQ/selenium/commit/b618499adcc3a9f667590652c5757c0caa703289
99
- # execute_atom :isDisplayed, element
100
- execute :is_element_displayed, id: element.ref
101
- end
102
-
103
- # For Appium
104
- # override
105
- def element_attribute(element, name)
106
- # For W3C in Selenium Client
107
- # execute_atom :getAttribute, element, name
108
- execute :get_element_attribute, id: element.ref, name: name
109
- end
110
-
111
- # For Appium
112
- # override
113
- def find_element_by(how, what, parent = nil)
114
- how, what = convert_locators(how, what)
115
-
116
- id = if parent
117
- execute :find_child_element, { id: parent }, { using: how, value: what }
118
- else
119
- execute :find_element, {}, { using: how, value: what }
120
- end
121
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
122
- end
123
-
124
- # For Appium
125
- # override
126
- def find_elements_by(how, what, parent = nil)
127
- how, what = convert_locators(how, what)
128
-
129
- ids = if parent
130
- execute :find_child_elements, { id: parent }, { using: how, value: what }
131
- else
132
- execute :find_elements, {}, { using: how, value: what }
133
- end
134
-
135
- ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
136
- end
137
-
138
- # For Appium
139
- # @param [Hash] id The id which can get as a response from server
140
- # @return [::Selenium::WebDriver::Element]
141
- def convert_to_element(id)
142
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
143
- end
144
-
145
- # For Appium
146
- # override
147
- # called in 'extend DriverExtensions::HasNetworkConnection'
148
- def network_connection
149
- execute :get_network_connection
150
- end
151
-
152
- # For Appium
153
- # override
154
- # called in 'extend DriverExtensions::HasNetworkConnection'
155
- def network_connection=(type)
156
- execute :set_network_connection, {}, { parameters: { type: type } }
157
- end
158
-
159
- # For Appium
160
- # No implementation for W3C webdriver module
161
- # called in 'extend DriverExtensions::HasLocation'
162
- def location
163
- obj = execute(:get_location) || {}
164
- ::Selenium::WebDriver::Location.new obj['latitude'], obj['longitude'], obj['altitude']
165
- end
166
-
167
- # For Appium
168
- # No implementation for W3C webdriver module
169
- # called in +extend DriverExtensions::HasLocation+
170
- # It has below code as well. We should consider the same context in Selenium 4 as backward compatibility.
171
- #
172
- # def location=(loc)
173
- # # note: Location = Struct.new(:latitude, :longitude, :altitude)
174
- # raise TypeError, "expected #{Location}, got #{loc.inspect}:#{loc.class}" unless loc.is_a?(Location)
175
- #
176
- # @bridge.set_location loc.latitude, loc.longitude, loc.altitude
177
- # end
178
- #
179
- def set_location(lat, lon, alt = 0.0)
180
- loc = { latitude: lat, longitude: lon, altitude: alt }
181
- execute :set_location, {}, { location: loc }
182
- end
183
-
184
- #
185
- # logs
186
- #
187
- # For Appium
188
- # No implementation for W3C webdriver module
189
- def available_log_types
190
- types = execute :get_available_log_types
191
- Array(types).map(&:to_sym)
192
- end
193
-
194
- # For Appium
195
- # No implementation for W3C webdriver module
196
- def log(type)
197
- data = execute :get_log, {}, { type: type.to_s }
198
-
199
- Array(data).map do |l|
200
- begin
201
- ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
202
- rescue KeyError
203
- next
204
- end
205
- end
206
- end
207
-
208
- # For Appium
209
- def log_event(vendor, event)
210
- execute :post_log_event, {}, { vendor: vendor, event: event }
211
- end
212
-
213
- # For Appium
214
- def log_events(type = nil)
215
- args = {}
216
- args['type'] = type unless type.nil?
217
-
218
- execute :get_log_events, {}, args
219
- end
220
-
221
- def take_viewport_screenshot
222
- execute_script('mobile: viewportScreenshot')
223
- end
224
-
225
- def take_element_screenshot(element)
226
- execute :take_element_screenshot, id: element.ref
227
- end
228
-
229
- private
230
-
231
- # Don't convert locators for Appium Client
232
- # TODO: Only for Appium. Ideally, we'd like to keep the selenium-webdriver
233
- def convert_locators(how, what)
234
- # case how
235
- # when 'class name'
236
- # how = 'css selector'
237
- # what = ".#{escape_css(what)}"
238
- # when 'id'
239
- # how = 'css selector'
240
- # what = "##{escape_css(what)}"
241
- # when 'name'
242
- # how = 'css selector'
243
- # what = "*[name='#{escape_css(what)}']"
244
- # when 'tag name'
245
- # how = 'css selector'
246
- # end
247
- [how, what]
248
- end
249
- end # class W3C
250
- end # class Bridge
251
- end # class Base
252
- end # module Core
253
- end # module Appium
@@ -1,110 +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
- module Core
17
- # ref: https://github.com/appium/appium-base-driver/blob/master/lib/mjsonwp/routes.js
18
- module Commands
19
- # Some commands differ for each driver.
20
- COMMAND = {
21
- # common
22
- get_all_sessions: [:get, 'sessions'],
23
- available_contexts: [:get, 'session/:session_id/contexts'],
24
- set_context: [:post, 'session/:session_id/context'],
25
- current_context: [:get, 'session/:session_id/context'],
26
-
27
- touch_actions: [:post, 'session/:session_id/touch/perform'],
28
- multi_touch: [:post, 'session/:session_id/touch/multi/perform'],
29
-
30
- set_immediate_value: [:post, 'session/:session_id/appium/element/:id/value'],
31
- replace_value: [:post, 'session/:session_id/appium/element/:id/replace_value'],
32
-
33
- launch_app: [:post, 'session/:session_id/appium/app/launch'],
34
- close_app: [:post, 'session/:session_id/appium/app/close'],
35
- reset: [:post, 'session/:session_id/appium/app/reset'],
36
- background_app: [:post, 'session/:session_id/appium/app/background'],
37
- app_strings: [:post, 'session/:session_id/appium/app/strings'],
38
-
39
- device_locked?: [:post, 'session/:session_id/appium/device/is_locked'],
40
- unlock: [:post, 'session/:session_id/appium/device/unlock'],
41
- lock: [:post, 'session/:session_id/appium/device/lock'],
42
- device_time: [:get, 'session/:session_id/appium/device/system_time'],
43
- install_app: [:post, 'session/:session_id/appium/device/install_app'],
44
- remove_app: [:post, 'session/:session_id/appium/device/remove_app'],
45
- app_installed?: [:post, 'session/:session_id/appium/device/app_installed'],
46
- activate_app: [:post, 'session/:session_id/appium/device/activate_app'],
47
- terminate_app: [:post, 'session/:session_id/appium/device/terminate_app'],
48
- app_state: [:post, 'session/:session_id/appium/device/app_state'],
49
- shake: [:post, 'session/:session_id/appium/device/shake'],
50
- hide_keyboard: [:post, 'session/:session_id/appium/device/hide_keyboard'],
51
- press_keycode: [:post, 'session/:session_id/appium/device/press_keycode'],
52
- long_press_keycode: [:post, 'session/:session_id/appium/device/long_press_keycode'],
53
- # keyevent is only for Selendroid
54
- keyevent: [:post, 'session/:session_id/appium/device/keyevent'],
55
- push_file: [:post, 'session/:session_id/appium/device/push_file'],
56
- pull_file: [:post, 'session/:session_id/appium/device/pull_file'],
57
- pull_folder: [:post, 'session/:session_id/appium/device/pull_folder'],
58
- get_clipboard: [:post, 'session/:session_id/appium/device/get_clipboard'],
59
- set_clipboard: [:post, 'session/:session_id/appium/device/set_clipboard'],
60
- finger_print: [:post, 'session/:session_id/appium/device/finger_print'],
61
- get_settings: [:get, 'session/:session_id/appium/settings'],
62
- update_settings: [:post, 'session/:session_id/appium/settings'],
63
- stop_recording_screen: [:post, 'session/:session_id/appium/stop_recording_screen'],
64
- start_recording_screen: [:post, 'session/:session_id/appium/start_recording_screen'],
65
- compare_images: [:post, 'session/:session_id/appium/compare_images'],
66
- is_keyboard_shown: [:get, 'session/:session_id/appium/device/is_keyboard_shown'],
67
- execute_driver: [:post, 'session/:session_id/appium/execute_driver'],
68
- post_log_event: [:post, 'session/:session_id/appium/log_event'],
69
- get_log_events: [:post, 'session/:session_id/appium/events']
70
- }.freeze
71
-
72
- COMMAND_ANDROID = {
73
- open_notifications: [:post, 'session/:session_id/appium/device/open_notifications'],
74
- toggle_airplane_mode: [:post, 'session/:session_id/appium/device/toggle_airplane_mode'],
75
- start_activity: [:post, 'session/:session_id/appium/device/start_activity'],
76
- current_activity: [:get, 'session/:session_id/appium/device/current_activity'],
77
- current_package: [:get, 'session/:session_id/appium/device/current_package'],
78
- get_system_bars: [:get, 'session/:session_id/appium/device/system_bars'],
79
- get_display_density: [:get, 'session/:session_id/appium/device/display_density'],
80
- toggle_wifi: [:post, 'session/:session_id/appium/device/toggle_wifi'],
81
- toggle_data: [:post, 'session/:session_id/appium/device/toggle_data'],
82
- toggle_location_services: [:post, 'session/:session_id/appium/device/toggle_location_services'],
83
- end_coverage: [:post, 'session/:session_id/appium/app/end_test_coverage'],
84
- get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'],
85
- get_performance_data: [:post, 'session/:session_id/appium/getPerformanceData'],
86
- get_network_connection: [:get, 'session/:session_id/network_connection'], # defined also in OSS
87
- set_network_connection: [:post, 'session/:session_id/network_connection'], # defined also in OSS
88
-
89
- # only emulator
90
- send_sms: [:post, 'session/:session_id/appium/device/send_sms'],
91
- gsm_call: [:post, 'session/:session_id/appium/device/gsm_call'],
92
- gsm_signal: [:post, 'session/:session_id/appium/device/gsm_signal'],
93
- gsm_voice: [:post, 'session/:session_id/appium/device/gsm_voice'],
94
- set_network_speed: [:post, 'session/:session_id/appium/device/network_speed'],
95
- set_power_capacity: [:post, 'session/:session_id/appium/device/power_capacity'],
96
- set_power_ac: [:post, 'session/:session_id/appium/device/power_ac'],
97
-
98
- # For chromium: https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/server/http_handler.cc
99
- chrome_send_command: [:post, 'session/:session_id/goog/cdp/execute']
100
- }.freeze
101
-
102
- COMMAND_IOS = {
103
- touch_id: [:post, 'session/:session_id/appium/simulator/touch_id'],
104
- toggle_touch_id_enrollment: [:post, 'session/:session_id/appium/simulator/toggle_touch_id_enrollment']
105
- }.freeze
106
-
107
- COMMANDS = {}.merge(COMMAND).merge(COMMAND_ANDROID).merge(COMMAND_IOS).freeze
108
- end # module Commands
109
- end # module Core
110
- end # module Appium
@@ -1,28 +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
- module Core
17
- module Commands
18
- module MJSONWP
19
- COMMANDS = ::Appium::Core::Commands::COMMANDS.merge(::Appium::Core::Base::Commands::OSS).merge(
20
- {
21
- # W3C already has.
22
- take_element_screenshot: [:get, 'session/:session_id/element/:id/screenshot']
23
- }
24
- ).freeze
25
- end # module MJSONWP
26
- end # module Commands
27
- end # module Core
28
- end # Appium
@@ -1,56 +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
- module Core
17
- module Commands
18
- module W3C
19
- COMMANDS = ::Appium::Core::Commands::COMMANDS.merge(::Appium::Core::Base::Commands::W3C).merge(
20
- {
21
- # ::Appium::Core::Base::Commands::OSS has the following commands and Appium also use them.
22
- # Delegated to ::Appium::Core::Base::Commands::OSS commands
23
- status: [:get, 'status'], # https://w3c.github.io/webdriver/#dfn-status
24
- is_element_displayed: [:get, 'session/:session_id/element/:id/displayed'], # hint: https://w3c.github.io/webdriver/#element-displayedness
25
-
26
- get_timeouts: [:get, 'session/:session_id/timeouts'], # https://w3c.github.io/webdriver/#get-timeouts
27
-
28
- # Add OSS commands to W3C commands. We can remove them if we would like to remove them from W3C module.
29
- ### Session capability
30
- get_capabilities: [:get, 'session/:session_id'],
31
-
32
- ### rotatable
33
- get_screen_orientation: [:get, 'session/:session_id/orientation'],
34
- set_screen_orientation: [:post, 'session/:session_id/orientation'],
35
-
36
- get_location: [:get, 'session/:session_id/location'],
37
- set_location: [:post, 'session/:session_id/location'],
38
-
39
- ### For IME
40
- ime_get_available_engines: [:get, 'session/:session_id/ime/available_engines'],
41
- ime_get_active_engine: [:get, 'session/:session_id/ime/active_engine'],
42
- ime_is_activated: [:get, 'session/:session_id/ime/activated'],
43
- ime_deactivate: [:post, 'session/:session_id/ime/deactivate'],
44
- ime_activate_engine: [:post, 'session/:session_id/ime/activate'],
45
-
46
- send_keys_to_active_element: [:post, 'session/:session_id/keys'],
47
-
48
- ### Logs
49
- get_available_log_types: [:get, 'session/:session_id/log/types'],
50
- get_log: [:post, 'session/:session_id/log']
51
- }
52
- ).freeze
53
- end # module W3C
54
- end # module Commands
55
- end # module Core
56
- end # module Appium