appium_lib_core 5.0.0.beta1 → 5.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -79,7 +79,7 @@ module Appium
79
79
  end
80
80
 
81
81
  def create_bridge_command(method, &block)
82
- ::Appium::Core::Base::Bridge::W3C.class_eval do
82
+ ::Appium::Core::Base::Bridge.class_eval do
83
83
  undef_method method if method_defined? method
84
84
  block_given? ? class_eval(&block) : define_method(method) { execute method }
85
85
  end
@@ -12,16 +12,12 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # rubocop:disable Style/ClassAndModuleChildren
16
15
  module Appium
17
16
  module Core
18
17
  # Implement useful features for element.
19
18
  # Patch for Selenium Webdriver.
20
- class Selenium::WebDriver::Element
21
- # To extend Appium related SearchContext into ::Selenium::WebDriver::Element
19
+ class Element < ::Selenium::WebDriver::Element
22
20
  include ::Appium::Core::Base::SearchContext
23
-
24
- # TODO: Probably can remove own TakesScreenshot since Selenium 4
25
21
  include ::Appium::Core::Base::TakesScreenshot
26
22
 
27
23
  # Returns the value of attributes like below. Read each platform to know more details.
@@ -152,7 +148,6 @@ module Appium
152
148
  end
153
149
  File.open(png_path, 'wb') { |f| f << screenshot_as(:png) }
154
150
  end
155
- end
151
+ end # class Element
156
152
  end # module Core
157
153
  end # module Appium
158
- # rubocop:enable Style/ClassAndModuleChildren
@@ -21,7 +21,7 @@ module Appium
21
21
  # will trigger as soon as the file is required. in contrast a method
22
22
  # will trigger only when invoked.
23
23
  def self.patch_webdriver_element
24
- ::Selenium::WebDriver::Element.class_eval do
24
+ ::Appium::Core::Element.class_eval do
25
25
  # Cross platform way of entering text into a textfield
26
26
  def type(text, driver)
27
27
  driver.execute_script %(au.getElement('#{ref}').setValue('#{text}');)
@@ -14,7 +14,7 @@
14
14
 
15
15
  module Appium
16
16
  module Core
17
- VERSION = '5.0.0.beta1' unless defined? ::Appium::Core::VERSION
18
- DATE = '2021-03-21' unless defined? ::Appium::Core::DATE
17
+ VERSION = '5.0.0.beta2' unless defined? ::Appium::Core::VERSION
18
+ DATE = '2021-04-13' unless defined? ::Appium::Core::DATE
19
19
  end
20
20
  end
data/script/commands.rb CHANGED
@@ -23,17 +23,13 @@ module Script
23
23
 
24
24
  # Set commands implemented in this core library.
25
25
  #
26
- # - implemented_w3c_commands: All commands include ::Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS
26
+ # - implemented_w3c_commands: All commands include ::Selenium::WebDriver::Remote::Bridge::COMMANDS
27
27
  # - implemented_core_commands: All commands except for selenium-webdriver's commands
28
- # - webdriver_w3c_commands: ::Selenium::WebDriver::Remote::W3C::Bridge::COMMANDS
29
28
  #
30
29
  def initialize
31
30
  @spec_commands = nil
32
31
 
33
- @implemented_w3c_commands = convert_driver_commands Appium::Core::Commands::W3C::COMMANDS
34
32
  @implemented_core_commands = convert_driver_commands Appium::Core::Commands::COMMANDS
35
-
36
- @webdriver_w3c_commands = convert_driver_commands Appium::Core::Base::Commands::W3C
37
33
  end
38
34
 
39
35
  # Get the bellow url's file.
@@ -95,13 +91,6 @@ module Script
95
91
  result
96
92
  end
97
93
 
98
- def diff_webdriver_w3c
99
- result = compare_commands(@spec_commands, @webdriver_w3c_commands)
100
- white_list.each { |v| result.delete v }
101
- mjsonwp_spec.each { |v| result.delete v }
102
- result
103
- end
104
-
105
94
  def compare_commands(command1, with_command2)
106
95
  return {} if command1.nil?
107
96
  return command1 if with_command2.nil?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appium_lib_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.beta1
