appium_lib_core 4.1.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +148 -275
  3. data/README.md +13 -8
  4. data/Rakefile +4 -0
  5. data/appium_lib_core.gemspec +5 -8
  6. data/bin/console +0 -4
  7. data/lib/appium_lib_core/android/device/auth_finger_print.rb +2 -1
  8. data/lib/appium_lib_core/android/device.rb +4 -4
  9. data/lib/appium_lib_core/common/base/bridge.rb +291 -90
  10. data/lib/appium_lib_core/common/base/capabilities.rb +10 -3
  11. data/lib/appium_lib_core/common/base/device_ime.rb +49 -0
  12. data/lib/appium_lib_core/common/base/driver.rb +225 -187
  13. data/lib/appium_lib_core/common/base/driver_settings.rb +51 -0
  14. data/lib/appium_lib_core/common/base/has_location.rb +80 -0
  15. data/lib/appium_lib_core/common/base/has_network_connection.rb +56 -0
  16. data/lib/appium_lib_core/common/base/http_default.rb +1 -3
  17. data/lib/appium_lib_core/common/base/remote_status.rb +31 -0
  18. data/lib/appium_lib_core/common/base/rotable.rb +54 -0
  19. data/lib/appium_lib_core/common/base/screenshot.rb +6 -6
  20. data/lib/appium_lib_core/common/base/search_context.rb +20 -5
  21. data/lib/appium_lib_core/common/base.rb +1 -3
  22. data/lib/appium_lib_core/common/command.rb +255 -4
  23. data/lib/appium_lib_core/common/device/app_management.rb +2 -14
  24. data/lib/appium_lib_core/common/device/image_comparison.rb +12 -4
  25. data/lib/appium_lib_core/common/device/keyevent.rb +4 -4
  26. data/lib/appium_lib_core/common/{command/mjsonwp.rb → device/orientation.rb} +14 -11
  27. data/lib/appium_lib_core/common/device/touch_actions.rb +2 -0
  28. data/lib/appium_lib_core/common/device/value.rb +6 -6
  29. data/lib/appium_lib_core/common/error.rb +4 -1
  30. data/lib/appium_lib_core/common/log.rb +4 -1
  31. data/lib/appium_lib_core/common/touch_action/multi_touch.rb +19 -0
  32. data/lib/appium_lib_core/common/touch_action/touch_actions.rb +16 -2
  33. data/lib/appium_lib_core/common/wait.rb +38 -6
  34. data/lib/appium_lib_core/device.rb +1 -5
  35. data/lib/appium_lib_core/driver.rb +42 -50
  36. data/lib/appium_lib_core/{patch.rb → element.rb} +66 -9
  37. data/lib/appium_lib_core/ios/uiautomation/patch.rb +1 -1
  38. data/lib/appium_lib_core/{common/base/command.rb → mac2/bridge.rb} +9 -8
  39. data/lib/appium_lib_core/mac2/device/screen.rb +48 -0
  40. data/lib/appium_lib_core/mac2/device.rb +92 -0
  41. data/lib/appium_lib_core/mac2.rb +17 -0
  42. data/lib/appium_lib_core/version.rb +2 -2
  43. data/lib/appium_lib_core.rb +2 -5
  44. metadata +29 -82
  45. data/.github/ISSUE_TEMPLATE/issue-report.md +0 -29
  46. data/.github/contributing.md +0 -26
  47. data/.github/issue_template.md +0 -20
  48. data/.github/workflows/unittest.yml +0 -68
  49. data/.gitignore +0 -18
  50. data/.rubocop.yml +0 -58
  51. data/azure-pipelines.yml +0 -15
  52. data/ci-jobs/functional/android_setup.yml +0 -3
  53. data/ci-jobs/functional/ios_setup.yml +0 -7
  54. data/ci-jobs/functional/publish_test_result.yml +0 -18
  55. data/ci-jobs/functional/run_appium.yml +0 -25
  56. data/ci-jobs/functional/start-emulator.sh +0 -26
  57. data/ci-jobs/functional_test.yml +0 -298
  58. data/docs/mobile_command.md +0 -34
  59. data/lib/appium_lib_core/common/base/bridge/mjsonwp.rb +0 -81
  60. data/lib/appium_lib_core/common/base/bridge/w3c.rb +0 -252
  61. data/lib/appium_lib_core/common/command/common.rb +0 -110
  62. data/lib/appium_lib_core/common/command/w3c.rb +0 -56
  63. data/release_notes.md +0 -816
  64. data/script/commands.rb +0 -200