4
+ version: 5.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuaki MATSUO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-21 00:00:00.000000000 Z
11
+ date: 2021-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 1.11.0
131
+ version: 1.12.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 1.11.0
138
+ version: 1.12.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: appium_thor
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -256,9 +256,7 @@ files:
256
256
  - lib/appium_lib_core/common.rb
257
257
  - lib/appium_lib_core/common/base.rb
258
258
  - lib/appium_lib_core/common/base/bridge.rb
259
- - lib/appium_lib_core/common/base/bridge/w3c.rb
260
259
  - lib/appium_lib_core/common/base/capabilities.rb
261
- - lib/appium_lib_core/common/base/command.rb
262
260
  - lib/appium_lib_core/common/base/driver.rb
263
261
  - lib/appium_lib_core/common/base/has_location.rb
264
262
  - lib/appium_lib_core/common/base/has_network_connection.rb
@@ -269,8 +267,6 @@ files:
269
267
  - lib/appium_lib_core/common/base/screenshot.rb
270
268
  - lib/appium_lib_core/common/base/search_context.rb
271
269
  - lib/appium_lib_core/common/command.rb
272
- - lib/appium_lib_core/common/command/common.rb
273
- - lib/appium_lib_core/common/command/w3c.rb
274
270
  - lib/appium_lib_core/common/device/app_management.rb
275
271
  - lib/appium_lib_core/common/device/app_state.rb
276
272
  - lib/appium_lib_core/common/device/battery_status.rb
@@ -299,6 +295,7 @@ files:
299
295
  - lib/appium_lib_core/common/ws/websocket.rb
300
296
  - lib/appium_lib_core/device.rb
301
297
  - lib/appium_lib_core/driver.rb
298
+ - lib/appium_lib_core/element.rb
302
299
  - lib/appium_lib_core/ios.rb
303
300
  - lib/appium_lib_core/ios/device.rb
304
301
  - lib/appium_lib_core/ios/device/clipboard.rb
@@ -315,7 +312,6 @@ files:
315
312
  - lib/appium_lib_core/mac2/bridge.rb
316
313
  - lib/appium_lib_core/mac2/device.rb
317
314
  - lib/appium_lib_core/mac2/device/screen.rb
318
- - lib/appium_lib_core/patch.rb
319
315
  - lib/appium_lib_core/version.rb
320
316
  - lib/appium_lib_core/windows.rb
321
317
  - lib/appium_lib_core/windows/bridge.rb
@@ -1,348 +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::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
- # TODO: For compatibility. Should remove.
38
- def dialect
39
- :w3c
40
- end
41
-
42
- # TODO: fixme
43
- def browser
44
- @browser ||= begin
45
- name = @capabilities.browser_name
46
- name ? name.tr(' ', '_').downcase.to_sym : 'unknown'
47
- rescue KeyError
48
- 'unknown'
49
- end
50
- end
51
-
52
- # Prefix for extra capability defined by W3C
53
- APPIUM_PREFIX = 'appium:'
54
-
55
- # Override
56
- # Creates session handling both OSS and W3C dialects.
57
- #
58
- # @param [::Selenium::WebDriver::Remote::Capabilities, Hash] desired_capabilities A capability
59
- # @return [::Selenium::WebDriver::Remote::Capabilities]
60
- #
61
- # @example
62
- #
63
- # opts = {
64
- # caps: {
65
- # platformName: :ios,
66
- # automationName: 'XCUITest',
67
- # app: 'test/functional/app/UICatalog.app.zip',
68
- # platformVersion: '11.4',
69
- # deviceName: 'iPhone Simulator',
70
- # useNewWDA: true,
71
- # },
72
- # appium_lib: {
73
- # wait: 30
74
- # }
75
- # }
76
- # core = ::Appium::Core.for(caps)
77
- # driver = core.start_driver #=> driver.dialect == :w3c if the Appium server support W3C.
78
- #
79
- def create_session(desired_capabilities)
80
- caps = add_appium_prefix(desired_capabilities)
81
- response = execute(:new_session, {}, { capabilities: { firstMatch: [caps] } })
82
-
83
- @session_id = response['sessionId']
84
- capabilities = response['capabilities']
85
-
86
- raise ::Selenium::WebDriver::Error::WebDriverError, 'no sessionId in returned payload' unless @session_id
87
-
88
- @capabilities = json_create(capabilities)
89
- end
90
-
91
- # Append +appium:+ prefix for Appium following W3C spec
92
- # https://www.w3.org/TR/webdriver/#dfn-validate-capabilities
93
- #
94
- # @param [::Selenium::WebDriver::Remote::Capabilities, Hash] capabilities A capability
95
- # @return [::Selenium::WebDriver::Remote::Capabilities]
96
- def add_appium_prefix(capabilities)
97
- w3c_capabilities = ::Selenium::WebDriver::Remote::Capabilities.new
98
-
99
- capabilities = capabilities.__send__(:capabilities) unless capabilities.is_a?(Hash)
100
-
101
- capabilities.each do |name, value|
102
- next if value.nil?
103
- next if value.is_a?(String) && value.empty?
104
-
105
- capability_name = name.to_s
106
- w3c_name = extension_prefix?(capability_name) ? name : "#{APPIUM_PREFIX}#{capability_name}"
107
-
108
- w3c_capabilities[w3c_name] = value
109
- end
110
-
111
- w3c_capabilities
112
- end
113
-
114
- private
115
-
116
- def camel_case(str)
117
- str.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
118
- end
119
-
120
- def extension_prefix?(capability_name)
121
- snake_cased_capability_names = ::Selenium::WebDriver::Remote::Capabilities::KNOWN.map(&:to_s)
122
- camel_cased_capability_names = snake_cased_capability_names.map { |v| camel_case(v) }
123
-
124
- # Check 'EXTENSION_CAPABILITY_PATTERN'
125
- snake_cased_capability_names.include?(capability_name) ||
126
- camel_cased_capability_names.include?(capability_name) ||
127
- capability_name.match(':')
128
- end
129
-
130
- def json_create(value)
131
- @dialect = :w3c
132
- ::Selenium::WebDriver::Remote::Capabilities.json_create(value)
133
- end
134
-
135
- public
136
-
137
- def commands(command)
138
- ::Appium::Core::Commands::W3C::COMMANDS[command]
139
- end
140
-
141
- # Returns all available sessions on the Appium server instance
142
- def sessions
143
- execute :get_all_sessions
144
- end
145
-
146
- def status
147
- execute :status
148
- end
149
-
150
- # Perform touch actions for W3C module.
151
- # Generate +touch+ pointer action here and users can use this via +driver.action+
152
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/W3CActionBuilder.html
153
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/PointerActions.html
154
- # - https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
155
- #
156
- # 'mouse' action is by default in the Ruby client. Appium server force the +mouse+ action to +touch+ once in
157
- # the server side. So we don't consider the case.
158
- #
159
- # @example
160
- #
161
- # element = @driver.find_element(:id, "some id")
162
- # @driver.action.click(element).perform # The 'click' is a part of 'PointerActions'
163
- #
164
- def action(async = false)
165
- # Used for default duration of each touch actions
166
- # Override from 250 milliseconds to 50 milliseconds
167
- action_builder = super
168
- action_builder.default_move_duration = 0.05
169
- action_builder
170
- end
171
-
172
- # Port from MJSONWP
173
- def get_timeouts
174
- execute :get_timeouts
175
- end
176
-
177
- # Port from MJSONWP
178
- def session_capabilities
179
- ::Selenium::WebDriver::Remote::Capabilities.json_create execute(:get_capabilities)
180
- end
181
-
182
- # Port from MJSONWP
183
- def send_keys_to_active_element(key)
184
- text = ::Selenium::WebDriver::Keys.encode(key).join('')
185
- execute :send_keys_to_active_element, {}, { value: text.split(//) }
186
- end
187
-
188
- # For Appium
189
- # override
190
- def page_source
191
- # For W3C
192
- # execute_script('var source = document.documentElement.outerHTML;' \
193
- # 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \
194
- # 'return source;')
195
- execute :get_page_source
196
- end
197
-
198
- # For Appium
199
- # override
200
- def element_displayed?(element)
201
- # For W3C
202
- # https://github.com/SeleniumHQ/selenium/commit/b618499adcc3a9f667590652c5757c0caa703289
203
- # execute_atom :isDisplayed, element
204
- execute :is_element_displayed, id: element.ref
205
- end
206
-
207
- # For Appium
208
- # override
209
- def element_attribute(element, name)
210
- # For W3C in Selenium Client
211
- # execute_atom :getAttribute, element, name
212
- execute :get_element_attribute, id: element.ref, name: name
213
- end
214
-
215
- # For Appium
216
- # override
217
- def find_element_by(how, what, parent = nil)
218
- how, what = convert_locators(how, what)
219
-
220
- id = if parent
221
- execute :find_child_element, { id: parent }, { using: how, value: what }
222
- else
223
- execute :find_element, {}, { using: how, value: what }
224
- end
225
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
226
- end
227
-
228
- # For Appium
229
- # override
230
- def find_elements_by(how, what, parent = nil)
231
- how, what = convert_locators(how, what)
232
-
233
- ids = if parent
234
- execute :find_child_elements, { id: parent }, { using: how, value: what }
235
- else
236
- execute :find_elements, {}, { using: how, value: what }
237
- end
238
-
239
- ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
240
- end
241
-
242
- # For Appium
243
- # @param [Hash] id The id which can get as a response from server
244
- # @return [::Selenium::WebDriver::Element]
245
- def convert_to_element(id)
246
- ::Selenium::WebDriver::Element.new self, element_id_from(id)
247
- end
248
-
249
- # For Appium
250
- # override
251
- # called in 'extend DriverExtensions::HasNetworkConnection'
252
- def network_connection
253
- execute :get_network_connection
254
- end
255
-
256
- # For Appium
257
- # override
258
- # called in 'extend DriverExtensions::HasNetworkConnection'
259
- def network_connection=(type)
260
- execute :set_network_connection, {}, { parameters: { type: type } }
261
- end
262
-
263
- # For Appium
264
- # No implementation for W3C webdriver module
265
- # called in 'extend DriverExtensions::HasLocation'
266
- def location
267
- obj = execute(:get_location) || {}
268
- ::Selenium::WebDriver::Location.new obj['latitude'], obj['longitude'], obj['altitude']
269
- end
270
-
271
- # For Appium
272
- # No implementation for W3C webdriver module
273
- def set_location(lat, lon, alt = 0.0, speed: nil)
274
- loc = { latitude: lat, longitude: lon, altitude: alt }
275
- loc[:speed] = speed unless speed.nil?
276
- execute :set_location, {}, { location: loc }
277
- end
278
-
279
- #
280
- # logs
281
- #
282
- # For Appium
283
- # No implementation for W3C webdriver module
284
- def available_log_types
285
- types = execute :get_available_log_types
286
- Array(types).map(&:to_sym)
287
- end
288
-
289
- # For Appium
290
- # No implementation for W3C webdriver module
291
- def log(type)
292
- data = execute :get_log, {}, { type: type.to_s }
293
-
294
- Array(data).map do |l|
295
- begin
296
- ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
297
- rescue KeyError
298
- next
299
- end
300
- end
301
- end
302
-
303
- # For Appium
304
- def log_event(vendor, event)
305
- execute :post_log_event, {}, { vendor: vendor, event: event }
306
- end
307
-
308
- # For Appium
309
- def log_events(type = nil)
310
- args = {}
311
- args['type'] = type unless type.nil?
312
-
313
- execute :get_log_events, {}, args
314
- end
315
-
316
- def take_viewport_screenshot
317
- execute_script('mobile: viewportScreenshot')
318
- end
319
-
320
- def take_element_screenshot(element)
321
- execute :take_element_screenshot, id: element.ref
322
- end
323
-
324
- private
325
-
326
- # Don't convert locators for Appium Client
327
- # TODO: Only for Appium. Ideally, we'd like to keep the selenium-webdriver
328
- def convert_locators(how, what)
329
- # case how
330
- # when 'class name'
331
- # how = 'css selector'
332
- # what = ".#{escape_css(what)}"
333
- # when 'id'
334
- # how = 'css selector'
335
- # what = "##{escape_css(what)}"
336
- # when 'name'
337
- # how = 'css selector'
338
- # what = "*[name='#{escape_css(what)}']"
339
- # when 'tag name'
340
- # how = 'css selector'
341
- # end
342
- [how, what]
343
- end
344
- end # class W3C
345
- end # class Bridge
346
- end # class Base
347
- end # module Core
348
- end # module Appium