@@ -1,298 +0,0 @@
1
- # jobs for functional test
2
- parameters:
3
- vmImage: 'macOS-10.15'
4
- vmImageForIOS: 'macOS-10.15' # Not sure the reason, but macOS 10.14 instance raises no info.plist error
5
- xcodeForIOS: 12.2
6
- xcodeForTVOS: 12.2
7
- androidSDK: 30
8
- appiumVersion: 'beta'
9
- ignoreVersionSkip: true
10
- CI: true
11
-
12
-
13
- jobs:
14
- # Run unit tests on different Node versions
15
- - job: func_test_ios_base
16
- pool:
17
- vmImage: ${{ parameters.vmImageForIOS }}
18
- variables:
19
- CI: ${{ parameters.ci }}
20
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
21
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
22
- steps:
23
- - template: ./functional/ios_setup.yml
24
- parameters:
25
- xcodeVersion: ${{ parameters.xcodeForIOS }}
26
- - template: ./functional/run_appium.yml
27
- - script: bundle exec rake test:func:ios TESTS=test/functional/ios/driver_test.rb,test/functional/ios/patch_test.rb
28
- displayName: Run tests func_test_ios_base
29
- - template: ./functional/publish_test_result.yml
30
-
31
- - job: func_test_ios_webdriver1
32
- pool:
33
- vmImage: ${{ parameters.vmImageForIOS }}
34
- variables:
35
- CI: ${{ parameters.ci }}
36
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
37
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
38
- steps:
39
- - template: ./functional/ios_setup.yml
40
- parameters:
41
- xcodeVersion: ${{ parameters.xcodeForIOS }}
42
- - template: ./functional/run_appium.yml
43
- - script: bundle exec rake test:func:ios TESTS=test/functional/ios/webdriver/create_session_test.rb,test/functional/ios/webdriver/w3c_actions_test.rb
44
- displayName: Run tests func_test_ios_webdriver1
45
- - template: ./functional/publish_test_result.yml
46
-
47
- - job: func_test_ios_webdriver2
48
- pool:
49
- vmImage: ${{ parameters.vmImageForIOS }}
50
- variables:
51
- CI: ${{ parameters.ci }}
52
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
53
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
54
- steps:
55
- - template: ./functional/ios_setup.yml
56
- parameters:
57
- xcodeVersion: ${{ parameters.xcodeForIOS }}
58
- - template: ./functional/run_appium.yml
59
- - script: bundle exec rake test:func:ios TESTS=test/functional/ios/webdriver/device_test.rb
60
- displayName: Run tests func_test_ios_webdriver2
61
- - template: ./functional/publish_test_result.yml
62
-
63
- - job: func_test_ios_ios1
64
- pool:
65
- vmImage: ${{ parameters.vmImageForIOS }}
66
- variables:
67
- CI: ${{ parameters.ci }}
68
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
69
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
70
- steps:
71
- - template: ./functional/ios_setup.yml
72
- parameters:
73
- xcodeVersion: ${{ parameters.xcodeForIOS }}
74
- - template: ./functional/run_appium.yml
75
- - script: bundle exec rake test:func:ios TESTS=test/functional/ios/ios/device_test.rb
76
- displayName: Run tests func_test_ios_ios1
77
- - template: ./functional/publish_test_result.yml
78
-
79
- - job: func_test_ios_ios2
80
- pool:
81
- vmImage: ${{ parameters.vmImageForIOS }}
82
- variables:
83
- CI: ${{ parameters.ci }}
84
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
85
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
86
- steps:
87
- - template: ./functional/ios_setup.yml
88
- parameters:
89
- xcodeVersion: ${{ parameters.xcodeForIOS }}
90
- - template: ./functional/run_appium.yml
91
- - script: bundle exec rake test:func:ios TESTS=test/functional/ios/ios/device_wda_attachment_test.rb,test/functional/ios/ios/search_context_test.rb
92
- displayName: Run tests func_test_ios_ios2
93
- - template: ./functional/publish_test_result.yml
94
-
95
- - job: func_test_ios_ios3
96
- pool:
97
- vmImage: ${{ parameters.vmImageForIOS }}
98
- variables:
99
- CI: ${{ parameters.ci }}
100
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
101
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
102
- steps:
103
- - template: ./functional/ios_setup.yml
104
- parameters:
105
- xcodeVersion: ${{ parameters.xcodeForIOS }}
106
- - script: brew install ffmpeg && brew tap wix/brew && brew install wix/brew/applesimutils
107
- displayName: Install ffmpeg and applesimutils
108
- - template: ./functional/run_appium.yml
109
- - script: bundle exec rake test:func:ios TESTS=test/functional/ios/ios/mjpeg_server_test.rb,test/functional/ios/ios/mobile_commands_test.rb
110
- displayName: Run tests func_test_ios_ios3
111
- - template: ./functional/publish_test_result.yml
112
-
113
- - job: func_test_ios_tvos
114
- pool:
115
- vmImage: ${{ parameters.vmImage }}
116
- variables:
117
- CI: ${{ parameters.ci }}
118
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
119
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
120
- steps:
121
- - template: ./functional/ios_setup.yml
122
- parameters:
123
- xcodeVersion: ${{ parameters.xcodeForTVOS }}
124
- - template: ./functional/run_appium.yml
125
- - script: bundle exec rake test:func:ios TESTS=test/functional/ios/tv_driver_test.rb
126
- displayName: Run tests func_test_ios_tvos
127
- - template: ./functional/publish_test_result.yml
128
-
129
- # Skip since opencv4nodejs fails to install on the macOS instance
130
- # - job: func_test_ios_opencv
131
- # pool:
132
- # vmImage: ${{ parameters.vmImageForIOS }}
133
- # variables:
134
- # CI: ${{ parameters.ci }}
135
- # IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
136
- # APPIUM_VERSION: ${{ parameters.appiumVersion }}
137
- # steps:
138
- # - template: ./functional/ios_setup.yml
139
- # parameters:
140
- # xcodeVersion: ${{ parameters.xcodeForIOS }}
141
- # - template: ./functional/run_appium.yml
142
- # - script: npm install -g opencv4nodejs@5.1.0
143
- # displayName: Install opencv4nodejs@5.1.0
144
- # - script: bundle exec rake test:func:ios test/functional/ios/ios/image_comparison_test.rb
145
- # displayName: Run tests
146
- # - template: ./functional/publish_test_result.yml
147
-
148
-
149
- - job: func_test_android_base
150
- pool:
151
- vmImage: ${{ parameters.vmImage }}
152
- variables:
153
- CI: ${{ parameters.ci }}
154
- ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
155
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
156
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
157
- strategy:
158
- matrix:
159
- uiautomator2:
160
- AUTOMATION_NAME_DROID: 'uiautomator2'
161
- espresso:
162
- AUTOMATION_NAME_DROID: 'espresso'
163
- steps:
164
- - template: ./functional/android_setup.yml
165
- - template: ./functional/run_appium.yml
166
- - script: bundle exec rake test:func:android TESTS=test/functional/android/driver_test.rb,test/functional/android/patch_test.rb
167
- displayName: Run tests func_test_android_base
168
- - template: ./functional/publish_test_result.yml
169
-
170
- - job: func_test_android_webdriver
171
- pool:
172
- vmImage: ${{ parameters.vmImage }}
173
- variables:
174
- CI: ${{ parameters.ci }}
175
- ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
176
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
177
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
178
- strategy:
179
- matrix:
180
- uiautomator2:
181
- AUTOMATION_NAME_DROID: 'uiautomator2'
182
- espresso:
183
- AUTOMATION_NAME_DROID: 'espresso'
184
- steps:
185
- - template: ./functional/android_setup.yml
186
- - template: ./functional/run_appium.yml
187
- - script: bundle exec rake test:func:android TESTS=test/functional/android/webdriver/create_session_test.rb,test/functional/android/webdriver/device_test.rb,test/functional/android/webdriver/w3c_actions_test.rb
188
- displayName: Run tests func_test_android_webdriver
189
- - template: ./functional/publish_test_result.yml
190
-
191
- - job: func_test_android_android1
192
- pool:
193
- vmImage: ${{ parameters.vmImage }}
194
- variables:
195
- CI: ${{ parameters.ci }}
196
- ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
197
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
198
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
199
- strategy:
200
- matrix:
201
- uiautomator2:
202
- AUTOMATION_NAME_DROID: 'uiautomator2'
203
- espresso:
204
- AUTOMATION_NAME_DROID: 'espresso'
205
- steps:
206
- - template: ./functional/android_setup.yml
207
- - template: ./functional/run_appium.yml
208
- - script: bundle exec rake test:func:android TESTS=test/functional/android/android/device_test.rb
209
- displayName: Run tests func_test_android_android1
210
- - template: ./functional/publish_test_result.yml
211
-
212
- - job: func_test_android_android2
213
- pool:
214
- vmImage: ${{ parameters.vmImage }}
215
- variables:
216
- CI: ${{ parameters.ci }}
217
- ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
218
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
219
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
220
- strategy:
221
- matrix:
222
- uiautomator2:
223
- AUTOMATION_NAME_DROID: 'uiautomator2'
224
- espresso:
225
- AUTOMATION_NAME_DROID: 'espresso'
226
- steps:
227
- - template: ./functional/android_setup.yml
228
- - template: ./functional/run_appium.yml
229
- - script: bundle exec rake test:func:android TESTS=test/functional/android/android/search_context_test.rb,test/functional/android/android/mjpeg_server_test.rb
230
- displayName: Run tests func_test_android_android2
231
- - template: ./functional/publish_test_result.yml
232
-
233
- - job: func_test_android_android3
234
- pool:
235
- vmImage: ${{ parameters.vmImage }}
236
- variables:
237
- CI: ${{ parameters.ci }}
238
- ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
239
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
240
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
241
- strategy:
242
- matrix:
243
- uiautomator2:
244
- AUTOMATION_NAME_DROID: 'uiautomator2'
245
- espresso:
246
- AUTOMATION_NAME_DROID: 'espresso'
247
- steps:
248
- - template: ./functional/android_setup.yml
249
- - template: ./functional/run_appium.yml
250
- - script: bundle exec rake test:func:android TESTS=test/functional/android/android/device_data_test.rb
251
- displayName: Run tests func_test_android_android3
252
- - template: ./functional/publish_test_result.yml
253
-
254
- - job: func_test_android_mobile_command_espresso
255
- pool:
256
- vmImage: ${{ parameters.vmImage }}
257
- variables:
258
- CI: ${{ parameters.ci }}
259
- ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
260
- AUTOMATION_NAME_DROID: espresso
261
- IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
262
- APPIUM_VERSION: ${{ parameters.appiumVersion }}
263
- strategy:
264
- matrix:
265
- uiautomator2:
266
- AUTOMATION_NAME_DROID: 'uiautomator2'
267
- espresso:
268
- AUTOMATION_NAME_DROID: 'espresso'
269
- steps:
270
- - template: ./functional/android_setup.yml
271
- - template: ./functional/run_appium.yml
272
- - script: bundle exec rake test:func:android TESTS=test/functional/android/android/mobile_commands_test.rb
273
- displayName: Run tests func_test_android_mobile_command_espresso
274
- - template: ./functional/publish_test_result.yml
275
-
276
- # Skip since opencv4nodejs fails to install on the macOS instance
277
- # - job: func_test_android_opencv
278
- # pool:
279
- # vmImage: ${{ parameters.vmImage }}
280
- # variables:
281
- # CI: ${{ parameters.ci }}
282
- # ANDROID_SDK_VERSION: ${{ parameters.androidSDK }}
283
- # IGNORE_VERSION_SKIP: ${{ parameters.ignoreVersionSkip }}
284
- # APPIUM_VERSION: ${{ parameters.appiumVersion }}
285
- # strategy:
286
- # matrix:
287
- # uiautomator2:
288
- # AUTOMATION_NAME_DROID: 'uiautomator2'
289
- # espresso:
290
- # AUTOMATION_NAME_DROID: 'espresso'
291
- # steps:
292
- # - template: ./functional/android_setup.yml
293
- # - template: ./functional/run_appium.yml
294
- # - script: npm install -g opencv4nodejs@5.1.0
295
- # displayName: Install opencv4nodejs@5.1.0
296
- # - script: bundle exec rake test:func:android TESTS=test/functional/android/android/image_comparison_test.rb
297
- # displayName: Run tests func_test_android_opencv
298
- # - template: ./functional/publish_test_result.yml
@@ -1,34 +0,0 @@
1
- # Mobile Command
2
-
3
- Appium has `mobile:` command.
4
- We can invoke them via `execute_script` command with `mobile:` arguments.
5
-
6
- - root:
7
- - https://github.com/appium/appium/blob/master/commands-yml/commands/mobile-command.yml
8
- - Android:
9
- - https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android
10
- - iOS:
11
- - https://github.com/appium/appium/tree/master/docs/en/writing-running-appium/ios
12
-
13
-
14
- ```ruby
15
- # Android shell : https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/android-shell.md
16
- args = { command: 'echo', args: 'list' }
17
- @driver.execute_script 'mobile: shell', args # Run `adb shell echo 'list'`
18
-
19
- # iOS performance : https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios/ios-xctest-performance.md
20
- args = { timeout: 60 * 1000, profileName: 'Activity Monitor' }
21
- @driver.execute_script 'mobile: startPerfRecord', args
22
-
23
- @driver.execute_script 'mobile: stopPerfRecord', { profileName: 'Activity Monitor' }
24
- ```
25
-
26
- Mobile commands return their error messages. As a selenium client, it usually handles as unknown error.
27
- To handle it, we would recommend you to handle the error based on the error message.
28
-
29
- ```ruby
30
- error = assert_raises ::Selenium::WebDriver::Error::UnknownError do
31
- @driver.execute_script 'mobile: scrollToPage', { element: el.ref, scrollToPage: -100 }
32
- end
33
- assert error.message.include? 'be a non-negative integer'
34
- ```
@@ -1,81 +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 MJSONWP < ::Selenium::WebDriver::Remote::OSS::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
-
36
- def commands(command)
37
- ::Appium::Core::Commands::MJSONWP::COMMANDS[command]
38
- end
39
-
40
- # Returns all available sessions on the Appium server instance
41
- def sessions
42
- execute :get_all_sessions
43
- end
44
-
45
- # For Appium
46
- def log_event(vendor, event)
47
- execute :post_log_event, {}, { vendor: vendor, event: event }
48
- end
49
-
50
- # For Appium
51
- def log_events(type = nil)
52
- args = {}
53
- args['type'] = type unless type.nil?
54
-
55
- execute :get_log_events, {}, args
56
- end
57
-
58
- def take_element_screenshot(element)
59
- execute :take_element_screenshot, id: element.ref
60
- end
61
-
62
- def take_viewport_screenshot
63
- # TODO: this hasn't been supported by Espresso driver
64
- execute_script('mobile: viewportScreenshot')
65
- end
66
-
67
- def send_actions(_data)
68
- raise Error::UnsupportedOperationError, '#send_actions has not been supported in MJSONWP'
69
- end
70
-
71
- # For Appium
72
- # @param [Hash] id The id which can get as a response from server
73
- # @return [::Selenium::WebDriver::Element]
74
- def convert_to_element(id)
75
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
76
- end
77
- end # class MJSONWP
78
- end # class Bridge
79
- end # class Base
80
- end # module Core
81
- end # module Appium
@@ -1,252 +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
-
36
- def commands(command)
37
- ::Appium::Core::Commands::W3C::COMMANDS[command]
38
- end
39
-
40
- # Returns all available sessions on the Appium server instance
41
- def sessions
42
- execute :get_all_sessions
43
- end
44
-
45
- # Perform touch actions for W3C module.
46
- # Generate +touch+ pointer action here and users can use this via +driver.action+
47
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/W3CActionBuilder.html
48
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/PointerActions.html
49
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
50
- #
51
- # 'mouse' action is by default in the Ruby client. Appium server force the +mouse+ action to +touch+ once in
52
- # the server side. So we don't consider the case.
53
- #
54
- # @example
55
- #
56
- # element = @driver.find_element(:id, "some id")
57
- # @driver.action.click(element).perform # The 'click' is a part of 'PointerActions'
58
- #
59
- def action(async = false)
60
- # Used for default duration of each touch actions
61
- # Override from 250 milliseconds to 50 milliseconds
62
- action_builder = super
63
- action_builder.default_move_duration = 0.05
64
- action_builder
65
- end
66
-
67
- # Port from MJSONWP
68
- def get_timeouts
69
- execute :get_timeouts
70
- end
71
-
72
- # Port from MJSONWP
73
- def session_capabilities
74
- ::Selenium::WebDriver::Remote::W3C::Capabilities.json_create execute(:get_capabilities)
75
- end
76
-
77
- # Port from MJSONWP
78
- def send_keys_to_active_element(key)
79
- text = ::Selenium::WebDriver::Keys.encode(key).join('')
80
- execute :send_keys_to_active_element, {}, { value: text.split(//) }
81
- end
82
-
83
- # For Appium
84
- # override
85
- def page_source
86
- # For W3C
87
- # execute_script('var source = document.documentElement.outerHTML;' \
88
- # 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \
89
- # 'return source;')
90
- execute :get_page_source
91
- end
92
-
93
- # For Appium
94
- # override
95
- def element_displayed?(element)
96
- # For W3C
97
- # https://github.com/SeleniumHQ/selenium/commit/b618499adcc3a9f667590652c5757c0caa703289
98
- # execute_atom :isDisplayed, element
99
- execute :is_element_displayed, id: element.ref
100
- end
101
-
102
- # For Appium
103
- # override
104
- def element_attribute(element, name)
105
- # For W3C in Selenium Client
106
- # execute_atom :getAttribute, element, name
107
- execute :get_element_attribute, id: element.ref, name: name
108
- end
109
-
110
- # For Appium
111
- # override
112
- def find_element_by(how, what, parent = nil)
113
- how, what = convert_locators(how, what)
114
-
115
- id = if parent
116
- execute :find_child_element, { id: parent }, { using: how, value: what }
117
- else
118
- execute :find_element, {}, { using: how, value: what }
119
- end
120
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
121
- end
122
-
123
- # For Appium
124
- # override
125
- def find_elements_by(how, what, parent = nil)
126
- how, what = convert_locators(how, what)
127
-
128
- ids = if parent
129
- execute :find_child_elements, { id: parent }, { using: how, value: what }
130
- else
131
- execute :find_elements, {}, { using: how, value: what }
132
- end
133
-
134
- ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
135
- end
136
-
137
- # For Appium
138
- # @param [Hash] id The id which can get as a response from server
139
- # @return [::Selenium::WebDriver::Element]
140
- def convert_to_element(id)
141
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
142
- end
143
-
144
- # For Appium
145
- # override
146
- # called in 'extend DriverExtensions::HasNetworkConnection'
147
- def network_connection
148
- execute :get_network_connection
149
- end
150
-
151
- # For Appium
152
- # override
153
- # called in 'extend DriverExtensions::HasNetworkConnection'
154
- def network_connection=(type)
155
- execute :set_network_connection, {}, { parameters: { type: type } }
156
- end
157
-
158
- # For Appium
159
- # No implementation for W3C webdriver module
160
- # called in 'extend DriverExtensions::HasLocation'
161
- def location
162
- obj = execute(:get_location) || {}
163
- ::Selenium::WebDriver::Location.new obj['latitude'], obj['longitude'], obj['altitude']
164
- end
165
-
166
- # For Appium
167
- # No implementation for W3C webdriver module
168
- # called in +extend DriverExtensions::HasLocation+
169
- # It has below code as well. We should consider the same context in Selenium 4 as backward compatibility.
170
- #
171
- # def location=(loc)
172
- # # note: Location = Struct.new(:latitude, :longitude, :altitude)
173
- # raise TypeError, "expected #{Location}, got #{loc.inspect}:#{loc.class}" unless loc.is_a?(Location)
174
- #
175
- # @bridge.set_location loc.latitude, loc.longitude, loc.altitude
176
- # end
177
- #
178
- def set_location(lat, lon, alt = 0.0)
179
- loc = { latitude: lat, longitude: lon, altitude: alt }
180
- execute :set_location, {}, { location: loc }
181
- end
182
-
183
- #
184
- # logs
185
- #
186
- # For Appium
187
- # No implementation for W3C webdriver module
188
- def available_log_types
189
- types = execute :get_available_log_types
190
- Array(types).map(&:to_sym)
191
- end
192
-
193
- # For Appium
194
- # No implementation for W3C webdriver module
195
- def log(type)
196
- data = execute :get_log, {}, { type: type.to_s }
197
-
198
- Array(data).map do |l|
199
- begin
200
- ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
201
- rescue KeyError
202
- next
203
- end
204
- end
205
- end
206
-
207
- # For Appium
208
- def log_event(vendor, event)
209
- execute :post_log_event, {}, { vendor: vendor, event: event }
210
- end
211
-
212
- # For Appium
213
- def log_events(type = nil)
214
- args = {}
215
- args['type'] = type unless type.nil?
216
-
217
- execute :get_log_events, {}, args
218
- end
219
-
220
- def take_viewport_screenshot
221
- execute_script('mobile: viewportScreenshot')
222
- end
223
-
224
- def take_element_screenshot(element)
225
- execute :take_element_screenshot, id: element.ref
226
- end
227
-
228
- private
229
-
230
- # Don't convert locators for Appium Client
231
- # TODO: Only for Appium. Ideally, we'd like to keep the selenium-webdriver
232
- def convert_locators(how, what)
233
- # case how
234
- # when 'class name'
235
- # how = 'css selector'
236
- # what = ".#{escape_css(what)}"
237
- # when 'id'
238
- # how = 'css selector'
239
- # what = "##{escape_css(what)}"
240
- # when 'name'
241
- # how = 'css selector'
242
- # what = "*[name='#{escape_css(what)}']"
243
- # when 'tag name'
244
- # how = 'css selector'
245
- # end
246
- [how, what]
247
- end
248
- end # class W3C
249
- end # class Bridge
250
- end # class Base
251
- end # module Core
252
- end # module Appium